-
Notifications
You must be signed in to change notification settings - Fork 0
/
SLP_Examples.h
62 lines (50 loc) · 1.44 KB
/
SLP_Examples.h
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
#ifndef SLP_EXAMPLES_H
#define SLP_EXAMPLES_H
#include <iostream>
#include <cassert>
#include "Perceptron.h"
void ORPerceptron()
{
std::cout << "Training OR Perceptron..." << std::endl;
// Training set for OR function.
std::vector<TrainingSample> training_set =
{
TrainingSample(false,{ 0, 0 }),
TrainingSample(true,{ 0, 1 }),
TrainingSample(true,{ 1, 0 }),
TrainingSample(true,{ 1, 1 })
};
// Threshhold is 0.5!
Perceptron slp(2, 0.2, 0.5);
// Let's train our network.
slp.train(training_set, 5);
// Let's verify it.
assert(slp.get_result({ 0, 0 }) == false);
assert(slp.get_result({ 0, 1 }) == true);
assert(slp.get_result({ 1, 0 }) == true);
assert(slp.get_result({ 1, 1 }) == true);
std::cout << "OR Perceptron is successfully trained!" << std::endl;
}
void ANDPerceptron()
{
std::cout << "Training AND Perceptron..." << std::endl;
// Training set for AND function.
std::vector<TrainingSample> training_set =
{
TrainingSample(false,{ 0, 0 }),
TrainingSample(false,{ 0, 1 }),
TrainingSample(false,{ 1, 0 }),
TrainingSample(true,{ 1, 1 })
};
// Threshhold is 1.5!
Perceptron slp(2, 0.2, 1.5);
// Let's train our network.
slp.train(training_set, 5);
// Let's verify it.
assert(slp.get_result({ 0, 0 }) == false);
assert(slp.get_result({ 0, 1 }) == false);
assert(slp.get_result({ 1, 0 }) == false);
assert(slp.get_result({ 1, 1 }) == true);
std::cout << "AND Perceptron is successfully trained!" << std::endl;
}
#endif