forum.alglib.net
http://forum.alglib.net/

Passing parameters to optimizer
http://forum.alglib.net/viewtopic.php?f=2&t=3821
Page 1 of 1

Author:  SteSus85 [ Wed Nov 08, 2017 5:08 pm ]
Post subject:  Passing parameters to optimizer

Hey,
I use BFGS optimizer and I'd like to run a parallel loop few optimization procedures. In order to do this I should provide unique (parameters to) objective function for each parallel stream. How can I do this with alglib? Can I run optimizer by passing unique pointers to it?

My current objective function defined as
Code:
void function3_func(const real_1d_array &x, double &func, void *ptr)
{
   func = -d_Likelihood(delta_tk, c, x[0],x[1], x[2], NN, y_ob, (int)TT);
}


How can I pass unique y_ob in parallel?

Thx in advance,
Stepan

Author:  SteSus85 [ Thu Nov 09, 2017 11:21 am ]
Post subject:  Solution

If someone need it. I used the following constructions:
Code:
void function2_func(const real_1d_array &x, double &func, void *ptr)
{
   InputData data_tmp = *((InputData *)ptr);
   func = -c_Likelihood(x[0], x[1], x[2], data_tmp.N, data_tmp.R, data_tmp.Q, data_tmp.NN);
}

Code:
struct InputData
{
   int R,Q,NN;
   double  N;
};

InputData data;
simulated_data.Q = Q_tmp; simulated_data.N = N_tmp;
simulated_data.R = c_tmp; simulated_data.NN = N_tmp;
...
alglib::minbleicoptimize( state, function2_func, NULL, (void*)&data);

Author:  Sergey.Bochkanov [ Thu Nov 09, 2017 1:42 pm ]
Post subject:  Re: Passing parameters to optimizer

Yes, that's exactly how it is intended to work! :))

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/