-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
47 lines (42 loc) · 1.08 KB
/
example.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
#include <iostream>
#include <random>
#include <iomanip>
#include "neural.h"
int rand_i32()
{
static std::mt19937 engine(time(NULL));
static std::uniform_int_distribution<int> distr(0, 3);
return distr(engine);
}
struct pair
{
std::vector<float> in;
std::vector<float> t;
};
// pairs that determines XOR problem
std::vector<pair> lrn_pairs
{
{{1,1}, {1}},
{{1,-1}, {-1}},
{{-1,1}, {-1}},
{{-1,-1}, {1}}
};
int main() {
neural n(2,1);
n.learning_speed(1);
n.momentum_rate(0.4);
for(int i = 0; i < 6000; i++)
{
auto p = lrn_pairs[rand_i32()];
n.calculate(p.in);
n.learn(p.t);
}
for(int i = 0; i < 4; i++)
{
std::cout << std::setprecision(1) <<"input : [" << lrn_pairs[i].in[0] << "] [" << lrn_pairs[i].in[1] << "]";
std::vector<float> & result = n.calculate(lrn_pairs[i].in);
std::cout << std::setprecision(1) <<"\nresult : [" << result[0] << "]";
std::cout << std::endl <<std::endl;
}
return 0;
}