Skip to content

Instantly share code, notes, and snippets.

@hjpithadia
Forked from xavierdcruz0/thingy
Created March 2, 2016 21:56
Show Gist options
  • Save hjpithadia/dd78abfcfc771d1334b1 to your computer and use it in GitHub Desktop.
Save hjpithadia/dd78abfcfc771d1334b1 to your computer and use it in GitHub Desktop.
import numpy as np
import itertools
# update rule for neuron x1
def update_1((a, b, c)):
test = c-b+2
if (test > 0):
new = 1
elif (test == 0):
new = a
elif (test < 0):
new = 0
return [new, b, c]
# update rule for neuron x2
def update_2((a, b, c)):
test = c-a+2
if (test > 0):
new = 1
elif (test == 0):
new = b
elif (test < 0):
new = 0
return [a, new, c]
# update rule for neuron x3
def update_3((a, b, c)):
test = a+b-2
if (test > 0):
new = 1
elif (test == 0):
new = c
elif (test < 0):
new = 0
return [a, b, new]
# update all neurons
def update((a, b, c)):
print "updating neuron 1: " + str(update_1((a, b, c)))
print "updating neuron 2: " + str(update_2((a, b, c)))
print "updating neuron 2: " + str(update_3((a, b, c)))
# generate all combinations: [[0, 0, 0], [0, 0, 1],...,[1, 1, 1]]
def generate_combinations(n):
sequences = ["".join(seq) for seq in itertools.product("01", repeat=n)]
outarray = []
for s in sequences:
string_pieces = list(s)
int_pieces = []
for j in range(n):
int_pieces.append(int(string_pieces[j]))
outarray.append(int_pieces)
return outarray
# for 3 neurons
N = 3
inputs = generate_combinations(N)
# cycle through all possible inputs and work out the next period configuration
for i in inputs:
print "========="
print "input: " + str(i)
update(i)
print "========="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment