1 # Python NeuralNetwork sample for andgate. 
   2 # See andgate.py
   3 
   4 >>> def f(x1,x2,w1,w2):
   5 	return x1*w1 + x2*w2
   6 
   7 >>> thres = 0.5
   8 >>> w1 = 0.3
   9 >>> w2 = -0.2
  10 >>> x1,x1 = 0,0
  11 >>> 
  12 >>> f(x1,x2,w1,w2)
  13 Traceback (most recent call last):
  14   File "<pyshell#8>", line 1, in f(x1,x2,w1,w2)
  15 NameError: name 'x2' is not defined
  16 >>> x1,x1 = 0,0
  17 >>> x1,x2 = 0,0
  18 >>> f(x1,x2,w1,w2)
  19 0.0
  20 >>> x1,x2 = 0,1
  21 >>> f(x1,x2,w1,w2)
  22 -0.20000000000000001
  23 >>> isOver=lambda x1,x2,w1,w2:f(x1,x2,w1,w2)>thres
  24 >>> isOver(x1,x2,w1,w2)
  25 0
  26 >>> result=isOver
  27 >>> result(x1,x2,w1,w2)
  28 0
  29 >>> expected=0
  30 >>> isSame=lambda x1,x2,w1,w2,expected:result(x1,x2,w1,w2)==expected
  31 >>> isSame(x1,x2,w1,w2,0)
  32 1
  33 >>> x1,x2=1,0
  34 >>> isSame(x1,x2,w1,w2,0)
  35 1
  36 >>> x1,x2=1,1
  37 >>> isSame(x1,x2,w1,w2,1)
  38 0
  39 >>> result(x1,x2,w1,w2)
  40 0
  41 >>> f(x1,x2,w1,w2)
  42 0.099999999999999978
  43 >>> f(x1,x2,w1+w1delta,w2+w2delta)
  44 Traceback (most recent call last):
  45   File "<pyshell#27>", line 1, in f(x1,x2,w1+w1delta,w2+w2delta)
  46 NameError: name 'w1delta' is not defined
  47 >>> w1delta,w2delta=0.2,0.2
  48 >>> f(x1,x2,w1+w1delta,w2+w2delta)
  49 0.5
  50 >>> w1delta,w2delta=0.3,0.3
  51 >>> f(x1,x2,w1+w1delta,w2+w2delta)
  52 0.69999999999999996
  53 >>> isSame(x1,x2,w1+w1delta,w2+w2delta,1)
  54 1
  55 >>> x1,x2=0,0
  56 >>> w1prime=w1+w1delta
  57 >>> w2prime=w2+w2delta
  58 >>> isSame(x1,x2,w1prime,w2prime,0)
  59 1
  60 >>> x1,x2=0,1
  61 >>> isSame(x1,x2,w1prime,w2prime,0)
  62 1
  63 >>> isSame(1,0,w1prime,w2prime,0)
  64 0
  65 >>> f(1,0,w1prime,w2prime)
  66 0.59999999999999998
  67 >>> 
  68 >>> 
  69 >>> import andgate
  70 >>> andgate.printGenerations()
  71 0.0
  72 -0.2
  73 0.3
  74 0.1
  75 >>> reload(andgate)
  76 <module 'andgate' from 'C:\PYTHON22\andgate.py'>
  77 >>> andgate.printGenerations()
  78 (0,0) : 0.000000
  79 (0,1) : -0.200000
  80 (1,0) : 0.300000
  81 (1,1) : 0.100000
  82 >>> reload(andgate)
  83 <module 'andgate' from 'C:\PYTHON22\andgate.py'>
  84 >>> andgate.printGenerations()
  85 Traceback (most recent call last):
  86   File "<pyshell#48>", line 1, in andgate.printGenerations()
  87 TypeError: printGenerations() takes exactly 2 arguments (0 given)
  88 >>> andgate.printGenerations(0.3,-0.2)
  89 (0,0) : 0.000000
  90 (0,1) : -0.200000
  91 (1,0) : 0.300000
  92 (1,1) : 0.100000
  93 >>> andgate.printGenerations(0.4,-0.1)
  94 (0,0) : 0.000000
  95 (0,1) : -0.100000
  96 (1,0) : 0.400000
  97 (1,1) : 0.300000
  98 >>> andgate.printGenerations(0.5,0)
  99 (0,0) : 0.000000
 100 (0,1) : 0.000000
 101 (1,0) : 0.500000
 102 (1,1) : 0.500000
 103 >>> andgate.printGenerations(0.6,0.1)
 104 (0,0) : 0.000000
 105 (0,1) : 0.100000
 106 (1,0) : 0.600000
 107 (1,1) : 0.700000
 108 >>> andgate.printGenerations(0.55,0.05)
 109 (0,0) : 0.000000
 110 (0,1) : 0.050000
 111 (1,0) : 0.550000
 112 (1,1) : 0.600000
 113 >>> andgate.printGenerations(0.4,0.2)
 114 (0,0) : 0.000000
 115 (0,1) : 0.200000
 116 (1,0) : 0.400000
 117 (1,1) : 0.600000
 118 >>> andgate.printGenerations(0.4,-0.1)
 119 (0,0) : 0.000000
 120 (0,1) : -0.100000
 121 (1,0) : 0.400000
 122 (1,1) : 0.300000
 123 >>> andgate.printGenerations(0.5,0)
 124 (0,0) : 0.000000
 125 (0,1) : 0.000000
 126 (1,0) : 0.500000
 127 (1,1) : 0.500000
 128 >>> andgate.printGenerations(0.6,0.1)
 129 (0,0) : 0.000000
 130 (0,1) : 0.100000
 131 (1,0) : 0.600000
 132 (1,1) : 0.700000
 133 >>> andgate.printGenerations(0.5,0.1)
 134 (0,0) : 0.000000
 135 (0,1) : 0.100000
 136 (1,0) : 0.500000
 137 (1,1) : 0.600000
 138 >>> 
 139 >>> reload(andgate)
 140 <module 'andgate' from 'C:\PYTHON22\andgate.py'>
 141 >>> andgate.adjust(1,1,0.3,-0.2,1)
 142 (0.39000000000000001, -0.11)
 143 >>> andgate.printGenerations(0.39,-0.11)
 144 (0,0) : 0.000000
 145 (0,1) : -0.110000
 146 (1,0) : 0.390000
 147 (1,1) : 0.280000
 148 >>> andgate.adjust(1,1,0.39,-0.11,1)
 149 (0.46200000000000002, -0.038000000000000006)
 150 >>> andgate.printGenerations(0.462,-0.038)
 151 (0,0) : 0.000000
 152 (0,1) : -0.038000
 153 (1,0) : 0.462000
 154 (1,1) : 0.424000
 155 >>> andgate.adjust(1,1,0.462,-0.038,1)
 156 (0.51960000000000006, 0.019599999999999999)
 157 >>> andgate.printGenerations(0.5196,0.0196)
 158 (0,0) : 0.000000
 159 (0,1) : 0.019600
 160 (1,0) : 0.519600
 161 (1,1) : 0.539200
 162 >>> andgate.adjust(1,0,0.5196,0.0196,0)
 163 (0.46763999999999994, 0.019599999999999999)
 164 >>> andgate.printGenerations(0.4676,0.0196)
 165 (0,0) : 0.000000
 166 (0,1) : 0.019600
 167 (1,0) : 0.467600
 168 (1,1) : 0.487200
 169 >>> andgate.adjust(1,1,0.4676,0.0196,1)
 170 (0.51888000000000001, 0.070879999999999999)
 171 >>> andgate.printGenerations(0.5188,0.07088)
 172 (0,0) : 0.000000
 173 (0,1) : 0.070880
 174 (1,0) : 0.518800
 175 (1,1) : 0.589680
 176 >>> andgate.adjust(1,0,0.5188,0.07088,0)
 177 (0.46692, 0.070879999999999999)
 178 >>> andgate.printGenerations(0.46692,0.07088)
 179 (0,0) : 0.000000
 180 (0,1) : 0.070880
 181 (1,0) : 0.466920
 182 (1,1) : 0.537800
web biohackers.net