first try of propagation

This commit is contained in:
Marc Wäckerlin
2017-01-09 16:11:06 +00:00
parent c7cc3d1690
commit fcfe5871f1
5 changed files with 96 additions and 15 deletions

View File

@@ -8,7 +8,7 @@
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <neuron.hxx>
#include <cppunit/TestFixture.h>
#include <cppunit/ui/text/TestRunner.h>
@@ -19,15 +19,36 @@
/// @todo Rename DummyTest and DummyTest::dummy()
/// @todo Write test cases
class DummyTest: public CppUnit::TestFixture {
class NeuroNetTest: public CppUnit::TestFixture {
public:
void dummy() {
void simplexor() {
NeuroNet<float, 2, 1> neuronet;
Matrix<float, 1, 2> in[] = {{1, 1},
{1, -1},
{-1, 1},
{-1, -1}};
Matrix<float, 1, 1> out[] = {-1,
1,
1,
-1};
for (int i(0); i<sizeof(in)/sizeof(*in); ++i) {
std::cout<<in[i]<<""<<out[i]<<" ~ "
<<neuronet.feed(in[i]).apply([](float&v){
v = v<0 ? -1.0 : 1.0;
})<<std::endl;
auto res(neuronet.feed(in[i])
.apply([](float&v){
std::cout<<"v="<<v<<std::endl;
v = v<0 ? -1.0 : 1.0;
}));
CPPUNIT_ASSERT_EQUAL(out[i], res);
}
}
CPPUNIT_TEST_SUITE(DummyTest);
CPPUNIT_TEST(dummy);
CPPUNIT_TEST_SUITE(NeuroNetTest);
CPPUNIT_TEST(simplexor);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DummyTest);
CPPUNIT_TEST_SUITE_REGISTRATION(NeuroNetTest);
int main(int argc, char** argv) try {
std::ofstream ofs((*argv+std::string(".xml")).c_str());