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

[MERGE] Merge with kra568/tmp

parents 2886c16a 4ec263f9
No related branches found
No related tags found
No related merge requests found
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 10.9.18 -
*/
#include "LearningMethod.h" #include "LearningMethod.h"
namespace lib4neuro { namespace lib4neuro {
//TODO NOT SAFE!!!!
std::vector<double>* LearningMethod::get_parameters() { std::vector<double>* LearningMethod::get_parameters() {
return &this->optimal_parameters; return &this->optimal_parameters;
} }
...@@ -17,4 +12,4 @@ namespace lib4neuro { ...@@ -17,4 +12,4 @@ namespace lib4neuro {
this->optimize(ef, this->optimize(ef,
ofs); ofs);
} }
} }
\ No newline at end of file
...@@ -299,7 +299,7 @@ namespace lib4neuro { ...@@ -299,7 +299,7 @@ namespace lib4neuro {
/* initialize the particles */ /* 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)) { if (this->particle_swarm.at(pi)) {
delete this->particle_swarm.at(pi); delete this->particle_swarm.at(pi);
} }
...@@ -548,9 +548,10 @@ namespace lib4neuro { ...@@ -548,9 +548,10 @@ namespace lib4neuro {
this->w = w; this->w = w;
this->n_particles = n_particles; this->n_particles = n_particles;
this->iter_max = iter_max; this->iter_max = iter_max;
this->particle_swarm.resize(this->n_particles);
std::fill(this->particle_swarm.begin(), std::fill(this->particle_swarm.begin(),
this->particle_swarm.end(), this->particle_swarm.end(),
nullptr); nullptr);
} }
} }
\ No newline at end of file
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 15.3.19 -
*/
#include <boost/serialization/export.hpp> #include <boost/serialization/export.hpp>
...@@ -40,4 +34,4 @@ namespace lib4neuro { ...@@ -40,4 +34,4 @@ namespace lib4neuro {
return output; return output;
} }
}//end of namespace lib4neuro }//end of namespace lib4neuro
\ No newline at end of file
...@@ -91,6 +91,8 @@ namespace lib4neuro { ...@@ -91,6 +91,8 @@ namespace lib4neuro {
this->dim_i = n_inputs; this->dim_i = n_inputs;
this->dim_inn = m; this->dim_inn = m;
this->n_equations = n_equations; this->n_equations = n_equations;
this->errors_functions_types.resize(n_equations);
this->errors_functions_data_sets.resize(n_equations);
......
...@@ -159,7 +159,6 @@ int main() { ...@@ -159,7 +159,6 @@ int main() {
mse); mse);
/* Normalize data to prevent 'nan' results */ /* Normalize data to prevent 'nan' results */
ds.normalize();
net.randomize_parameters(); net.randomize_parameters();
optimize_via_gradient_descent(net, optimize_via_gradient_descent(net,
mse); mse);
......
...@@ -67,12 +67,17 @@ void optimize_via_particle_swarm(l4n::DESolver& solver, ...@@ -67,12 +67,17 @@ void optimize_via_particle_swarm(l4n::DESolver& solver,
void optimize_via_gradient_descent(l4n::DESolver& solver, void optimize_via_gradient_descent(l4n::DESolver& solver,
double accuracy) { double accuracy) {
printf("Solution via a gradient descent method!\n"); 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, l4n::GradientDescent gd(accuracy,
1000, 1000,
500000); 500000);
solver.randomize_parameters();
solver.solve(gd); solver.solve(gd);
} }
void export_solution(size_t n_test_points, void export_solution(size_t n_test_points,
......
...@@ -310,7 +310,7 @@ void test_pde(double accuracy, ...@@ -310,7 +310,7 @@ void test_pde(double accuracy,
} }
l4n::DataSet ds_t(&data_vec_t); l4n::DataSet ds_t(&data_vec_t);
l4n::DataSet ds_x(&data_vec_x); l4n::DataSet ds_x(&data_vec_x);
std::cout << "Train data setup finished" << std::endl;
...@@ -324,6 +324,7 @@ void test_pde(double accuracy, ...@@ -324,6 +324,7 @@ void test_pde(double accuracy,
solver_01.set_error_function(2, solver_01.set_error_function(2,
l4n::ErrorFunctionType::ErrorFuncMSE, l4n::ErrorFunctionType::ErrorFuncMSE,
&ds_x); &ds_x);
std::cout << "Error function defined" << std::endl;
/* Solving the equation */ /* Solving the equation */
optimize_via_particle_swarm(solver_01, optimize_via_particle_swarm(solver_01,
...@@ -373,18 +374,18 @@ int main() { ...@@ -373,18 +374,18 @@ int main() {
<< "********************************************************************************************************************************************" << "********************************************************************************************************************************************"
<< std::endl; << std::endl;
unsigned int n_inner_neurons = 4; unsigned int n_inner_neurons = 2;
unsigned int train_size = 50; unsigned int train_size = 5;
double accuracy = 1e-3; double accuracy = 1e-3;
double ds = 0.0; double ds = 0.0;
double de = 1.0; double de = 1.0;
unsigned int test_size = 100; unsigned int test_size = 10;
double ts = ds; double ts = ds;
double te = de + 0; double te = de + 0;
size_t particle_swarm_max_iters = 1000; size_t particle_swarm_max_iters = 10;
size_t n_particles = 50; size_t n_particles = 5;
test_pde(accuracy, test_pde(accuracy,
n_inner_neurons, n_inner_neurons,
train_size, train_size,
......
#include <iostream> #include <iostream>
#include "4neuro.h" #include "4neuro.h"
...@@ -33,4 +32,4 @@ int main() { ...@@ -33,4 +32,4 @@ int main() {
mse.eval_on_data_set(ds.get()); mse.eval_on_data_set(ds.get());
return 0; return 0;
} }
\ 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