diff --git a/esn.hpp b/esn.hpp index eeb87e3..2e7b557 100644 --- a/esn.hpp +++ b/esn.hpp @@ -40,6 +40,7 @@ #include #include +#include #include diff --git a/esn_2.hpp b/esn_2.hpp index ede5419..cfc98e9 100644 --- a/esn_2.hpp +++ b/esn_2.hpp @@ -39,8 +39,8 @@ #define _NN_ESN_HPP_ #include -#include #include +#include #include #include diff --git a/test_dnn_ff_io.cpp b/test_dnn_ff_io.cpp new file mode 100644 index 0000000..0cc8d47 --- /dev/null +++ b/test_dnn_ff_io.cpp @@ -0,0 +1,142 @@ +//| This file is a part of the sferes2 framework. +//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC) +//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr +//| +//| This software is a computer program whose purpose is to facilitate +//| experiments in evolutionary computation and evolutionary robotics. +//| +//| This software is governed by the CeCILL license under French law +//| and abiding by the rules of distribution of free software. You +//| can use, modify and/ or redistribute the software under the terms +//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the +//| following URL "http://www.cecill.info". +//| +//| As a counterpart to the access to the source code and rights to +//| copy, modify and redistribute granted by the license, users are +//| provided only with a limited warranty and the software's author, +//| the holder of the economic rights, and the successive licensors +//| have only limited liability. +//| +//| In this respect, the user's attention is drawn to the risks +//| associated with loading, using, modifying and/or developing or +//| reproducing the software by the user in light of its specific +//| status of free software, that may mean that it is complicated to +//| manipulate, and that also therefore means that it is reserved for +//| developers and experienced professionals having in-depth computer +//| knowledge. Users are therefore encouraged to load and test the +//| software's suitability as regards their requirements in conditions +//| enabling the security of their systems and/or data to be ensured +//| and, more generally, to use and operate it in the same conditions +//| as regards security. +//| +//| The fact that you are presently reading this means that you have +//| had knowledge of the CeCILL license and that you accept its terms. + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE dnn_ff + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include "gen_dnn_ff.hpp" +#include "phen_dnn.hpp" + +using namespace sferes; +using namespace sferes::gen::dnn; +using namespace sferes::gen::evo_float; +using boost::archive::xml_oarchive; +using boost::archive::xml_iarchive; +using boost::serialization::make_nvp; + +struct Params +{ + struct evo_float + { + SFERES_CONST float mutation_rate = 0.1f; + SFERES_CONST float cross_rate = 0.1f; + SFERES_CONST mutation_t mutation_type = polynomial; + SFERES_CONST cross_over_t cross_over_type = sbx; + SFERES_CONST float eta_m = 15.0f; + SFERES_CONST float eta_c = 15.0f; + }; + struct parameters + { + // maximum value of parameters + SFERES_CONST float min = -5.0f; + // minimum value + SFERES_CONST float max = 5.0f; + }; + struct dnn + { + SFERES_CONST size_t nb_inputs = 4; + SFERES_CONST size_t nb_outputs = 1; + SFERES_CONST size_t min_nb_neurons = 4; + SFERES_CONST size_t max_nb_neurons = 5; + SFERES_CONST size_t min_nb_conns = 100; + SFERES_CONST size_t max_nb_conns = 101; + + SFERES_CONST float m_rate_add_conn = 1.0f; + SFERES_CONST float m_rate_del_conn = 0.1f; + SFERES_CONST float m_rate_change_conn = 1.0f; + SFERES_CONST float m_rate_add_neuron = 1.0f; + SFERES_CONST float m_rate_del_neuron = 1.0f; + + SFERES_CONST int io_param_evolving = true; + SFERES_CONST init_t init = ff; + }; +}; + +BOOST_AUTO_TEST_CASE(direct_nn_ff_io) +{ + srand(time(0)); + typedef phen::Parameters, fit::FitDummy<>, Params> weight_t; + typedef phen::Parameters, fit::FitDummy<>, Params> bias_t; + typedef nn::PfWSum pf_t; + typedef nn::AfSigmoidBias af_t; + typedef nn::Neuron neuron_t; + typedef nn::Connection connection_t; + typedef gen::DnnFF gen_t; + typedef phen::Dnn, Params> phen_t; + phen_t i; + i.random(); + i.develop(); + std::vector in(Params::dnn::nb_inputs, 0); + for(int i=0;i(0, 1); + i.nn().step(in); + float output1 = i.nn().get_neuron_output(0); + i.show(std::cout); + + std::ofstream ofs("/tmp/nn.xml"); + xml_oarchive xml(ofs); + xml << make_nvp("test", i); + ofs.close(); + + + phen_t* i2 = new phen_t; + std::ifstream inputFile("/tmp/nn.xml"); + xml_iarchive xml2(inputFile); + xml2 >> make_nvp("test", *i2); + inputFile.close(); + + i2->develop(); + i2->nn().step(in); + float output2 = i2->nn().get_neuron_output(0); + i2->show(std::cout); + + std::cout << output1 << " " << output2; + BOOST_CHECK_EQUAL(output1, output2); +} + diff --git a/wscript b/wscript index 60d34ff..5b2db92 100644 --- a/wscript +++ b/wscript @@ -92,7 +92,16 @@ def build(bld): test_esn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION' test_esn.target = 'test_dnn_ff' test_esn.unit_test = 1 - + + + test_esn = bld.new_task_gen('cxx', 'program') + test_esn.source = 'test_dnn_ff_io.cpp' + test_esn.includes = '. ../../' + test_esn.uselib_local = 'sferes2' + test_esn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION' + test_esn.target = 'test_dnn_ff_io' + test_esn.unit_test = 1 + test_osc = bld.new_task_gen('cxx', 'program')