diff --git a/src/LearningMethods/LearningMethods.cpp b/src/LearningMethods/LearningMethods.cpp index f816582a109c07326370322cc94ed821e266b0c8..545784952abd238a6c6f383157602d73b2f4fd0a 100644 --- a/src/LearningMethods/LearningMethods.cpp +++ b/src/LearningMethods/LearningMethods.cpp @@ -1,13 +1,8 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄŤenko - * @date 10.9.18 - - */ #include "LearningMethod.h" namespace lib4neuro { + //TODO NOT SAFE!!!! std::vector<double>* LearningMethod::get_parameters() { return &this->optimal_parameters; } @@ -17,4 +12,4 @@ namespace lib4neuro { this->optimize(ef, ofs); } -} \ No newline at end of file +} diff --git a/src/LearningMethods/ParticleSwarm.cpp b/src/LearningMethods/ParticleSwarm.cpp index ccc823fee556a6d52d0a26cc89121205c6216fa0..dc3b35080ae059dd148e4c6874ed4783de7f30ed 100644 --- a/src/LearningMethods/ParticleSwarm.cpp +++ b/src/LearningMethods/ParticleSwarm.cpp @@ -299,7 +299,7 @@ namespace lib4neuro { /* initialize the particles */ - for (size_t pi = 0; pi < this->n_particles; ++pi) { + for (size_t pi = 0; pi < this->particle_swarm.size(); ++pi) { if (this->particle_swarm.at(pi)) { delete this->particle_swarm.at(pi); } @@ -548,9 +548,10 @@ namespace lib4neuro { this->w = w; this->n_particles = n_particles; this->iter_max = iter_max; + this->particle_swarm.resize(this->n_particles); std::fill(this->particle_swarm.begin(), this->particle_swarm.end(), nullptr); } -} \ No newline at end of file +} diff --git a/src/Neuron/NeuronBiased.cpp b/src/Neuron/NeuronBiased.cpp index 12974082e287e72898b839d40fb3a79267f5ea3a..65fd468d79f49196c69887862ddaf69058e19d8b 100644 --- a/src/Neuron/NeuronBiased.cpp +++ b/src/Neuron/NeuronBiased.cpp @@ -1,9 +1,3 @@ -/** - * DESCRIPTION OF THE FILE - * - * @author Michal KravÄŤenko - * @date 15.3.19 - - */ #include <boost/serialization/export.hpp> @@ -40,4 +34,4 @@ namespace lib4neuro { return output; } -}//end of namespace lib4neuro \ No newline at end of file +}//end of namespace lib4neuro diff --git a/src/Solvers/DESolver.cpp b/src/Solvers/DESolver.cpp index 3a82547c833731ea4576e4e4dba3bcb81246a4cf..2262b7bed1ea79e40df4ef7d1dbefb620ff1e7a8 100644 --- a/src/Solvers/DESolver.cpp +++ b/src/Solvers/DESolver.cpp @@ -91,6 +91,8 @@ namespace lib4neuro { this->dim_i = n_inputs; this->dim_inn = m; this->n_equations = n_equations; + this->errors_functions_types.resize(n_equations); + this->errors_functions_data_sets.resize(n_equations); diff --git a/src/examples/net_test_1.cpp b/src/examples/net_test_1.cpp index f659c71281d8e73a79a7cd4561ed31e04d2615ea..deeb7841c7db3779c97f948eb13f7de67096777e 100644 --- a/src/examples/net_test_1.cpp +++ b/src/examples/net_test_1.cpp @@ -159,7 +159,6 @@ int main() { mse); /* Normalize data to prevent 'nan' results */ - ds.normalize(); net.randomize_parameters(); optimize_via_gradient_descent(net, mse); diff --git a/src/examples/net_test_ode_1.cpp b/src/examples/net_test_ode_1.cpp index e431de035b4d5569d783e20a02a2c5ff4d66895a..5b06cede8dc8d44609b7a3841dd3b709337f0013 100644 --- a/src/examples/net_test_ode_1.cpp +++ b/src/examples/net_test_ode_1.cpp @@ -67,12 +67,17 @@ void optimize_via_particle_swarm(l4n::DESolver& solver, void optimize_via_gradient_descent(l4n::DESolver& solver, double accuracy) { printf("Solution via a gradient descent method!\n"); + solver.randomize_parameters(); +// TODO does not work (poor design of netsum) +// l4n::LevenbergMarquardt leven(10000, 0, 1e-6, 1e-6, 1e-6); +// solver.solve(leven); + + l4n::GradientDescent gd(accuracy, 1000, 500000); - - solver.randomize_parameters(); solver.solve(gd); + } void export_solution(size_t n_test_points, diff --git a/src/examples/net_test_pde_1.cpp b/src/examples/net_test_pde_1.cpp index 4614467783aa2b560d76184e6c6bdfcd1508fd3c..a5465a6b945845fc7eb88b482f3835dd0ffbeed6 100644 --- a/src/examples/net_test_pde_1.cpp +++ b/src/examples/net_test_pde_1.cpp @@ -310,7 +310,7 @@ void test_pde(double accuracy, } l4n::DataSet ds_t(&data_vec_t); l4n::DataSet ds_x(&data_vec_x); - + std::cout << "Train data setup finished" << std::endl; @@ -324,6 +324,7 @@ void test_pde(double accuracy, solver_01.set_error_function(2, l4n::ErrorFunctionType::ErrorFuncMSE, &ds_x); + std::cout << "Error function defined" << std::endl; /* Solving the equation */ optimize_via_particle_swarm(solver_01, @@ -373,18 +374,18 @@ int main() { << "********************************************************************************************************************************************" << std::endl; - unsigned int n_inner_neurons = 4; - unsigned int train_size = 50; + unsigned int n_inner_neurons = 2; + unsigned int train_size = 5; double accuracy = 1e-3; double ds = 0.0; double de = 1.0; - unsigned int test_size = 100; + unsigned int test_size = 10; double ts = ds; double te = de + 0; - size_t particle_swarm_max_iters = 1000; - size_t n_particles = 50; + size_t particle_swarm_max_iters = 10; + size_t n_particles = 5; test_pde(accuracy, n_inner_neurons, train_size, diff --git a/src/examples/x2_fitting.cpp b/src/examples/x2_fitting.cpp index 7d8d3fb2b2b82dd8dc8164caf3c980c310fec151..86936ae3faccd147211d1701f71b074d19f0617b 100644 --- a/src/examples/x2_fitting.cpp +++ b/src/examples/x2_fitting.cpp @@ -1,4 +1,3 @@ - #include <iostream> #include "4neuro.h" @@ -33,4 +32,4 @@ int main() { mse.eval_on_data_set(ds.get()); return 0; -} \ No newline at end of file +}