// code for fitting the OU spectrum to a given periodogram #ifndef FIT_OUT #define FIT_OU #include "Config.h" #include "InternalDefs.h" #include "Auxiliary.cpp" #include "../ALGLIB/src/dataanalysis.h" #include "../ALGLIB/src/interpolation.h" #include "../ALGLIB/src/stdafx.h" using namespace std; double fitted_RSS_OU( const alglib::real_2d_array &x, const alglib::real_1d_array &y, const alglib::real_1d_array &c, void (*func)(const alglib::real_1d_array &c, const alglib::real_1d_array &x, double &func, void *ptr)){ double RSS=0, ty; void *ptr; long n; alglib::real_1d_array tx; tx.setlength(1); for(n=0; n &spectrum, double suspected_power_o, double suspected_lambda, double &fitted_power_o, double &fitted_lambda){ long count = spectrum.size()-1; long n,m,k,q,p; alglib::real_2d_array x; x.setlength(count, 1); for(n=1; n trials_lambda, trials_power_o; for(n=-PS_OU_FIT_PARAMS_TRY_PLUSMINUS_ORDERDOFMAGNITUDE; n<=PS_OU_FIT_PARAMS_TRY_PLUSMINUS_ORDERDOFMAGNITUDE; ++n){ trials_power_o.push_back(oc[0]*pow(3, 1.0*n)); } for(n=-PS_OU_FIT_PARAMS_TRY_PLUSMINUS_ORDERDOFMAGNITUDE; n<=PS_OU_FIT_PARAMS_TRY_PLUSMINUS_ORDERDOFMAGNITUDE; ++n){ trials_lambda.push_back(oc[1]*pow(3, 1.0*n)); } vector trials_RSS; vector trials_c; for(q=0; q0){ trials_c.push_back(c); if(PS_OU_FIT_LOGARITHMICALLY){ trials_RSS.push_back(fitted_RSS_OU(x, y, c, fit_log_PS_OU_aux)); } else{ trials_RSS.push_back(fitted_RSS_OU(x, y, c, fit_PS_OU_aux)); } } } } if(trials_RSS.empty()) return false; long bestTrial=minimumIndex(trials_RSS); c = trials_c[bestTrial]; fitted_power_o = SQ(c[0]); fitted_lambda = abs(c[1]); return true; } #endif