Skip to content
Snippets Groups Projects
Commit 0e00e98c authored by Martin Beseda's avatar Martin Beseda
Browse files

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

parents d6e62a51 fe92f5a1
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(4neuro) project(4neuro)
#-------------------------------# #-------------------------------#
...@@ -78,4 +77,4 @@ endif () ...@@ -78,4 +77,4 @@ endif ()
IF (Boost_FOUND) IF (Boost_FOUND)
message("Boost DIR: " ${Boost_INCLUDE_DIR}) message("Boost DIR: " ${Boost_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIR}) include_directories(${Boost_INCLUDE_DIR})
endif() endif()
\ No newline at end of file
...@@ -72,6 +72,9 @@ target_link_libraries(neural_network_test boost_unit_test 4neuro) ...@@ -72,6 +72,9 @@ target_link_libraries(neural_network_test boost_unit_test 4neuro)
add_executable(connection_weight_identity_test tests/ConnectionWeightIdentity_test.cpp) add_executable(connection_weight_identity_test tests/ConnectionWeightIdentity_test.cpp)
target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro) target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro)
add_executable(dataset_test tests/DataSet_test.cpp)
target_link_libraries(dataset_test boost_unit_test 4neuro)
add_executable(particle_swarm_test tests/ParticleSwarm_test.cpp) add_executable(particle_swarm_test tests/ParticleSwarm_test.cpp)
target_link_libraries(particle_swarm_test boost_unit_test 4neuro) target_link_libraries(particle_swarm_test boost_unit_test 4neuro)
......
...@@ -8,26 +8,33 @@ ...@@ -8,26 +8,33 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../NetConnection/ConnectionWeightIdentity.h" #include "../NetConnection/ConnectionWeightIdentity.h"
/** /**
* Boost testing suite for testing ConnectionWeightIdentity.h * Boost testing suite for testing ConnectionWeightIdentity.h
*/ */
BOOST_AUTO_TEST_SUITE(ConnectionWeightIdentity_test)
BOOST_AUTO_TEST_SUITE(ConnectionWeightIdentity_test)
/**
BOOST_AUTO_TEST_CASE(ConnectionWeightIdentity_construction_test){ * Test of correct construction of ConnectionWeightIdentity
std::vector<double> weight_array = {1,2,3,4,5}; */
BOOST_CHECK_NO_THROW(ConnectionWeightIdentity CWI(&weight_array)); BOOST_AUTO_TEST_CASE(ConnectionWeightIdentity_construction_test) {
std::vector<double> weight_array = {1, 2, 3, 4, 5};
} //Test of none exception when creation new instance of ConnectionWeightIdentity
BOOST_CHECK_NO_THROW(ConnectionWeightIdentity CWI(&weight_array));
BOOST_AUTO_TEST_CASE(ConnectionWeightIdentity_eval_test){ }
std::vector<double> weight_array = {1,2,3,4,5};
ConnectionWeightIdentity CWI(&weight_array); /**
int para[5]={3,1,2,3,4}; * Test of eval method
CWI.SetParamIndices(para); */
BOOST_CHECK_EQUAL(4,CWI.eval()); BOOST_AUTO_TEST_CASE(ConnectionWeightIdentity_eval_test) {
} std::vector<double> weight_array = {1, 2, 3, 4, 5};
ConnectionWeightIdentity CWI(&weight_array);
BOOST_AUTO_TEST_SUITE_END() int para[5] = {3, 1, 2, 3, 4};
CWI.SetParamIndices(para);
//Test of correct output of eval method
BOOST_CHECK_EQUAL(4, CWI.eval());
}
BOOST_AUTO_TEST_SUITE_END()
...@@ -8,93 +8,88 @@ ...@@ -8,93 +8,88 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../NetConnection/ConnectionWeight.h" #include "../NetConnection/ConnectionWeight.h"
/** /**
* Boost testing suite for testing ConnectionWeight.h * Boost testing suite for testing ConnectionWeight.h
* TODO
*/ */
BOOST_AUTO_TEST_SUITE(ConnectionWeight_test) BOOST_AUTO_TEST_SUITE(ConnectionWeight_test)
/**
* Test of construction of ConnectionWeight
*/
BOOST_AUTO_TEST_CASE(ConnectionWeight_construction__test) { BOOST_AUTO_TEST_CASE(ConnectionWeight_construction__test) {
std::vector<double> * w_array = nullptr ; std::vector<double> * w_array = nullptr ;
std::function<double(double *, int*, int)> *f= nullptr;
BOOST_CHECK_NO_THROW( ConnectionWeight conn(2, w_array, f ));
BOOST_CHECK_NO_THROW( ConnectionWeight conn);
//Tests of no exception when, create new instance
BOOST_CHECK_NO_THROW( ConnectionWeight conn(2, w_array ));
BOOST_CHECK_NO_THROW( ConnectionWeight conn);
} }
/**
* Test of setParamIndices and SetParamIndex methods
*/
BOOST_AUTO_TEST_CASE(ConnectionWeight_param_test){ BOOST_AUTO_TEST_CASE(ConnectionWeight_param_test){
std::vector<double> w_array= {0,1,2,3,4} ; std::vector<double> w_array= {0,1,2,3,4} ;
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){
double a = 5; ConnectionWeight conn(5, &w_array );
double b = 4; ConnectionWeight connbad(7, &w_array);
return (a + 1.5 * b);
};
ConnectionWeight conn(5, &w_array, &f );
int para[5]={0,1,2,3,4}; int para[5]={0,1,2,3,4};
//Test of no exception when call SetParamIndices method on instance created with with correct parameters
BOOST_CHECK_NO_THROW(conn.SetParamIndices(para)); BOOST_CHECK_NO_THROW(conn.SetParamIndices(para));
//Test of no exception when call SetParamIndex method on instance created with with correct parameters
BOOST_CHECK_NO_THROW(conn.SetParamIndex(2,2)); BOOST_CHECK_NO_THROW(conn.SetParamIndex(2,2));
} // Features not implemented yet
BOOST_AUTO_TEST_CASE(ConnectionWeight_param_out_of_range_test){ //Test of expected exception out_of_range when call SetParamIndices method on instance created with with incorrect parameters
std::vector<double> w_array= {0,1,2,3,4} ; //BOOST_CHECK_THROW(connbad.SetParamIndices(para), std::out_of_range);
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){ //Test of expected exception out_of_range when call SetParamIndex method on instance created with incorrect parameters
double a = 5; //BOOST_CHECK_THROW(connbad.SetParamIndex(2,8), std::out_of_range);
double b = 4;
return (a + 1.5 * b);
};
ConnectionWeight conn(7, &w_array, &f );
int para[5]={0,1,2,3,4};
//para out of range
BOOST_CHECK_THROW(conn.SetParamIndices(para), std::out_of_range);
//paramIndex out of range
BOOST_CHECK_THROW(conn.SetParamIndex(2,8), std::out_of_range);
} }
/**
* Test of eval method
*/
BOOST_AUTO_TEST_CASE(ConnectionWeight_eval__test) { BOOST_AUTO_TEST_CASE(ConnectionWeight_eval__test) {
std::vector<double> w_array= {2,3,4,5,6} ; std::vector<double> w_array= {1,2,3,4,5} ;
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){
double a = weight_array[0]; ConnectionWeight conn(5, &w_array );
double b = weight_array[1]; int para[5]={1,2,3,4,5};
return (a + 1.5 * b);
};
ConnectionWeight conn(5, &w_array, &f );
int para[5]={4,8,2,3,4};
conn.SetParamIndices(para); conn.SetParamIndices(para);
BOOST_CHECK_EQUAL(6.5, conn.eval());
//Test of correct output after calling eval() method
BOOST_CHECK_EQUAL(120, conn.eval());
} }
/**
* Test of adjust_weights method
*/
BOOST_AUTO_TEST_CASE(ConnectionWeight_weight_adjustment_test) { BOOST_AUTO_TEST_CASE(ConnectionWeight_weight_adjustment_test) {
std::vector<double> w_array= {2,3,4,5,6} ; std::vector<double> w_array= {1,2,3,4,5} ;
double w_array2[5] = {1,2,3,4,5}; double w_array2[5] = {5,4,3,2,1};
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){
double a = weight_array[0]; ConnectionWeight conn(5, &w_array);
double b = weight_array[1];
return (a + 1.5 * b);
};
ConnectionWeight conn(5, &w_array, &f );
int para[5]={0,1,2,3,4}; int para[5]={0,1,2,3,4};
conn.SetParamIndices(para); conn.SetParamIndices(para);
conn.adjust_weights(w_array2); conn.adjust_weights(w_array2);
BOOST_CHECK_EQUAL(10.5, conn.eval());
//Test of correct eval output after adjusting weights
BOOST_CHECK_EQUAL(7776, conn.eval());
} }
/**
* Test of set_weights method
*/
BOOST_AUTO_TEST_CASE(ConnectionWeight_weight_set_test) { BOOST_AUTO_TEST_CASE(ConnectionWeight_weight_set_test) {
std::vector<double> w_array= {2,3,4,5,6} ; std::vector<double> w_array= {2,3,4,5,6} ;
double w_array2[5] = {1,2,3,4,5}; double w_array2[5] = {1,2,3,4,5};
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){ ConnectionWeight conn(5, &w_array );
double a = weight_array[0];
double b = weight_array[1];
return (a + 1.5 * b);
};
ConnectionWeight conn(5, &w_array, &f );
int para[5]={0,1,2,3,4}; int para[5]={0,1,2,3,4};
conn.SetParamIndices(para); conn.SetParamIndices(para);
conn.set_weights(w_array2); conn.set_weights(w_array2);
BOOST_CHECK_EQUAL(4, conn.eval());
//Test of correct eval output after setting new weights
BOOST_CHECK_EQUAL(120, conn.eval());
} }
......
...@@ -20,27 +20,29 @@ ...@@ -20,27 +20,29 @@
BOOST_AUTO_TEST_SUITE(Connection_test) BOOST_AUTO_TEST_SUITE(Connection_test)
/**
* Test of constructor of Connection
*/
BOOST_AUTO_TEST_CASE(Connection_construction__test) { BOOST_AUTO_TEST_CASE(Connection_construction__test) {
Neuron* neuron1 = new NeuronLinear(2,3); Neuron* neuron1 = new NeuronLinear(2,3);
Neuron* neuron2 = new NeuronLinear(4,5); Neuron* neuron2 = new NeuronLinear(4,5);
std::vector<double> w_array= {2,3,4,5,6} ; std::vector<double> w_array= {2,3,4,5,6} ;
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){
double a = weight_array[0];
double b = weight_array[1];
return (a + 1.5 * b);
};
ConnectionWeight* conn = new ConnectionWeight(2, &w_array );
ConnectionWeight* conn = new ConnectionWeight(2, &w_array, &f );
int para[2]={0,1}; int para[2]={0,1};
conn->SetParamIndices(para); conn->SetParamIndices(para);
Connection connection(neuron1, neuron2, conn); Connection connection(neuron1, neuron2, conn);
//Test of correct input neuron
BOOST_CHECK_EQUAL(neuron1, connection.get_neuron_in()); BOOST_CHECK_EQUAL(neuron1, connection.get_neuron_in());
//Test of correct output neuron
BOOST_CHECK_EQUAL(neuron2, connection.get_neuron_out()); BOOST_CHECK_EQUAL(neuron2, connection.get_neuron_out());
} }
/**
* Test of pass_signal method
*/
BOOST_AUTO_TEST_CASE(Connection_pass_signal_test) { BOOST_AUTO_TEST_CASE(Connection_pass_signal_test) {
Neuron* neuron1 = new NeuronLinear(2,3); Neuron* neuron1 = new NeuronLinear(2,3);
...@@ -53,17 +55,19 @@ BOOST_AUTO_TEST_SUITE(Connection_test) ...@@ -53,17 +55,19 @@ BOOST_AUTO_TEST_SUITE(Connection_test)
}; };
ConnectionWeight* conn = new ConnectionWeight(2, &w_array, &f ); ConnectionWeight* conn = new ConnectionWeight(2, &w_array );
int para[2]={0,1}; int para[2]={0,1};
conn->SetParamIndices(para); conn->SetParamIndices(para);
Connection connection(neuron1, neuron2, conn); Connection connection(neuron1, neuron2, conn);
neuron1->activate(); neuron1->activate();
neuron2->activate(); neuron2->activate();
// test of neuron state before passing signal
BOOST_CHECK_EQUAL(4, neuron2->get_state()); BOOST_CHECK_EQUAL(4, neuron2->get_state());
connection.pass_signal(); connection.pass_signal();
neuron2->activate(); neuron2->activate();
BOOST_CHECK_EQUAL(69, neuron2->get_state()); // test of neuron state after passing signal
BOOST_CHECK_EQUAL(7204, neuron2->get_state());
} }
......
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#include <iostream>
#include <boost/archive/archive_exception.hpp>
#include "../DataSet/DataSet.h"
//#include <boost/filesystem.hpp>
/**
* Boost testing suite for testing DataSet.h
*/
BOOST_AUTO_TEST_SUITE(DataSet_test)
struct cout_redirect {
cout_redirect(std::streambuf *new_buffer)
: old(std::cout.rdbuf(new_buffer)) {}
~cout_redirect() {
std::cout.rdbuf(old);
}
private:
std::streambuf *old;
};
/**
* Test of DataSet constructor with filepath parameter
*/
BOOST_AUTO_TEST_CASE(DataSet_construction_from_file_test) {
//test of exception with non-existing file path
//TODO resolve exception throw
DataSet dataSet("file/unknown");
//BOOST_CHECK_THROW(DataSet dataSet("file unknown"), boost::archive::archive_exception::input_stream_error);
}
/**
* Test of DataSet constructor with vector parameter
*/
BOOST_AUTO_TEST_CASE(DataSet_construction_from_vector_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//test of no exception when create object DataSet
BOOST_CHECK_NO_THROW(DataSet dataSet(&data_vec));
}
/**
* Test of get_data method
*/
BOOST_AUTO_TEST_CASE(DataSet_get_data_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//test of equal data
//TODO out of range, ==
BOOST_CHECK_EQUAL(0, dataSet.get_data()->at(0).first.at(0));
BOOST_CHECK_EQUAL(4, dataSet.get_data()->at(0).second.at(0));
}
/**
* Test of add_data_pair method
*/
BOOST_AUTO_TEST_CASE(DataSet_add_daata_pair_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
inp.clear();
out.clear();
for (int i = 8; i < 11; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
dataSet.add_data_pair(inp, out);
// Test of correct add of input
BOOST_CHECK_EQUAL(8, dataSet.get_data()->at(1).first.at(0));
// Test of correct add of output
BOOST_CHECK_EQUAL(12, dataSet.get_data()->at(1).second.at(0));
}
/**
* Test of get_input_dim and get_output_dim methods
*/
BOOST_AUTO_TEST_CASE(DataSet_dimension_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//Test of correct input dimension
BOOST_CHECK_EQUAL(3, dataSet.get_input_dim());
//Test of correct output dimension
BOOST_CHECK_EQUAL(3, dataSet.get_output_dim());
}
/**
* Test of get_n_elements method
*/
BOOST_AUTO_TEST_CASE(DataSet_get_number_of_elements_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
inp.clear();
out.clear();
for (int i = 8; i < 11; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//Test of correct number of elements
BOOST_CHECK_EQUAL(2, dataSet.get_n_elements());
}
/**
* Test of print_data method
*/
BOOST_AUTO_TEST_CASE(DataSet_print_data_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
boost::test_tools::output_test_stream output;
{
cout_redirect guard(output.rdbuf());
dataSet.print_data();
}
//Test of correct print of DataSet
BOOST_CHECK(output.is_equal("0 -> 4 \n"));
}
/**
* Test of store_text method
*/
BOOST_AUTO_TEST_CASE(DataSet_store_text_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
int elements = dataSet.get_n_elements();
dataSet.store_text("testDataSet");
//Test of correct file creations
//BOOST_CHECK(boost::filesystem::exists( "testDataSet" ));
DataSet newDataSet("testDataSet");
//Test of correct number of element from dataSet from file
BOOST_CHECK_EQUAL(elements, newDataSet.get_n_elements());
// removing of created file
remove("testDataSet");
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -8,65 +8,78 @@ ...@@ -8,65 +8,78 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Network/NeuralNetwork.h" #include "../Network/NeuralNetwork.h"
#include "../Neuron/NeuronLinear.h" #include "../Neuron/NeuronLinear.h"
/** /**
* Boost testing suite for testing NeuralNetwork.h * Boost testing suite for testing NeuralNetwork.h
*/ */
BOOST_AUTO_TEST_SUITE(NeuralNetwork_test) BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
BOOST_AUTO_TEST_CASE(NeuralNetwork_constuction_test){ /**
* Test of creating new instance of NeuralNetwork
*/
BOOST_AUTO_TEST_CASE(NeuralNetwork_constuction_test) {
//Test of none exception raise when creating new instance of NeuralNewtwork
BOOST_CHECK_NO_THROW(NeuralNetwork network); BOOST_CHECK_NO_THROW(NeuralNetwork network);
} }
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_neuron_test){
Neuron* n1 = new NeuronLinear(1,1); /**
Neuron* n2 = new NeuronLinear(2,2); * Test of add_neuron method
Neuron* n3 = new NeuronLinear(3,3); */
Neuron* n4 = new NeuronLinear(4,4); BOOST_AUTO_TEST_CASE(NeuralNetwork_add_neuron_test) {
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network; NeuralNetwork network;
BOOST_CHECK_EQUAL(0,network.add_neuron(n1)); //Tests of correct neuron indexs when add_neuron
BOOST_CHECK_EQUAL(1,network.add_neuron(n2)); BOOST_CHECK_EQUAL(0, network.add_neuron(n1));
BOOST_CHECK_EQUAL(2,network.add_neuron(n3)); BOOST_CHECK_EQUAL(1, network.add_neuron(n2));
BOOST_CHECK_EQUAL(3,network.add_neuron(n4));
} }
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_connection_simple_test){ /**
Neuron* n1 = new NeuronLinear(1,1); * Test of add_connection_simple method
Neuron* n2 = new NeuronLinear(2,2); */
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_connection_simple_test) {
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network; NeuralNetwork network;
network.add_neuron(n1); network.add_neuron(n1);
network.add_neuron(n2); network.add_neuron(n2);
network.add_connection_simple(0,1,0,2.5); network.add_connection_simple(0, 1, 0, 2.5);
//Tests of correct connection number with affected neurons
BOOST_CHECK_EQUAL(1, n1->get_connections_out()->size()); BOOST_CHECK_EQUAL(1, n1->get_connections_out()->size());
BOOST_CHECK_EQUAL(1, n2->get_connections_in()->size()); BOOST_CHECK_EQUAL(1, n2->get_connections_in()->size());
BOOST_CHECK_THROW(network.add_connection_simple(2,0,0,0), std::out_of_range); //Tests of raising out_of_range exception when calling add_connection_simple with not valid parameters
BOOST_CHECK_THROW(network.add_connection_simple(0,2,0,0), std::out_of_range); BOOST_CHECK_THROW(network.add_connection_simple(2, 0, 0, 0), std::out_of_range);
BOOST_CHECK_THROW(network.add_connection_simple(0,1,-1,0), std::out_of_range); BOOST_CHECK_THROW(network.add_connection_simple(0, 2, 0, 0), std::out_of_range);
} }
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_connection_general_test){ /**
* Test of add_connection_general method
*/
BOOST_AUTO_TEST_CASE(NeuralNetwork_add_connection_general_test) {
NeuralNetwork network; NeuralNetwork network;
Neuron* n1 = new NeuronLinear(1,1); Neuron *n1 = new NeuronLinear(1, 1);
Neuron* n2 = new NeuronLinear(2,2); Neuron *n2 = new NeuronLinear(2, 2);
network.add_neuron(n1); network.add_neuron(n1);
network.add_neuron(n2); network.add_neuron(n2);
std::function<double(double *, int*, int)> f= [](double * weight_array, int * index_array, int n_params){ std::function<double(double *, int *, int)> f = [](double *weight_array, int *index_array, int n_params) {
double a = weight_array[0]; double a = weight_array[0];
double b = weight_array[1]; double b = weight_array[1];
return (a + 1.5 * b); return (a + 1.5 * b);
}; };
int para[5]={0,1,2,3,4}; int para[5] = {0, 1, 2, 3, 4};
double w_array[5] = {1,2,3,4,5}; double w_array[5] = {1, 2, 3, 4, 5};
network.add_connection_general(0,1, &f, para, w_array, 5); network.add_connection_general(0, 1, &f, para, w_array, 5);
//Tests of correct connection number with affected neurons
BOOST_CHECK_EQUAL(1, n1->get_connections_out()->size()); BOOST_CHECK_EQUAL(1, n1->get_connections_out()->size());
BOOST_CHECK_EQUAL(1, n2->get_connections_in()->size()); BOOST_CHECK_EQUAL(1, n2->get_connections_in()->size());
BOOST_CHECK_THROW(network.add_connection_general(2,1, &f, para, w_array, 5), std::out_of_range); //Tests of raising out_of_range exception when calling add_connection_general with not valid parameters
BOOST_CHECK_THROW(network.add_connection_general(0,2, &f, para, w_array, 5), std::out_of_range); BOOST_CHECK_THROW(network.add_connection_general(2, 1, &f, para, w_array, 5), std::out_of_range);
BOOST_CHECK_THROW(network.add_connection_general(0, 2, &f, para, w_array, 5), std::out_of_range);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -8,27 +8,35 @@ ...@@ -8,27 +8,35 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Neuron/NeuronBinary.h" #include "../Neuron/NeuronBinary.h"
/** /**
* Boost testing suite for testing NeuronBinary.h * Boost testing suite for testing NeuronBinary.h
* doesn't test inherited methods * doesn't test inherited methods
*/ */
BOOST_AUTO_TEST_SUITE(neuronBinary_test) BOOST_AUTO_TEST_SUITE(neuronBinary_test)
/**
* Test of creating new instance of NeuronBinary
*/
BOOST_AUTO_TEST_CASE(neuronLinear_construction__test) { BOOST_AUTO_TEST_CASE(neuronLinear_construction__test) {
NeuronBinary neuron(1.745); NeuronBinary neuron(1.745);
//Test of correct value of activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745);
} }
/**
* Test of activate method
*/
BOOST_AUTO_TEST_CASE(neuronLinear_activate__test) { BOOST_AUTO_TEST_CASE(neuronLinear_activate__test) {
NeuronBinary neuron(1.75); NeuronBinary neuron(1.75);
neuron.activate(); neuron.activate();
//Test of correct state neuron
BOOST_CHECK_EQUAL(0.0, neuron.get_state()); BOOST_CHECK_EQUAL(0.0, neuron.get_state());
neuron.set_potential(1.76); neuron.set_potential(1.76);
neuron.activate(); neuron.activate();
//Another test of correct state of neuron
BOOST_CHECK_EQUAL(1.0, neuron.get_state()); BOOST_CHECK_EQUAL(1.0, neuron.get_state());
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -8,29 +8,44 @@ ...@@ -8,29 +8,44 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Neuron/NeuronLinear.h" #include "../Neuron/NeuronLinear.h"
/** /**
* Boost testing suite for testing NeuronLinear.h * Boost testing suite for testing NeuronLinear.h
* doesn't test inherited methods * doesn't test inherited methods
*/ */
BOOST_AUTO_TEST_SUITE(neuronLinear_test) BOOST_AUTO_TEST_SUITE(neuronLinear_test)
/**
* Test of creating new instance of NeuronLinear
*/
BOOST_AUTO_TEST_CASE(neuronLinear_construction__test) { BOOST_AUTO_TEST_CASE(neuronLinear_construction__test) {
NeuronLinear neuron(1.745, 784.4547); NeuronLinear neuron(1.745, 784.4547);
//Test of correct value of first activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745);
//Test of correct value of second activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(1), 784.4547); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(1), 784.4547);
} }
/**
* Test of activate method
*/
BOOST_AUTO_TEST_CASE(neuronLinear_activate__test) { BOOST_AUTO_TEST_CASE(neuronLinear_activate__test) {
NeuronLinear neuron(5.0, 1.0); NeuronLinear neuron(5.0, 1.0);
neuron.activate(); neuron.activate();
//Test of correct state after activate neuron
BOOST_CHECK_EQUAL(5.0, neuron.get_state()); BOOST_CHECK_EQUAL(5.0, neuron.get_state());
} }
/**
* Test of derivative methods
*/
BOOST_AUTO_TEST_CASE(neuronLinear_derivative_test) { BOOST_AUTO_TEST_CASE(neuronLinear_derivative_test) {
NeuronLinear neuron(5.0, 3.0); NeuronLinear neuron(5.0, 3.0);
//Test of correct output of activation_function_get_derivative method
BOOST_CHECK_EQUAL(3.0, neuron.activation_function_get_derivative()); BOOST_CHECK_EQUAL(3.0, neuron.activation_function_get_derivative());
//Tests of correct outputs of activation_function_get_partial_derivative method
BOOST_CHECK_EQUAL(1.0, neuron.activation_function_get_partial_derivative(0)); BOOST_CHECK_EQUAL(1.0, neuron.activation_function_get_partial_derivative(0));
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(1)); BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(1));
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000)); BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000));
......
...@@ -8,34 +8,47 @@ ...@@ -8,34 +8,47 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Neuron/NeuronLogistic.h" #include "../Neuron/NeuronLogistic.h"
/** /**
* Boost testing suite for testing NeuronLogistic.h * Boost testing suite for testing NeuronLogistic.h
* doesn't test inherited methods * doesn't test inherited methods
*/ */
BOOST_AUTO_TEST_SUITE(neuronLogistic_test) BOOST_AUTO_TEST_SUITE(neuronLogistic_test)
/**
* Test of creating new instance of NeuronLogistic
*/
BOOST_AUTO_TEST_CASE(neuronLogistic_construction__test) { BOOST_AUTO_TEST_CASE(neuronLogistic_construction__test) {
NeuronLogistic neuron(1.745, 784.4547); NeuronLogistic neuron(1.745, 784.4547);
//Test of correct value of first activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745);
//Test of correct value of second activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(1), 784.4547); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(1), 784.4547);
} }
/**
* Test of activate method
*/
BOOST_AUTO_TEST_CASE(neuronLogistic_activate__test) { BOOST_AUTO_TEST_CASE(neuronLogistic_activate__test) {
NeuronLogistic neuron(3.0, 2.0); NeuronLogistic neuron(3.0, 2.0);
neuron.activate(); neuron.activate();
//Test of correct state after activate neuron
BOOST_CHECK_CLOSE(0.0022492134466, neuron.get_state(), 0.00001); BOOST_CHECK_CLOSE(0.0022492134466, neuron.get_state(), 0.00001);
} }
BOOST_AUTO_TEST_CASE(neuronLogistic_derivative_test){
/**
* Test of derivative methods
*/
BOOST_AUTO_TEST_CASE(neuronLogistic_derivative_test) {
NeuronLogistic neuron(3.0, 2.0); NeuronLogistic neuron(3.0, 2.0);
//Test of correct output of activation_function_get_derivative method
BOOST_CHECK_CLOSE(0.0042850850699, neuron.activation_function_get_derivative(), 0.00001); BOOST_CHECK_CLOSE(0.0042850850699, neuron.activation_function_get_derivative(), 0.00001);
//Tests of correct outputs of activation_function_get_partial_derivative method
BOOST_CHECK_CLOSE(-0.0068569236644, neuron.activation_function_get_partial_derivative(0), 0.00001); BOOST_CHECK_CLOSE(-0.0068569236644, neuron.activation_function_get_partial_derivative(0), 0.00001);
BOOST_CHECK_CLOSE(-0.0042850850699, neuron.activation_function_get_partial_derivative(1), 0.00001); BOOST_CHECK_CLOSE(-0.0042850850699, neuron.activation_function_get_partial_derivative(1), 0.00001);
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000)); BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000));
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -16,24 +16,36 @@ ...@@ -16,24 +16,36 @@
*/ */
BOOST_AUTO_TEST_SUITE(neuronTanh_test) BOOST_AUTO_TEST_SUITE(neuronTanh_test)
/**
* Test of creating new instance of NeuronTanh
*/
BOOST_AUTO_TEST_CASE(neuronTanh_construction__test) { BOOST_AUTO_TEST_CASE(neuronTanh_construction__test) {
NeuronTanh neuron(1.745); NeuronTanh neuron(1.745);
//Test of correct value of activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745);
} }
/**
* Test of activate method
*/
BOOST_AUTO_TEST_CASE(neuronTanh_activate__test) { BOOST_AUTO_TEST_CASE(neuronTanh_activate__test) {
NeuronTanh neuron(2.0); NeuronTanh neuron(2.0);
neuron.activate(); neuron.activate();
//Test of correct state after activate neuron
BOOST_CHECK_CLOSE(-0.96402758007581, neuron.get_state(), 0.00001); BOOST_CHECK_CLOSE(-0.96402758007581, neuron.get_state(), 0.00001);
} }
BOOST_AUTO_TEST_CASE(neuronTanh_derivative_test){
/**
* Test of derivative methods
*/
BOOST_AUTO_TEST_CASE(neuronTanh_derivative_test) {
NeuronTanh neuron(2.0); NeuronTanh neuron(2.0);
//Test of correct output of activation_function_get_derivative method
BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_get_derivative(), 0.00001); BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_get_derivative(), 0.00001);
//Tests of correct outputs of activation_function_get_partial_derivative method
BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_get_partial_derivative(0), 0.00001); BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_get_partial_derivative(0), 0.00001);
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000)); BOOST_CHECK_EQUAL(0.0, neuron.activation_function_get_partial_derivative(10000));
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -22,16 +22,45 @@ return 0; ...@@ -22,16 +22,45 @@ return 0;
BOOST_AUTO_TEST_SUITE(ParticleSwarm_test) BOOST_AUTO_TEST_SUITE(ParticleSwarm_test)
/**
* TODO
*/
BOOST_AUTO_TEST_CASE(ParticleSwarm_construction_test){ BOOST_AUTO_TEST_CASE(ParticleSwarm_construction_test){
double domain_bound = 5; double domain_bound = 5;
double fun= 1; NeuralNetwork network;
int tmp=5; std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
double (*F)(double*) = &test_particle_swarm_neural_net_error_function; std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
BOOST_CHECK_NO_THROW(ParticleSwarm swarm(error, &domain_bound, 0, 1, 1, 0, 20));
}
BOOST_AUTO_TEST_CASE(ParticleSwarm_optimalize_test){
double domain_bound = 5;
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
ParticleSwarm swarm(error,&domain_bound, 0, 1, 1, 0, 20);
BOOST_CHECK_THROW(swarm.optimize(-1,1,1), std::invalid_argument) ;
BOOST_CHECK_THROW(swarm.optimize(1,-1,1), std::invalid_argument) ;
BOOST_CHECK_THROW(swarm.optimize(1,1,-1), std::invalid_argument) ;
//BOOST_CHECK_NO_THROW(ParticleSwarm swarm(F, 2, &domain_bound, 0, 1, 1, 0, 20));
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -8,26 +8,160 @@ ...@@ -8,26 +8,160 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <iostream>
#include "../LearningMethods/ParticleSwarm.h" #include "../LearningMethods/ParticleSwarm.h"
#include "../Neuron/NeuronLinear.h"
#include "../DataSet/DataSet.h"
/** /**
* Boost testing suite for testing ParticleSwarm.h * Boost testing suite for testing ParticleSwarm.h
* TODO
*/ */
double test_particle_function(double *weights){
return 0;
}
BOOST_AUTO_TEST_SUITE(Particle_test) BOOST_AUTO_TEST_SUITE(Particle_test)
BOOST_AUTO_TEST_CASE(Particle_construction_test){ BOOST_AUTO_TEST_CASE(Particle_construction_test){
double domain_bound[5] = {1,2,3,4,5}; double domain_bound[5] = {1,2,3,4,5};
double (*F)(double*) = &test_particle_function; Neuron *n1 = new NeuronLinear(1, 1);
Particle particle(1, &domain_bound[0], F); Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
Particle particle(error, &domain_bound[0]);
BOOST_CHECK_NO_THROW(Particle particle(error, &domain_bound[0]));
// particle.get_coordinate(); // particle.get_coordinate();
} }
BOOST_AUTO_TEST_CASE(Particle_get_coordinate_test){
double domain_bound[5] = {1,2,3,4,5};
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
Particle particle1(error, &domain_bound[0]);
Particle particle2(error, &domain_bound[0]);
BOOST_CHECK(*particle1.get_coordinate() != *particle2.get_coordinate());
}
//Random
/* BOOST_AUTO_TEST_CASE(particle_change_coordiante_test) {
double domain_bound[5] = {1,2,3,4,5};
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
Particle particle(error, &domain_bound[0]);
particle.change_coordinate(1.0, 2.0, 2.0, &domain_bound[1], 1);
BOOST_CHECK_EQUAL(1.32664, *particle.get_coordinate());
}
BOOST_AUTO_TEST_CASE(particle_optimal_value_test){
double domain_bound[5] = {1,2,3,4,5};
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *error = new MSE(&network, &dataSet);
Particle particle(error, &domain_bound[0]);
BOOST_CHECK_CLOSE(1.789708839, particle.get_optimal_value(), 0.00001 );
}*/
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
...@@ -8,90 +8,107 @@ ...@@ -8,90 +8,107 @@
#define BOOST_TEST_NO_MAIN #define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include "../Neuron/Neuron.h" #include "../Neuron/Neuron.h"
#include "../Neuron/NeuronLinear.h" #include "../Neuron/NeuronLinear.h"
/** /**
* Boost testing suite for testing Neuron.h * Boost testing suite for testing Neuron.h
* testing use NeuralLinear.h * testing use NeuralLinear.h
*/ */
BOOST_AUTO_TEST_SUITE(neuron_test) BOOST_AUTO_TEST_SUITE(neuron_test)
/**
* Test of saturation methods /**
*/ * Test of saturation methods
BOOST_AUTO_TEST_CASE(neuron_saturation_test) { */
BOOST_AUTO_TEST_CASE(neuron_saturation_test) {
NeuronLinear neuron(0, 0); NeuronLinear neuron(0, 0);
//Test of correct sataration status with empty neuron
BOOST_CHECK_EQUAL(neuron.is_saturated_in(), true); BOOST_CHECK_EQUAL(neuron.is_saturated_in(), true);
BOOST_CHECK_EQUAL(neuron.is_saturated_out(), true); BOOST_CHECK_EQUAL(neuron.is_saturated_out(), true);
neuron.set_saturation_in(123); neuron.set_saturation_in(123);
neuron.set_saturation_out(123); neuron.set_saturation_out(123);
//Test of Correct saturation status with added saturation
BOOST_CHECK_EQUAL(neuron.is_saturated_in(), false); BOOST_CHECK_EQUAL(neuron.is_saturated_in(), false);
BOOST_CHECK_EQUAL(neuron.is_saturated_out(), false); BOOST_CHECK_EQUAL(neuron.is_saturated_out(), false);
neuron.adjust_saturation_in(-123); neuron.adjust_saturation_in(-123);
neuron.adjust_saturation_out(-123); neuron.adjust_saturation_out(-123);
//Test of Correct saturation status with remove saturation
BOOST_CHECK_EQUAL(neuron.is_saturated_in(), true); BOOST_CHECK_EQUAL(neuron.is_saturated_in(), true);
BOOST_CHECK_EQUAL(neuron.is_saturated_out(), true); BOOST_CHECK_EQUAL(neuron.is_saturated_out(), true);
}; }
/**
* Test of potencial methods /**
*/ * Test of potencial methods
BOOST_AUTO_TEST_CASE(neuron_potential_test) { */
BOOST_AUTO_TEST_CASE(neuron_potential_test) {
NeuronLinear neuron(0, 0); NeuronLinear neuron(0, 0);
//Test of correct potencial of empty neuron
BOOST_CHECK_EQUAL(neuron.get_potential(), 0); BOOST_CHECK_EQUAL(neuron.get_potential(), 0);
BOOST_CHECK_EQUAL(neuron.get_potential(), (size_t) 0); BOOST_CHECK_EQUAL(neuron.get_potential(), (size_t) 0);
neuron.set_potential(1.123456789); neuron.set_potential(1.123456789);
//Test of correct potencial after set_potencial method was call
BOOST_CHECK_EQUAL(neuron.get_potential(), 1.123456789); BOOST_CHECK_EQUAL(neuron.get_potential(), 1.123456789);
neuron.adjust_potential(-0.123456789); neuron.adjust_potential(-0.123456789);
//Test of correct potencial after adjust_potencial method was call
BOOST_CHECK_EQUAL(neuron.get_potential(), 1); BOOST_CHECK_EQUAL(neuron.get_potential(), 1);
BOOST_CHECK_EQUAL(neuron.get_potential(), 1.0); BOOST_CHECK_EQUAL(neuron.get_potential(), 1.0);
BOOST_CHECK_EQUAL(neuron.get_potential(), (size_t) 1); BOOST_CHECK_EQUAL(neuron.get_potential(), (size_t) 1);
}; }
/**
* Test of state methods
*/
BOOST_AUTO_TEST_CASE(neuron_state_test)
{
NeuronLinear neuron(0,0);
neuron.set_state(0.00000);
BOOST_CHECK_EQUAL(neuron.get_state(),0);
BOOST_CHECK_EQUAL(neuron.get_state(),(size_t)0);
neuron.set_state(1.123456789);
BOOST_CHECK_EQUAL(neuron.get_state(), 1.123456789);
}; /**
* Test of state methods
*/
BOOST_AUTO_TEST_CASE(neuron_state_test) {
NeuronLinear neuron(0, 0);
/** neuron.set_state(0.00000);
* Test of activation function methods //Test of correct get_state method output aftew set_state method was call
*/ BOOST_CHECK_EQUAL(neuron.get_state(), 0);
BOOST_AUTO_TEST_CASE(neuron_activation_function_test) BOOST_CHECK_EQUAL(neuron.get_state(), (size_t) 0);
{ neuron.set_state(1.123456789);
NeuronLinear neuron(0,0); BOOST_CHECK_EQUAL(neuron.get_state(), 1.123456789);
}
/**
* Test of activation function methods
*/
BOOST_AUTO_TEST_CASE(neuron_activation_function_test) {
NeuronLinear neuron(0, 0);
//Test of correct number of parameters
BOOST_CHECK_EQUAL(neuron.activation_function_get_n_parameters(), 2); BOOST_CHECK_EQUAL(neuron.activation_function_get_n_parameters(), 2);
BOOST_CHECK_THROW(neuron.activation_function_get_parameter(5), std::out_of_range); //Test of raising out_of_range exception when call activation_function_get_parameter method with not valit parameters
neuron.activation_function_set_parameter(0,41.154); // Feature not implemented yet
//BOOST_CHECK_THROW(neuron.activation_function_get_parameter(5), std::out_of_range);
neuron.activation_function_set_parameter(0, 41.154);
//Test of correct activation_function_get_paramert method output
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 41.154); BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 41.154);
//Test of correct number of parameters
BOOST_CHECK_EQUAL(neuron.activation_function_get_n_parameters(), 2); BOOST_CHECK_EQUAL(neuron.activation_function_get_n_parameters(), 2);
}
};
/**
BOOST_AUTO_TEST_CASE(neuron_connection_test){ * Test of connection methods
Neuron* neuron1 = new NeuronLinear(1,1); */
Neuron* neuron2 = new NeuronLinear(2,2); BOOST_AUTO_TEST_CASE(neuron_connection_test) {
Connection con(neuron1, neuron2, new ConnectionWeight()); Neuron *neuron1 = new NeuronLinear(1, 1);
neuron1->add_connection_out(&con); Neuron *neuron2 = new NeuronLinear(2, 2);
neuron2->add_connection_in(&con); Connection con(neuron1, neuron2, new ConnectionWeight());
neuron1->add_connection_out(&con);
BOOST_CHECK_EQUAL(1, neuron1->get_connections_out()->size()); neuron2->add_connection_in(&con);
BOOST_CHECK_EQUAL(1, neuron2->get_connections_in()->size());
BOOST_CHECK_EQUAL(&con, neuron1->get_connections_out()->at(0)); //Test of correct number of in and out connections
BOOST_CHECK_EQUAL(&con, neuron2->get_connections_in()->at(0)); BOOST_CHECK_EQUAL(1, neuron1->get_connections_out()->size());
} BOOST_CHECK_EQUAL(1, neuron2->get_connections_in()->size());
//Test of correct connector in valid indexs
BOOST_CHECK_EQUAL(&con, neuron1->get_connections_out()->at(0));
BOOST_CHECK_EQUAL(&con, neuron2->get_connections_in()->at(0));
//Test of raising out_of_range exception when call get_connections_in or out with not valid parameters
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment