import numpy as np
import lif
import [Link] as plt
# 2 input neurons
# 1 output neuron
# initialize random weights
# Adjust weights using hebbian
#
[Link]
-1007692-g002
# At the end of learning, the neuron�s tuning curves are uniformally distributed
(Fig 2Giii), and the quality of the representation becomes optimal for all input
signals (Fig 2Aiii and 2Ciii).
# What are decoding weights?
# What are tuning curves?
# Are our inputs correlated? (for AND, OR gate)
# When does learning converge? Mainly what does this mean: "Learning converges when
all tuning curve maxima are aligned with the respective feedforward weights (Fig
3Bii; dashed lines and arrows)."
# ---------------------------------------------------------------------------
# [Link]
class SNN():
def __init__(self):
[Link](1) # Generate same random weights for every trial
# Matrix containing the weights between each neuron
self.z = [Link][1,0,0,0,1,1,0,1,0,1]
[Link] = [Link][1,1,1]
[Link] = [Link][2,2,2]
def sigmoid(x):
return 1 / (1 + [Link](-x))
def forward_propagation(self, inputs):
out = [Link](inputs, [Link])
zhat = [Link](out)
error = self.z - zhat
return zhat
# pass spikes from input to output
# pass the out of the input to the in of the output (the weights affect this
process)
# how do the weights effect this connection?
def train(self, inputs, outputs, epochs):
weights = [Link](2, 1)
# perform encoding into input neurons (input_nns)
for i in range(epochs):
output_nns = self.forward_propagation(inputs)
delta_w1 = [Link]([inputs[0]*output_nns, input[0], output_nns],
[Link]) # dot product? multiply the avg rates?
delta_w2 = [Link]([inputs[1]*output_nns, input[1], output_nns],
[Link])
weights[0] += delta_w1
weights[1] += delta_w2
# loop through each combo of x and y ?
# use hebbian rule to determine weight adjustment
# apply weight adjustment
# [Link]
# fr: firing rate estimate (in Hz)
# train_length: length of the spike train (in seconds)
def poissonSpike(fr, nbins, num_trials):
dt = 1 / 1000
spikeMatrix = [Link](num_trials, nbins) < fr * dt
t = [Link](0, (nbins * (dt - 1)), dt)
return (spikeMatrix, t)
def rasterPlot(spikeMatrix):
spikes_x = []
spikes_y = []
for i in range([Link][0]):
for j in range([Link][1]):
if spikeMatrix[i][j]:
spikes_y.append(i)
spikes_x.append(j)
[Link](spikes_x, spikes_y, marker="|")
[Link]([Link]([Link](spikes_y)))
# [Link]([Link]([Link](spikes_x)))
[Link]("Time Step")
[Link]("Trial")
[Link]()
sm, t = poissonSpike(300, 30, 20)
rasterPlot(sm)