Git Product home page Git Product logo

Comments (3)

romanngg avatar romanngg commented on July 28, 2024

Hi Wei,

Unfortunately we don't have a Tanh function since we don't know of a closed-form expression to compute the kernel with this activation.

Currently you could try the following workarounds:

  1. Use stax.Erf() instead, which is very similar to Tanh and has a closed-form kernel expression.

  2. Use the original jax.experimental.stax (accessed as nt.stax.ostax in the snippet below) to construct the network and use NT to compute the Monte Carlo estimate of the kernel, e.g.

from neural_tangents import stax, monte_carlo_kernel_fn
from jax import random

init_fn, apply_fn = stax.ostax.serial(stax.ostax.Dense(512), stax.ostax.Tanh)
kernel_fn = monte_carlo_kernel_fn(init_fn, apply_fn, 
                                  key=random.PRNGKey(1), n_samples=100)

kernel_fn(x1=random.normal(random.PRNGKey(1), (10, 40)), 
          x2=random.normal(random.PRNGKey(2), (20, 40)), 
          get=('nngp', 'ntk'))
  1. You could look into approximating the intractable integrals with a lookup table as was done in https://arxiv.org/pdf/1711.00165.pdf (sec 2.5; https://github.com/brain-research/nngp/blob/42a5fb523653c0a213851628bc3ca0b78a2e8d1c/nngp.py#L307), but this would likely require a lot of effort to implement (NT does not support this currently).

Let me know if any of this helps!

from neural-tangents.

WeiHuang05 avatar WeiHuang05 commented on July 28, 2024

Hi Roman,

Many thanks for your reply. The second method works for Tanh function very well.

I just have a suggestion for your consideration.

If erf(x) changes to erf(\sqrt{\pi}/2 x), it is going to look more like the Tanh function, in the context of
the mean field theory (https://arxiv.org/abs/1802.09979). Since the intersection between critical line and \sigma_b = 0 is \sigma_w=1 for both erf(\sqrt{\pi}/2 x) and Tanh.

Best regards,
Wei

from neural-tangents.

romanngg avatar romanngg commented on July 28, 2024

Sorry for huge delay, FYI @SiuMath added this option in d7fc2db

from neural-tangents.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.