#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
using namespace ukf::parameter;
#define VERBOSE true
double my_func(gsl_vector * param, gsl_vector * input)
{
double x1 = gsl_vector_get(param, 0);
double x2 = gsl_vector_get(param, 1);
return gsl_pow_2(1.0 - x1) + 100 * gsl_pow_2(x2 - gsl_pow_2(x1));
}
int main(int argc, char* argv[]) {
srand(time(NULL));
for(
int i = 0 ; i < p.
n ; i++)
gsl_vector_set(s.
w,i,10.0*(2.0*rand()/
double(RAND_MAX-1)-1.0));
gsl_vector * xi = gsl_vector_alloc(1);
gsl_vector_set(xi, 0, 0.0);
double yi=0.0;
double errorBound = 1e-5;
int nbStepsLimit = 100000;
double error = 2*errorBound;;
error = 0.0;
std::cout << "###########\n Before learning : " << std::endl;
std::cout << "Rosenbrock function value : " << yi << std::endl;
std::cout << "###########\n " << std::endl;
int epoch = 0;
error = 2 * errorBound;
std::ofstream outfile("example-006.data");
while( epoch <= nbStepsLimit && error > errorBound)
{
error = fabs(my_func(s.
w, xi));
if(epoch % (nbStepsLimit/100) == 0)
std::cout << "Epoch " << epoch << " error = " << error << std::endl;
outfile << s.
w->data[0] <<
" " << s.
w->data[1] <<
" " << my_func(s.
w, xi) << std::endl;
epoch++;
}
outfile.close();
std::cout << " Run on " << epoch << " epochs ; RMS = " << error << "\n" << std::endl ;
std::cout <<
" x = " << gsl_vector_get(s.
w, 0) <<
" ; y = " << gsl_vector_get(s.
w, 1) <<
" ; z = " << my_func(s.
w, xi) << std::endl;
std::cout << " You can plot the results by calling : python plot-example-006.py"<< std::endl;
}