Hi, I’m a grad student. I would like to understand the essence of predictive coding.
Can you tell me how to implement the example from this article? “https://www.frontiersin.org/articles/10.3389/fncom.2024.1338280/full”
import nengo
import numpy as np
from tensorflow.keras.datasets import mnist
from nengo_extras.gui import image_display_function
(train_images, ), (, _) = mnist.load_data()
class MNISTIterator:
def init(self, data, presentation_time):
self.data = data
self.idx = 0
self.presentation_time = presentation_time
def next_image(self, t):
if int(t / self.presentation_time) > self.idx:
self.idx += 1
idx = self.idx % len(self.data)
image = self.data[idx].flatten()
return image
class PredictiveCodingModel(nengo.Network):
def init(self, T, e0_shape, mnist_iterator):
super().init()
with self:
self.e0 = nengo.Node(output=mnist_iterator)
display_f1 = image_display_function((1, 28, 28))
display_node1 = nengo.Node(display_f1, size_in=np.prod(e0_shape),label="display_node_input")
nengo.Connection(self.e0, display_node1, synapse=None, label="input_to_display_node1")
I = nengo.Ensemble(784, dimensions=1, label='I')
pe0 = nengo.Ensemble(784, dimensions=1, label='pe0')
ne0 = nengo.Ensemble(784, dimensions=1, label='ne0')
pe1 = nengo.Ensemble(1296, dimensions=1, label='pe1')
ne1 = nengo.Ensemble(1296, dimensions=1, label='ne1')
r1 = nengo.Ensemble(1296, dimensions=1, label='r1')
r2 = nengo.Ensemble(1024, dimensions=1, label='r2')
nengo.Connection(self.e0, I.neurons)
nengo.Connection(I, pe0)
nengo.Connection(I, ne0)
nengo.Connection(pe0, r1)
nengo.Connection(r1, pe0)
nengo.Connection(ne0, r1)
nengo.Connection(r1, ne0)
nengo.Connection(pe1, r1)
nengo.Connection(r1, pe1)
nengo.Connection(ne1, r1)
nengo.Connection(r1, ne1)
nengo.Connection(pe1, r2)
nengo.Connection(r2, pe1)
nengo.Connection(ne1, r2)
nengo.Connection(r2, ne1)
T = 1
e0_shape = (28, 28)
train_images = train_images / 255.0
presentation_time = 0.5 # sec
mnist_iterator = MNISTIterator(train_images, presentation_time)
model = PredictiveCodingModel(T, e0_shape, mnist_iterator.next_image)
for starters, how to implement inhibitory neurons between ensembles with different numbers of neurons?