|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 9, |
| 5 | + "execution_count": 8, |
6 | 6 | "metadata": { |
7 | 7 | "collapsed": false |
8 | 8 | }, |
|
14 | 14 | "Random starting synaptic weights: \n", |
15 | 15 | "[[-0.16595599]\n", |
16 | 16 | " [ 0.44064899]\n", |
17 | | - " [-0.99977125]]\n", |
18 | | - "error after 0 iterations: 0.578374046722\n", |
19 | | - "error after 1000 iterations: 0.0353771814512\n", |
20 | | - "error after 2000 iterations: 0.024323319584\n", |
21 | | - "error after 3000 iterations: 0.0196075022358\n", |
22 | | - "error after 4000 iterations: 0.016850233908\n", |
23 | | - "error after 5000 iterations: 0.014991814044\n", |
24 | | - "error after 6000 iterations: 0.0136320935305\n", |
25 | | - "error after 7000 iterations: 0.01258242301\n", |
26 | | - "error after 8000 iterations: 0.0117408289409\n", |
27 | | - "error after 9000 iterations: 0.0110467781322\n", |
| 17 | + " [-0.99977125]\n", |
| 18 | + " [-0.39533485]]\n", |
| 19 | + "error after 0 iterations: 0.449903018833\n", |
| 20 | + "error after 1000 iterations: 0.013750440233\n", |
| 21 | + "error after 2000 iterations: 0.00965974377145\n", |
| 22 | + "error after 3000 iterations: 0.00786218913086\n", |
| 23 | + "error after 4000 iterations: 0.00679524113652\n", |
| 24 | + "error after 5000 iterations: 0.00606919069443\n", |
| 25 | + "error after 6000 iterations: 0.00553435906148\n", |
| 26 | + "error after 7000 iterations: 0.00511936227674\n", |
| 27 | + "error after 8000 iterations: 0.00478528276951\n", |
| 28 | + "error after 9000 iterations: 0.00450886340585\n", |
| 29 | + "error after 10000 iterations: 0.00427523967482\n", |
| 30 | + "error after 11000 iterations: 0.00407440954071\n", |
| 31 | + "error after 12000 iterations: 0.00389936317766\n", |
| 32 | + "error after 13000 iterations: 0.00374502274318\n", |
| 33 | + "error after 14000 iterations: 0.00360760779755\n", |
| 34 | + "error after 15000 iterations: 0.00348423814505\n", |
| 35 | + "error after 16000 iterations: 0.00337267580097\n", |
| 36 | + "error after 17000 iterations: 0.00327115193553\n", |
| 37 | + "error after 18000 iterations: 0.00317824759008\n", |
| 38 | + "error after 19000 iterations: 0.00309280947588\n", |
28 | 39 | "New synaptic weights after training: \n", |
29 | | - "[[ 12.79547496]\n", |
30 | | - " [ -4.2162058 ]\n", |
31 | | - " [ -4.21608782]]\n", |
32 | | - "Considering new situation [1, 0, 0] -> ?: \n", |
33 | | - "[ 0.99999723]\n" |
| 40 | + "[[ 3.16744718]\n", |
| 41 | + " [-0.24954816]\n", |
| 42 | + " [-5.53795575]\n", |
| 43 | + " [ 2.93806832]]\n", |
| 44 | + "Considering new situation [1, 0, 1, 1] -> ?: \n", |
| 45 | + "[ 0.63819991]\n" |
34 | 46 | ] |
35 | 47 | } |
36 | 48 | ], |
|
47 | 59 | " # We model a single neuron, with 3 input connections and 1 output connection.\n", |
48 | 60 | " # We assign random weights to a 3 x 1 matrix, with values in the range -1 to 1\n", |
49 | 61 | " # and mean 0.\n", |
50 | | - " self.synaptic_weights = 2 * np.random.random((3, 1)) - 1\n", |
| 62 | + " self.synaptic_weights = 2 * np.random.random((4, 1)) - 1\n", |
51 | 63 | "\n", |
52 | 64 | " # The Sigmoid function, which describes an S shaped curve.\n", |
53 | 65 | " # We pass the weighted sum of the inputs through this function to\n", |
|
98 | 110 | "\n", |
99 | 111 | " # The training set. We have 4 examples, each consisting of 3 input values\n", |
100 | 112 | " # and 1 output value.\n", |
101 | | - " training_set_inputs = np.array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 0]])\n", |
| 113 | + " training_set_inputs = np.array([[0, 0, 1, 0], [1, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]])\n", |
102 | 114 | " training_set_outputs = np.array([[0, 1, 1, 0]]).T\n", |
103 | 115 | "\n", |
104 | 116 | " # Train the neural network using a training set.\n", |
105 | 117 | " # Do it 10,000 times and make small adjustments each time.\n", |
106 | | - " neural_network.train(training_set_inputs, training_set_outputs, 10000)\n", |
| 118 | + " neural_network.train(training_set_inputs, training_set_outputs, 20000)\n", |
107 | 119 | "\n", |
108 | 120 | " print (\"New synaptic weights after training: \")\n", |
109 | 121 | " print (neural_network.synaptic_weights)\n", |
110 | 122 | "\n", |
111 | 123 | " # Test the neural network with a new pattern\n", |
112 | | - " test = [1, 0, 0]\n", |
| 124 | + " test = [1, 0, 1, 1]\n", |
113 | 125 | " print (\"Considering new situation %s -> ?: \" % test )\n", |
114 | 126 | " print (neural_network.think(np.array(test)))\n" |
115 | 127 | ] |
116 | 128 | }, |
117 | 129 | { |
118 | 130 | "cell_type": "code", |
119 | | - "execution_count": 14, |
| 131 | + "execution_count": 6, |
120 | 132 | "metadata": { |
121 | 133 | "collapsed": false |
122 | 134 | }, |
|
185 | 197 | ], |
186 | 198 | "metadata": { |
187 | 199 | "kernelspec": { |
188 | | - "display_name": "Python 3", |
| 200 | + "display_name": "Python 2", |
189 | 201 | "language": "python", |
190 | | - "name": "python3" |
| 202 | + "name": "python2" |
191 | 203 | }, |
192 | 204 | "language_info": { |
193 | 205 | "codemirror_mode": { |
194 | 206 | "name": "ipython", |
195 | | - "version": 3 |
| 207 | + "version": 2 |
196 | 208 | }, |
197 | 209 | "file_extension": ".py", |
198 | 210 | "mimetype": "text/x-python", |
199 | 211 | "name": "python", |
200 | 212 | "nbconvert_exporter": "python", |
201 | | - "pygments_lexer": "ipython3", |
202 | | - "version": "3.5.2" |
| 213 | + "pygments_lexer": "ipython2", |
| 214 | + "version": "2.7.12" |
203 | 215 | } |
204 | 216 | }, |
205 | 217 | "nbformat": 4, |
|
0 commit comments