init
This commit is contained in:
34
tests/01.cpp
Normal file
34
tests/01.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "../src/Network"
|
||||
#include "../src/Problem"
|
||||
|
||||
#include <iostream>
|
||||
class X: public S::Problem
|
||||
{
|
||||
protected:
|
||||
std::vector<bool> representation() const
|
||||
{
|
||||
return std::vector<bool>({1,1});
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
S::FeedForwardNetwork n(2,3,2);
|
||||
S::Solution s =n.solve(X());
|
||||
if(s.size()!=2)
|
||||
{
|
||||
std::cout << "1";
|
||||
return 1;
|
||||
}
|
||||
if(s[0]!=1)
|
||||
{
|
||||
std::cout << "2";
|
||||
return 1;
|
||||
}
|
||||
if(s[1]!=1)
|
||||
{
|
||||
std::cout << "3";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
tests/01.out
Normal file
1
tests/01.out
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
61
tests/02.cpp
Normal file
61
tests/02.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
#include "../src/Network"
|
||||
#include "../src/Problem"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class X: public S::Problem
|
||||
{
|
||||
protected:
|
||||
std::vector<bool> representation() const
|
||||
{
|
||||
return std::vector<bool>({1,1});
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
S::FeedForwardNetwork n(2,4,2);
|
||||
if(n[1]->size() != 4)
|
||||
{
|
||||
std::cout << "ACtual size:" << n[0]->size();
|
||||
return 1;
|
||||
}
|
||||
n[2]->operator[](0)->setPotential(25);
|
||||
std::cout << "Potential: " << n[2]->operator[](0)->getPotential() << "\n";
|
||||
S::Solution s =n.solve(X());
|
||||
if(s.size()!=2)
|
||||
{
|
||||
std::cout << "1";
|
||||
return 1;
|
||||
}
|
||||
if(s[0]!=0)
|
||||
{
|
||||
std::cout << "2";
|
||||
return 1;
|
||||
}
|
||||
if(s[1]!=1)
|
||||
{
|
||||
std::cout << "3";
|
||||
return 1;
|
||||
}
|
||||
|
||||
n[2]->operator[](0)->setWeight(0,26.0);
|
||||
s =n.solve(X());
|
||||
if(s.size()!=2)
|
||||
{
|
||||
std::cout << "a1";
|
||||
return 1;
|
||||
}
|
||||
if(s[0]!=1)
|
||||
{
|
||||
std::cout << "a2";
|
||||
return 1;
|
||||
}
|
||||
if(s[1]!=1)
|
||||
{
|
||||
std::cout << "a3";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
75
tests/03.cpp
Normal file
75
tests/03.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "../src/Network"
|
||||
#include "../src/Problem"
|
||||
|
||||
#include <iostream>
|
||||
class X: public S::Problem
|
||||
{
|
||||
public: X(bool x,bool y):x(x),y(y) {}
|
||||
protected: std::vector<bool> representation() const { return std::vector<bool>({x,y}); }
|
||||
private:
|
||||
bool x;
|
||||
bool y;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
srand(time(NULL));
|
||||
int lm=5;
|
||||
S::FeedForwardNetwork 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]->operator[](n)->getPotential();
|
||||
net[l]->operator[](n)->setPotential(pot*(rand()%21+90)/100);
|
||||
wei=net[l]->operator[](n)->getWeight(w);
|
||||
net[l]->operator[](n)->setWeight(w,wei*(rand()%21+90)/100);
|
||||
|
||||
for(int i=0;i<100;i++)
|
||||
{
|
||||
bool x= rand()%2;
|
||||
bool y=rand()%2;
|
||||
S::Solution s =net.solve(X(x,y));
|
||||
if(s[0]!= (x xor y))
|
||||
err++;
|
||||
}
|
||||
|
||||
if(err > prev_err)
|
||||
{
|
||||
net[l]->operator[](n)->setPotential(pot);
|
||||
net[l]->operator[](n)->setWeight(w,wei);
|
||||
};
|
||||
// std::cout << "C: " << c << " err: " << err << " prev: "<<prev_err << "\n";
|
||||
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";
|
||||
}
|
||||
17
tests/Makefile
Normal file
17
tests/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
include ../Makefile.const
|
||||
|
||||
LIB_DIR = ..
|
||||
ALL_TESTS=01 02 03
|
||||
|
||||
CXXFLAGS += -I$(LIB_DIR)
|
||||
|
||||
all:| lib $(ALL_TESTS);
|
||||
|
||||
test: all
|
||||
@for i in $(ALL_TESTS); do echo -n ./$$i; echo -n " - "; ./$$i; echo ""; done
|
||||
|
||||
%: %.cpp $(LIB_DIR)/$(LIBNAME).a
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $ $(LIB_DIR)/$(LIBNAME).a -lm
|
||||
|
||||
lib:
|
||||
make -C ../
|
||||
Reference in New Issue
Block a user