unsubscribe

On Fri, May 30, 2014 at 5:00 PM, <[email protected]>
wrote:

> Send NLopt-discuss mailing list submissions to
>         [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
> or, via email, send a message with subject or body 'help' to
>         [email protected]
>
> You can reach the person managing the list at
>         [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of NLopt-discuss digest..."
>
>
> Today's Topics:
>
>    1. Re: help with MLE estimation with NLopt in C++    (Steven G.
>       Johnson) (Chong Li)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 29 May 2014 19:16:57 -0400
> From: Chong Li <[email protected]>
> To: [email protected]
> Subject: Re: [NLopt-discuss] help with MLE estimation with NLopt in
>         C++     (Steven G. Johnson)
> Message-ID:
>         <CAPPgUKJ8MzHNxg0RZABfBiqX9WDwVbiajZ7J=
> [email protected]>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
>
>     When I am using the following code to to do an optimization (the
> objective function takes a vector of vectors as data argument), I can
> compile the program (Not MLE estimation, actually). However, I get a
> Segmentation fault (core dumped)
>  error every time I run it. Could you please give me some suggestions on
> how to correct the code so that it will work?
> Thanks a lot for your time and best regards,
>
> Chong
>
>
> double myvfunc(const std::vector<double> &x, std::vector<double> &grad,
> void * my_func_data)
> {
>     std::vector<std::vector<double> > *d =
> reinterpret_cast<std::vector<std::vector<double> > *>(my_func_data);
>     std::vector<double> meanret = rowWiseMean(*d);
>     if (!grad.empty()) {
>         for (unsigned int i=0; i != meanret.size(); i++)
>         grad[i] = meanret[i];
>     }
>     return dotProduct(x, meanret);
> }
>
>
> double myvconstraint(const std::vector<double> &x, std::vector<double>
> &grad, void * my_ineconstr_data)
> {
>     std::vector<std::vector<double> > *d =
> reinterpret_cast<std::vector<std::vector<double> > *>(my_ineconstr_data);
>     unsigned int dim = (*d)[0].size();
>     unsigned int T = (*d).size();
>     std::vector<std::vector<double> > vc(dim, std::vector<double>(dim));
>     for (unsigned int i = 0; i != T; i++)
>         vc = matSum(vc, vectorProduct((*d)[i], (*d)[i]));
>     vc = scalarDivideMat(double(T), vc);
>
>     if (!grad.empty()) {
>         for (unsigned int i =0; i != dim; i++)
>         grad[i] = 2 * (matVecProd(vc, x)[i]);
>     }
>     return dotProduct(x, matVecProd(vc, x) ) - 0.03;
> }
>
>
>
> int main()
>
> {
>
> nlopt::opt opt(nlopt::LD_MMA, 5);
>
> std::vector<double> lb(5);
> lb[0] = 0; lb[1] = 0;  lb[2] = 0; lb[3] = 0; lb[4] = 0;
> opt.set_lower_bounds(lb);
>
> std::vector<double> ub(5);
> ub[0] =1; ub[1] =1; ub[2] =1; ub[3] =1; ub[4] =1;
> opt.set_upper_bounds(ub);
>
>
> //genSimData is a function generate a 10 by 5 matrix of random numbers.
> std::vector<std::vector<double> > dd = genSimData(10, 5, 3);
>
> void *pd = &dd;
>
>
> opt.set_min_objective(myvfunc, pd);
> opt.add_inequality_constraint(myvconstraint, pd, 1e-8);
>
>
> opt.set_xtol_rel(1e-4);
>
> std::vector<double> x(5);
> x[0] = 0.2; x[1] = 0.2; x[2] = 0.2; x[3]= 0.2; x[4]= 0.2;
>
> double minf;
> nlopt::result result = opt.optimize(x, minf);
> std::cout << result << std::endl;
> std::cout << minf << std::endl;
> std::cout << x[0] << std::endl;
> std::cout << x[1] << std::endl;
> return 0;
>
> }
>
>
>
>
> --
> Chong Li (? ?)
>
> Department of Economics,
> Maxwell School of Citizenship and Public Affairs,
> Syracuse University
> Syracuse, NY 13244-1020
>
> Email:[email protected]
>
> Mobile: 315-744-2709
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://ab-initio.mit.edu/pipermail/nlopt-discuss/attachments/20140529/628178cd/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> NLopt-discuss mailing list
> [email protected]
> http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
>
>
> ------------------------------
>
> End of NLopt-discuss Digest, Vol 56, Issue 6
> ********************************************
>
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to