Exemplo n.º 1
0
import nengo
import nengo_function_space as nfs

domain = np.linspace(-1, 1, 200)


# define kinds of functions you'd like to represent
def gaussian(mag, mean, sd):
    return mag * np.exp(-(domain-mean)**2/(2*sd**2))

# build the function space, generate the basis functions
fs = nfs.FunctionSpace(
    nfs.Function(
        gaussian,
        mean=nengo.dists.Uniform(-1, 1),
        sd=nengo.dists.Uniform(0.1, 0.7),
        mag=1),
    n_basis=10)

model = nengo.Network()
with model:
    # create an ensemble to represent the weights over the basis functions
    ens = nengo.Ensemble(n_neurons=1000, dimensions=fs.n_basis)
    # set encoders and evaluation points to be in a range that gets used
    ens.encoders = fs.project(
        nfs.Function(gaussian,
                             mean=nengo.dists.Uniform(-1, 1),
                             sd=0.05,
                             mag=1))
    ens.eval_points = fs.project(
Exemplo n.º 2
0
import numpy as np

import nengo
import nengo_function_space as nfs

domain = np.linspace(-1, 1, 200)


# define kinds of functions you'd like to represent
def gaussian(mag, mean, sd):
    return mag * np.exp(-(domain - mean)**2 / (2 * sd**2))


# build the function space
fs = nfs.FunctionSpace(nfs.Function(gaussian,
                                    mean=nengo.dists.Uniform(-1, 1),
                                    sd=nengo.dists.Uniform(0.1, 0.7),
                                    mag=1),
                       n_basis=20)

model = nengo.Network()
with model:
    # an ensemble to represent the weights over the basis functions
    ens = nengo.Ensemble(n_neurons=500, dimensions=fs.n_basis)
    # use separate distributions for the encoders and the evaluation points.
    # TODO: why?
    ens.encoders = fs.project(
        nfs.Function(gaussian, mean=nengo.dists.Uniform(-1, 1), sd=0.05,
                     mag=1))
    ens.eval_points = fs.project(
        nfs.Function(gaussian,
                     mean=nengo.dists.Uniform(-1, 1),
import numpy as np

import nengo
import nengo_function_space as nfs

domain = np.linspace(-1, 1, 200)


# define kinds of functions you'd like to represent
def gaussian(mag, mean, sd):
    return mag * np.exp(-(domain - mean)**2 / (2 * sd**2))


# create a distribution sampling that function space
gauss = nfs.Function(gaussian,
                     mean=nengo.dists.Uniform(-1, 1),
                     sd=nengo.dists.Uniform(0.1, 0.5),
                     mag=nengo.dists.Uniform(-1, 1))

# build the function space, generate the basis functions
fs = nfs.FunctionSpace(gauss, n_basis=15)

model = nengo.Network()
with model:
    # an ensemble representing the first function
    ens1 = nengo.Ensemble(n_neurons=2000, dimensions=fs.n_basis)
    # set encoders and evaluation points to be in a range that gets used
    ens1.encoders = fs.project(gauss)
    ens1.eval_points = fs.project(gauss)

    # an ensemble representing the second function
    ens2 = nengo.Ensemble(n_neurons=2000, dimensions=fs.n_basis)
Exemplo n.º 4
0
import nengo
import nengo_function_space as nfs

domain = np.linspace(-1, 1, 200)


# define kinds of functions you'd like to represent
def gaussian(mag, mean, sd):
    v = mag * np.exp(-(domain)**2 / (2 * sd**2))
    return np.roll(v, int(mean * 100))


# build the function space, generate the basis functions
fs = nfs.FunctionSpace(nfs.Function(gaussian,
                                    mean=nengo.dists.Uniform(-1, 1),
                                    sd=0.2,
                                    mag=1),
                       n_basis=10,
                       n_samples=1000)

model = nengo.Network()
with model:

    # create an ensemble to represent the weights over the basis functions
    ens = nengo.Ensemble(n_neurons=2000,
                         dimensions=fs.n_basis + 1,
                         radius=1.5,
                         neuron_type=nengo.Direct())
    # create combined distribution, which uses both FunctionSpaceDistribution
    # and normal Nengo distributions across different dimensions
    ens.encoders = nfs.Combined([
Exemplo n.º 5
0
max_std = .5


# define kinds of functions you'd like to represent
def gaussian2D(mean_x, mean_y, std_x, std_y):
    x_domain, y_domain = np.meshgrid(domain, domain)
    std_x = min(max(std_x, min_std), max_std)
    std_y = min(max(std_y, min_std), max_std)
    # flatten the result when returning
    return np.exp(-((x_domain-mean_x)**2./(2.*std_x) +
                    (y_domain-mean_y)**2./(2.*std_y))).flatten()

# create a distribution over the function space
gauss2D = nfs.Function(
    gaussian2D,
    mean_x=nengo.dists.Uniform(-1, 1),
    mean_y=nengo.dists.Uniform(-1, 1),
    std_x=nengo.dists.Uniform(min_std, max_std),
    std_y=nengo.dists.Uniform(min_std, max_std))

# build the function space, generate the basis functions
fs = nfs.FunctionSpace(gauss2D, n_basis=12)

model = nengo.Network()
model.config[nengo.Ensemble].neuron_type = nengo.Direct()
with model:
    # create an ensemble to represent the weights over the basis functions
    ens = nengo.Ensemble(n_neurons=500, dimensions=fs.n_basis)
    # set encoders and evaluation points to be in a range that gets used
    ens.encoders = fs.project(gauss2D)
    ens.eval_points = fs.project(gauss2D)
Exemplo n.º 6
0
import nengo
import nengo_function_space as nfs

domain = np.linspace(-1, 1, 200)


# define kinds of functions you'd like to represent
def gaussian(mag, mean, sd):
    return mag * np.exp(-(domain-mean)**2/(2*sd**2))

# build the function space, generate the basis functions
fs = nfs.FunctionSpace(
    nfs.Function(
        gaussian,
        mean=nengo.dists.Uniform(-1, 1),
        sd=nengo.dists.Uniform(0.1, 0.7),
        mag=1),
    n_basis=10, n_samples=1000)

# create a distribution for generating encoders and eval points
ens_dist = nfs.Function(
    gaussian,
    mean=nengo.dists.Uniform(-1, 1),
    sd=nengo.dists.Uniform(0.2, 0.5),
    mag=1)

model = nengo.Network()
with model:
    # create an ensemble to represent the weights over the basis functions
    ens = nengo.Ensemble(n_neurons=500, dimensions=fs.n_basis)