-
Notifications
You must be signed in to change notification settings - Fork 25
/
xor.py
24 lines (18 loc) · 936 Bytes
/
xor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
from microMLP import MicroMLP
mlp = MicroMLP.Create( neuronsByLayers = [2, 2, 1],
activationFuncName = MicroMLP.ACTFUNC_GAUSSIAN,
layersAutoConnectFunction = MicroMLP.LayersFullConnect )
nnFalse = MicroMLP.NNValue.FromBool(False)
nnTrue = MicroMLP.NNValue.FromBool(True)
mlp.AddExample( [nnFalse, nnFalse], [nnFalse] )
mlp.AddExample( [nnFalse, nnTrue ], [nnTrue ] )
mlp.AddExample( [nnTrue , nnTrue ], [nnFalse] )
mlp.AddExample( [nnTrue , nnFalse], [nnTrue ] )
learnCount = mlp.LearnExamples()
print( "LEARNED :" )
print( " - False xor False = %s" % mlp.Predict([nnFalse, nnFalse])[0].AsBool )
print( " - False xor True = %s" % mlp.Predict([nnFalse, nnTrue] )[0].AsBool )
print( " - True xor True = %s" % mlp.Predict([nnTrue , nnTrue] )[0].AsBool )
print( " - True xor False = %s" % mlp.Predict([nnTrue , nnFalse])[0].AsBool )