Skip to content

Instantly share code, notes, and snippets.

@djaney
Created June 13, 2017 13:12
Show Gist options
  • Save djaney/422a814df1a22adaee0b7e0c71f98df8 to your computer and use it in GitHub Desktop.
Save djaney/422a814df1a22adaee0b7e0c71f98df8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import random;
nodes = [3,3,4,4,4,1,1,1,1]
weights = []
def main():
for i in nodes:
for j in range(1, i+2):
weights.append( random.random() )
i1 = 1
i2 = 1
i3 = 1
i4 = 1
s5 = sig(5,[i1])
s6 = sig(6,[i2])
s7 = sig(7,[i3])
s8 = sig(8,[i4])
s2 = sig(2,[s5,s6,s7,s8])
s3 = sig(3,[s5,s6,s7,s8])
s4 = sig(4,[s5,s6,s7,s8])
left = sig(0,[s2,s3,s4])
right = sig(1,[s2,s3,s4])
print( left,right )
def sig(n, attr):
if 0 == n :
sw = 0;
else:
sw = sum(i for i in nodes[:n]) + n
ew = sw + nodes[n]
total = 0;
for i,w in enumerate(weights[sw:ew-1]) :
total += w*attr[i]
total += weights[ew]
return 1 / ( 1 + len(attr)**total )
if "__main__" == __name__ :
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment