Skip to content
Snippets Groups Projects
Commit 0802a4da authored by Michal Kravcenko's avatar Michal Kravcenko
Browse files

Changed the structure and Connections, Neurons and Neural networks to be more...

Changed the structure and Connections, Neurons and Neural networks to be more clean and better suited for solving differential equations

Adjusted the class DESolver to account for the changes
parents 32b7bce3 8770eecd
No related branches found
No related tags found
No related merge requests found
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
#include "../NetConnection/Connection.h"
#include "../NetConnection/ConnectionWeight.h"
#include "../Neuron/NeuronLinear.h"
#include <iostream>
/**
* Boost testing suite for testing Connection.h
*/
BOOST_AUTO_TEST_SUITE(Connection_test)
/**
* Test of constructor of Connection
*/
BOOST_AUTO_TEST_CASE(Connection_construction__test) {
Neuron *neuron1 = new NeuronLinear(2, 3);
Neuron *neuron2 = new NeuronLinear(4, 5);
std::vector<double> w_array = {2, 3, 4, 5, 6};
ConnectionWeight *conn = new ConnectionWeight(2, &w_array);
Connection connection(neuron1, neuron2, conn);
//Test of correct input neuron
BOOST_CHECK_EQUAL(neuron1, connection.get_neuron_in());
//Test of correct output neuron
BOOST_CHECK_EQUAL(neuron2, connection.get_neuron_out());
}
/**
* Test of pass_signal method
*/
BOOST_AUTO_TEST_CASE(Connection_pass_signal_test) {
Neuron *neuron1 = new NeuronLinear(2, 3);
Neuron *neuron2 = new NeuronLinear(4, 5);
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);
Connection connection(neuron1, neuron2, conn);
neuron1->activate();
neuron2->activate();
// test of neuron state before passing signal
BOOST_CHECK_EQUAL(4, neuron2->get_state());
connection.pass_signal();
neuron2->activate();
// test of neuron state after passing signal
BOOST_CHECK_EQUAL(7204, neuron2->get_state());
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
......@@ -44,11 +44,11 @@ BOOST_AUTO_TEST_SUITE(neuronLogistic_test)
NeuronLogistic neuron(3.0, 2.0);
//Test of correct output of activation_function_get_derivative method
BOOST_CHECK_CLOSE(0.00447566759338, neuron.activation_function_eval_derivative(), 0.00001);
BOOST_CHECK_CLOSE(0.0042850850699, neuron.activation_function_eval_derivative(), 0.00001);
//Tests of correct outputs of activation_function_get_partial_derivative method
BOOST_CHECK_CLOSE(-0.0036025788498, neuron.activation_function_eval_partial_derivative(0), 0.00001);
BOOST_CHECK_CLOSE(-0.0044756675933, neuron.activation_function_eval_partial_derivative(1), 0.00001);
BOOST_CHECK_CLOSE(-0.0068569236644, neuron.activation_function_eval_partial_derivative(0), 0.00001);
BOOST_CHECK_CLOSE(-0.0042850850699, neuron.activation_function_eval_partial_derivative(1), 0.00001);
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_eval_partial_derivative(10000));
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
BOOST_AUTO_TEST_SUITE_END()
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
#include "../Neuron/NeuronTanh.h"
/**
* Boost testing suite for testing NeuronTanh.h
* doesn't test inherited methods
*/
BOOST_AUTO_TEST_SUITE(neuronTanh_test)
/**
* Test of creating new instance of NeuronTanh
*/
BOOST_AUTO_TEST_CASE(neuronTanh_construction__test) {
NeuronTanh neuron(1.745);
//Test of correct value of activation function parameter
BOOST_CHECK_EQUAL(neuron.activation_function_get_parameter(0), 1.745);
}
/**
* Test of activate method
*/
BOOST_AUTO_TEST_CASE(neuronTanh_activate__test) {
NeuronTanh neuron(2.0);
neuron.activate();
//Test of correct state after activate neuron
BOOST_CHECK_CLOSE(-0.96402758007581, neuron.get_state(), 0.00001);
}
/**
* Test of derivative methods
*/
BOOST_AUTO_TEST_CASE(neuronTanh_derivative_test) {
NeuronTanh neuron(2.0);
//Test of correct output of activation_function_get_derivative method
BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_eval_derivative(), 0.00001);
//Tests of correct outputs of activation_function_get_partial_derivative method
BOOST_CHECK_CLOSE(-0.0706508248531644, neuron.activation_function_eval_partial_derivative(0), 0.00001);
BOOST_CHECK_EQUAL(0.0, neuron.activation_function_eval_partial_derivative(10000));
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
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