69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#include "../src/NeuralNetwork/FeedForward"
|
|
|
|
#include <iostream>
|
|
class X: public Shin::Problem
|
|
{
|
|
public: X(bool x,bool y):Problem() {data.push_back(x);data.push_back(y);}
|
|
};
|
|
|
|
int main()
|
|
{
|
|
srand(time(NULL));
|
|
int lm=5;
|
|
Shin::NeuralNetwork::FeedForward net({2,lm,1});
|
|
bool x=1;
|
|
int prev_err=0;
|
|
int err=0;
|
|
int l;
|
|
int n;
|
|
int w;
|
|
int pot;
|
|
int wei;
|
|
int c=0;
|
|
std::cout << "\ntest 1 & 1 -" << net.solve(X(1,1))[0];
|
|
std::cout << "\ntest 1 & 0 -" << net.solve(X(1,0))[0];
|
|
std::cout << "\ntest 0 & 1 - " << net.solve(X(0,1))[0];
|
|
std::cout << "\ntest 0 & 0- " << net.solve(X(0,0))[0];
|
|
std::cout << "\n---------------------------------------";
|
|
do{
|
|
if(c%10000 ==1)
|
|
{
|
|
std::cout << "\nmixed";
|
|
srand(time(NULL));
|
|
}
|
|
err=0;
|
|
c++;
|
|
l=rand()%2+1;
|
|
n=rand()%lm;
|
|
w=rand()%2;
|
|
if(l==2)
|
|
n=0;
|
|
pot=net[l][n].getPotential();
|
|
net[l][n].setPotential(pot*(rand()%21+90)/100);
|
|
wei=net[l][n].getWeight(w);
|
|
net[l][n].setWeight(w,wei*(rand()%21+90)/100);
|
|
|
|
for(int i=0;i<100;i++)
|
|
{
|
|
bool x= rand()%2;
|
|
bool y=rand()%2;
|
|
Shin::Solution s =net.solve(X(x,y));
|
|
if(s[0]!= (x xor y))
|
|
err++;
|
|
}
|
|
|
|
if(err > prev_err)
|
|
{
|
|
net[l][n].setPotential(pot);
|
|
net[l][n].setWeight(w,wei);
|
|
};
|
|
prev_err=err;
|
|
if(err <1)
|
|
x=0;
|
|
}while(x);
|
|
std::cout << "\ntest 1 & 1 -" << net.solve(X(1,1))[0];
|
|
std::cout << "\ntest 1 & 0 -" << net.solve(X(1,0))[0];
|
|
std::cout << "\ntest 0 & 1 - " << net.solve(X(0,1))[0];
|
|
std::cout << "\ntest 0 & 0- " << net.solve(X(0,0))[0];
|
|
std::cout << "\nTotaly: " << c << "\n";
|
|
} |