mirror of
https://github.com/davidalbertonogueira/MLP.git
synced 2025-12-16 20:07:07 +03:00
MISC Remove bias from examples.
This commit is contained in:
@@ -58,6 +58,14 @@ public:
|
||||
}
|
||||
|
||||
|
||||
std::vector<double> & GetOutputValues(const std::vector<double> &input);
|
||||
int GetOutputClass(const std::vector<double> &input);
|
||||
|
||||
void Train(const std::vector<TrainingSample> &training_sample_set,
|
||||
bool bias_already_in);
|
||||
|
||||
//void UpdateWeight(const std::vector<double> &x,
|
||||
// double error);
|
||||
private:
|
||||
|
||||
int m_num_inputs;
|
||||
|
||||
112
src/Main.cpp
112
src/Main.cpp
@@ -17,19 +17,19 @@ void LearnAND() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{{ 1, 0, 0 },{1,0}},
|
||||
{{ 1, 0, 1 },{1,0}},
|
||||
{{ 1, 1, 0 },{1,0}},
|
||||
{{ 1, 1, 1 },{0,1}}
|
||||
{{ 0, 0 },{1,0}},
|
||||
{{ 0, 1 },{1,0}},
|
||||
{{ 1, 0 },{1,0}},
|
||||
{{ 1, 1 },{0,1}}
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(2, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 0, 1 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 0 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 1 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 1, 0 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 1, 1 }) == 1);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -39,19 +39,19 @@ void LearnNAND() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{{ 1, 0, 0 },{0,1}},
|
||||
{{ 1, 0, 1 },{0,1}},
|
||||
{{ 1, 1, 0 },{0,1}},
|
||||
{{ 1, 1, 1 },{1,0}}
|
||||
{{ 0, 0 },{0,1}},
|
||||
{{ 0, 1 },{0,1}},
|
||||
{{ 1, 0 },{0,1}},
|
||||
{{ 1, 1 },{1,0}}
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(2, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 1 }) == 0);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -61,19 +61,19 @@ void LearnOR() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{{ 1, 0, 0 },{1,0}},
|
||||
{{ 1, 0, 1 },{0,1}},
|
||||
{{ 1, 1, 0 },{0,1}},
|
||||
{{ 1, 1, 1 },{0,1}}
|
||||
{{ 0, 0 },{1,0}},
|
||||
{{ 0, 1 },{0,1}},
|
||||
{{ 1, 0 },{0,1}},
|
||||
{{ 1, 1 },{0,1}}
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(2, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 1 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 1 }) == 1);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -83,19 +83,19 @@ void LearnNOR() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{{ 1, 0, 0 },{0,1}},
|
||||
{{ 1, 0, 1 },{1,0}},
|
||||
{{ 1, 1, 0 },{1,0}},
|
||||
{{ 1, 1, 1 },{1,0}}
|
||||
{{ 0, 0 },{0,1}},
|
||||
{{ 0, 1 },{1,0}},
|
||||
{{ 1, 0 },{1,0}},
|
||||
{{ 1, 1 },{1,0}}
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(2, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 0, 1 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 0 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 0, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 1, 0 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 1, 1 }) == 0);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -105,19 +105,19 @@ void LearnXOR() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{ { 1, 0, 0 },{ 1,0 } },
|
||||
{ { 1, 0, 1 },{ 0,1 } },
|
||||
{ { 1, 1, 0 },{ 0,1 } },
|
||||
{ { 1, 1, 1 },{ 1,0 } }
|
||||
{ { 0, 0 },{ 1,0 } },
|
||||
{ { 0, 1 },{ 0,1 } },
|
||||
{ { 1, 0 },{ 0,1 } },
|
||||
{ { 1, 1 },{ 1,0 } }
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(2, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutput({ 1, 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 0 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0, 1 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1, 1 }) == 0);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -127,15 +127,15 @@ void LearnNOT() {
|
||||
|
||||
std::vector<TrainingSample> training_set =
|
||||
{
|
||||
{{ 1, 0},{0,1}},
|
||||
{{ 1, 1},{1,1}}
|
||||
{{ 0},{0,1}},
|
||||
{{ 1},{1,1}}
|
||||
};
|
||||
|
||||
MLP my_mlp(0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, 1, 1);
|
||||
MLP my_mlp(1, 2, 1, 5, 0.1, 100, 0.5);
|
||||
my_mlp.Train(training_set, false);
|
||||
|
||||
assert(my_mlp.GetOutput({ 1, 0 }) == 1);
|
||||
assert(my_mlp.GetOutput({ 1, 1 }) == 0);
|
||||
assert(my_mlp.GetOutputClass({ 0 }) == 1);
|
||||
assert(my_mlp.GetOutputClass({ 1 }) == 0);
|
||||
std::cout << "Trained with success." << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user