-
Notifications
You must be signed in to change notification settings - Fork 2
/
xor_gate_multiple_perceptron.cpp
72 lines (51 loc) · 1.8 KB
/
xor_gate_multiple_perceptron.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Author: flouthoc (flouthoc@gmail.com)
Contributors:
*/
#include <iostream>
#include <vector>
#include "perceptron.h"
using namespace std;
int main(){
Perceptron per_xor_final(2);
Perceptron per_or(2);
Perceptron per_not_and(2);
//per.printWeights();
//traning set for per_xor_final;
vector<pair<vector<double>, bool>> trainingset_and{
make_pair(vector<double> {0,0}, false),
make_pair(vector<double> {1,0}, false),
make_pair(vector<double> {0,1}, false),
make_pair(vector<double> {1,1}, true)
};
//traning set for per_or
vector<pair<vector<double>, bool>> trainingset_or{
make_pair(vector<double> {0,0}, false),
make_pair(vector<double> {1,0}, true),
make_pair(vector<double> {0,1}, true),
make_pair(vector<double> {1,1}, true)
};
//traning set for per_or
vector<pair<vector<double>, bool>> trainingset_not_and{
make_pair(vector<double> {0,0}, true),
make_pair(vector<double> {1,0}, true),
make_pair(vector<double> {0,1}, true),
make_pair(vector<double> {1,1}, false)
};
per_xor_final.traintilllearn(trainingset_and);
per_or.traintilllearn(trainingset_or);
per_not_and.traintilllearn(trainingset_not_and);
cout<<"Inputs 1 & 1 --->";
cout<<per_xor_final.predict(vector<double>{per_or.predict(vector<double> {1,1}),
per_not_and.predict(vector<double> {1,1})})<<endl;
cout<<"Inputs 1 & 0 --->";
cout<<per_xor_final.predict(vector<double>{per_or.predict(vector<double> {1,0}),
per_not_and.predict(vector<double> {1,0})})<<endl;
cout<<"Inputs 0 & 1 --->";
cout<<per_xor_final.predict(vector<double>{per_or.predict(vector<double> {0,1}),
per_not_and.predict(vector<double> {0,1})})<<endl;
cout<<"Inputs 0 & 0 --->";
cout<<per_xor_final.predict(vector<double>{per_or.predict(vector<double> {0,0}),
per_not_and.predict(vector<double> {0,0})})<<endl;
return 0;
}