remove \r
[extl.git] / extl / intelligence / ann / test / xor_tester.h
blob57161eabcdb3b484ae65d4b1d26c304a6a9fae25
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: xor_tester.h
4 * Created: 08.12.17
5 * Updated: 08.12.17
7 * Brief: Unit-testing tester
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_INTELLIGENCE_ANN_TEST_XOR_TESTER_H
13 #define EXTL_INTELLIGENCE_ANN_TEST_XOR_TESTER_H
15 /* ///////////////////////////////////////////////////////////////////////
16 * ::extl::intelligence::test namespace
18 EXTL_INTELLIGENCE_BEGIN_WHOLE_NAMESPACE
19 EXTL_TEST_BEGIN_NAMESPACE
21 /* xor_tester
23 * 0 0 => 0
24 * 0 1 => 1
25 * 1 0 => 1
26 * 1 1 => 0
28 template<typename_param_k Net>
29 struct xor_tester
31 public:
32 typedef Net network_type;
33 typedef typename_type_k network_type::sample_type sample_type;
34 typedef typename_type_k network_type::samples_type samples_type;
35 typedef typename_type_k network_type::size_type size_type;
36 typedef typename_type_k network_type::float_type float_type;
37 typedef basic_network_validator<network_type> validator_type;
39 public:
40 void test(network_type& network, size_type n)
42 sample_type sp;
43 samples_type sps(4);
44 validator_type validator;
46 sps[0].binput("00");
47 sps[0].breal("0");
49 sps[1].binput("01");
50 sps[1].breal("1");
52 sps[2].binput("10");
53 sps[2].breal("1");
55 sps[3].binput("11");
56 sps[3].breal("0");
58 network.train(sps, n);
60 sp.binput("00");
61 network.run(sp);
62 EXTL_TEST_TRACE(_T("input:%d %d output:%d foutput:%f"), sp.get_binput(0), sp.get_binput(1), sp.get_boutput(0), network.foutput(0));
64 sp.binput("01");
65 network.run(sp);
66 EXTL_TEST_TRACE(_T("input:%d %d output:%d foutput:%f"), sp.get_binput(0), sp.get_binput(1), sp.get_boutput(0), network.foutput(0));
68 sp.binput("10");
69 network.run(sp);
70 EXTL_TEST_TRACE(_T("input:%d %d output:%d foutput:%f"), sp.get_binput(0), sp.get_binput(1), sp.get_boutput(0), network.foutput(0));
72 sp.binput("11");
73 network.run(sp);
74 EXTL_TEST_TRACE(_T("input:%d %d output:%d foutput:%f"), sp.get_binput(0), sp.get_binput(1), sp.get_boutput(0), network.foutput(0));
76 validator.validate(network, sps);
77 EXTL_TEST_TRACE(_T("n:%d mse:%f erate:%f\n"), sps.size() * n, validator.mse(), validator.erate());
80 /* ///////////////////////////////////////////////////////////////////////
81 * ::extl::intelligence::test namespace
83 EXTL_TEST_END_NAMESPACE
84 EXTL_INTELLIGENCE_END_WHOLE_NAMESPACE
85 /* //////////////////////////////////////////////////////////////////// */
86 #endif /* EXTL_INTELLIGENCE_ANN_TEST_XOR_TESTER_H */
87 /* //////////////////////////////////////////////////////////////////// */