Hi @shruti_sneha! This idea of defining a function implicitly by giving Nengo a set of points, rather than explicitly with an actual mathematical function, is something we’ve been playing around with for a while. We found it useful, so we made it easier in our most recent release (v2.2.0).
Here’s an example that shows how to do that in a simple one-dimensional case like you described (requires Nengo v2.2.0):
import matplotlib.pyplot as plt
import numpy as np
import nengo
m = 200 # number of training points
n = 100 # number of neurons
# --- create x and y points for target function (square)
rng = np.random.RandomState(0)
x = rng.uniform(-1, 1, size=(m, 1)) # random points along x-axis
y = x**2 + rng.normal(0, 0.1, size=(m, 1)) # square of x points plus noise
with nengo.Network() as model:
a = nengo.Ensemble(n, 1)
b = nengo.Ensemble(n, 1)
c = nengo.Connection(a, b, eval_points=x, function=y)
with nengo.Simulator(model) as sim:
pass
x2 = np.linspace(-1, 1, 100).reshape(-1, 1)
x2, _, y2 = nengo.utils.connection.eval_point_decoding(c, sim, eval_points=x2)
plt.plot(x, y, 'k.')
plt.plot(x2, y2, 'b-')
plt.show()
You can see that my function is defined implicitly by the points x
and y
. I create these points, but in practice they’d probably come from some dataset, or real-world measurements. Then, when I create the connection c
to compute this function, I pass the x
and y
points. The last part of the code plots how accurately this connection is able to compute the function, showing the noisy training points in black and the computed function in blue.
If you want a more interesting example using images, check out this example using the MNIST digits.