Classifying Numbers As Odd Or Even With Neural Networks
5
1
110b (6)
isEven?
0
101b (5)
Neurons
Array => Number
3
-2
2
4
3
1
5
4
6
-1
0
1
Neurons
Input Layer: NOT Neurons
Neurons
Array => Number
???
5
2
* -1
* 4
-5
8
3
3
function Neuron(weights){
this.weights = weights
}
Neuron.prototype.process = function(inputs){
var sum = 0
for (var i=0; i<inputs.length; i++) {
sum += inputs[i] * this.weights[i]
}
return sum
}
var neuron = new Neuron([4, -2, 6])
var output = neuron.process([1, 0, 1])
// output = 10
0
1
2
2.5
1
0
-3
1.5
1
0
1.5
Is 01b (1) even?
YES!
1.5 > 0.5
Need to adjust weights to get a more correct response!
Training Data
Number => isEven [0, 0, 0] => [1] [0, 0, 1] => [0] [0, 1, 0] => [1] [0, 1, 1] => [0] [1, 0, 0] => [1] ...
Hidden
Layer
5
9
4
0
2
generateTestData(0, 4)
[
{
"input": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
"output": [1]
},
{
"input": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
"output": [0]
},
{
"input": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
"output": [1]
},
{
"input": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
"output": [0]
}
]
0000 0000 0000 0011b === 3
false / not even
var trainingSet = generateTestData(0, 100);
var testSet = generateTestData(10000, 11000);
correctness([w1, w2, ...], tE) = xx% correctness([0.2, 2.9, ...], tE) = 60%
predictIsEven(number, weights) ==> e.g. 0.17 ==> 0.17 < 0.5, prediction is "not even"
correctness([1.2, 1.5, ...], tE) = 74% correctness([2.1, 0.3, ...], tE) = 23% correctness([1.3, 0.4, ...], tE) = 54%
exampleIsPredictedCorrectly(example, weights)
==> e.g. true
correctness(weights, trainingExamples)
==> e.g. 60%
CODE
Figure out what kind of changes to make
Make small random weight changes
Improvements
Backpropagation
0
1
2
2.5
1
0
-3
1.5
1
0
1.5
Is 01b (1) even?
YES
1.5 > 0.5
1
.7
1
1 > 0.5
0.7
0.7
0.3 < 0.5
NO
0.6
.5
0.3
0.7 > 0.5
0.5
Using neural nets to recognize handwritten digits
Slides
Full Code
Classifying numbers as odd or even with neural networks
By Matt Zeunert
Classifying numbers as odd or even with neural networks
- 1,399