Commit 5254ca92 authored by Martin Beseda's avatar Martin Beseda

Merge branch 'dev_cpp' of code.it4i.cz:voj0085/4Neuro into dev

parents ca78e2d8 1a04d074
**Summary**
Summary
(Summarize the bug encountered concisely)
**Steps to reproduce**
Steps to reproduce
(How one can reproduce the issue - this is very important)
**What is the current bug behavior?**
What is the current bug behavior?
(What actually happens)
**What is the expected correct behavior?**
What is the expected correct behavior?
(What you should see instead)
**Relevant logs and/or screenshots**
Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output,
logs, and code as it's very hard to read otherwise.)
**Possible fixes**
Possible fixes
(If you can, link to the line of code that might be responsible for the problem)
......
**Summary**
Summary
(Summarize the bug encountered concisely)
**Associated classes**
Associated classes
(Classes, which need to be modified, if any)
......
......@@ -10,7 +10,6 @@
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <boost/test/output_test_stream.hpp>
#include "../Solvers/DESolver.h"
/**
......@@ -116,6 +115,26 @@ BOOST_AUTO_TEST_SUITE(DESolver_test)
BOOST_CHECK_EQUAL(1, network->get_n_outputs());
}
BOOST_AUTO_TEST_CASE(DESolver_add_eq_test){
DESolver *deSolver = new DESolver(1,1,1);
MultiIndex *multiIndex = new MultiIndex(2);
multiIndex->set_partial_derivative(0,1);
multiIndex->set_partial_derivative(1,0.5);
deSolver->add_to_differential_equation(0, *multiIndex, 0.5);
std::vector<double> inp, out;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec_dy;
inp = {0.0};
out = {8.0};
data_vec_dy.emplace_back(std::make_pair(inp, out));
DataSet ds_02(&data_vec_dy);
deSolver->set_error_function( 0, ErrorFunctionType::ErrorFuncMSE, &ds_02 );
std::vector<double> weights;
weights.push_back(1.0);
BOOST_CHECK_EQUAL(64,deSolver->eval_total_error(weights));
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -13,14 +13,15 @@
struct cerr_redirect {
cerr_redirect(std::streambuf *new_buffer)
: old(std::cerr.rdbuf(new_buffer)
: old(std::cerr.rdbuf(new_buffer)
) {}
~cerr_redirect() {
std::cout.rdbuf(old);
}
private:
std::streambuf *old;
private:
std::streambuf *old;
};
/**
......@@ -38,7 +39,6 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
/**
* Test of add_neuron method
* TODO
* Existing bias out of range cancelation
*/
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_neuron_test) {
......@@ -47,7 +47,6 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
Neuron *n3 = new NeuronLinear();
Neuron *n4 = new NeuronLinear();
NeuralNetwork network;
//Tests of correct neuron indexs when add_neuron
......@@ -56,16 +55,18 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
BOOST_CHECK_EQUAL(1, network.add_neuron(n2, BIAS_TYPE::NEXT_BIAS));
BOOST_CHECK_EQUAL(2, network.add_neuron(n4, BIAS_TYPE::NO_BIAS));
//TODO fix dumping stack error
BOOST_CHECK_EQUAL(3, network.get_n_neurons());
BOOST_CHECK_EQUAL(2, network.get_n_biases());
//////TODO fix dumping stack error
// boost::test_tools::output_test_stream output;
// {
// cerr_redirect guard(output.rdbuf());
// network.add_neuron(n3, BIAS_TYPE::EXISTING_BIAS, 3);
// }
// BOOST_CHECK(output.is_equal("The supplied bias index is too large!\n\n"));
}
/**
......@@ -78,12 +79,13 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
network.add_neuron(n1, BIAS_TYPE::NO_BIAS);
network.add_neuron(n2, BIAS_TYPE::NO_BIAS);
BOOST_CHECK_EQUAL(0, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::NEXT_WEIGHT));
BOOST_CHECK_EQUAL(1, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::NEXT_WEIGHT, 5));
BOOST_CHECK_EQUAL(2, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::UNITARY_WEIGHT));
BOOST_CHECK_EQUAL(3, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::UNITARY_WEIGHT,5));
BOOST_CHECK_EQUAL(4, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::EXISTING_WEIGHT,1));
BOOST_CHECK_EQUAL(3, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::UNITARY_WEIGHT, 5));
BOOST_CHECK_EQUAL(4, network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::EXISTING_WEIGHT, 1));
BOOST_CHECK_EQUAL(2, network.get_n_weights());
//TODO fix dumping stack error
// boost::test_tools::output_test_stream output;
// {
......@@ -91,7 +93,6 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
// network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::EXISTING_WEIGHT,10);
// }
// BOOST_CHECK(output.is_equal("The supplied connection weight index is too large!\n\n"));
}
/**
......@@ -108,8 +109,8 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
BOOST_CHECK_EQUAL(0, network.get_n_inputs());
network.specify_input_neurons(inputs);
BOOST_CHECK_EQUAL(1, network.get_n_inputs());
}
BOOST_AUTO_TEST_CASE(NeuralNetwork_specify_outputs_neurons_test) {
NeuralNetwork network;
Neuron *n1 = new NeuronLinear();
......@@ -121,7 +122,6 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
BOOST_CHECK_EQUAL(0, network.get_n_outputs());
network.specify_output_neurons(outputs);
BOOST_CHECK_EQUAL(1, network.get_n_outputs());
}
BOOST_AUTO_TEST_CASE(NeuralNetwork_eval_single_test) {
......@@ -132,8 +132,7 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::UNITARY_WEIGHT , 2.5);
network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::UNITARY_WEIGHT, 2.5);
std::vector<size_t> output_neuron_indices;
output_neuron_indices.push_back(1);
......@@ -150,7 +149,28 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
network.eval_single(input, output);
BOOST_CHECK_EQUAL(5, output.at(0));
}
BOOST_AUTO_TEST_CASE(NeuralNetwork_randomize_weights_test) {
Neuron *n1 = new NeuronLinear();
Neuron *n2 = new NeuronLinear();
NeuralNetwork network;
network.add_neuron(n1, BIAS_TYPE::NO_BIAS);
network.add_neuron(n2, BIAS_TYPE::NO_BIAS);
for (int i = 0; i < 100; i++) {
network.add_connection_simple(0, 1, SIMPLE_CONNECTION_TYPE::NEXT_WEIGHT);
}
network.randomize_weights();
std::vector<double> *weights = network.get_parameter_ptr_weights();
double sum=0;
for (int i = 0; i < 100; i++) {
sum += weights->at(i);
}
sum=sum/100;
BOOST_CHECK(sum<0.15 && sum>-0.15);
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
......@@ -24,7 +24,8 @@ BOOST_AUTO_TEST_SUITE(ParticleSwarm_test)
BOOST_AUTO_TEST_CASE(ParticleSwarm_construction_test){
double domain_bound = 5;
std::vector<double> domain_bound;
domain_bound.push_back(5);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
......@@ -42,7 +43,8 @@ BOOST_AUTO_TEST_SUITE(ParticleSwarm_test)
}
BOOST_AUTO_TEST_CASE(ParticleSwarm_optimalize_test){
double domain_bound = 5;
std::vector<double> domain_bound;
domain_bound.push_back(5);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment