Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Simple evaluation of lf evaluators in mata...


From   Matthew Baker <matthew.baker@hunter.cuny.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Simple evaluation of lf evaluators in mata...
Date   Tue, 15 Jan 2013 16:10:21 -0500

Dear Jeff --

Thanks a million! That's exactly what I needed to know.

Best,

Matt

On Tue, Jan 15, 2013 at 2:39 PM, Jeff Pitblado, StataCorp LP
<jpitblado@stata.com> wrote:
> Matthew Baker <matthew.baker@hunter.cuny.edu> want to make direct calls to an
> 'lf' evaluator that was used with -moptimize()-:
>
>> I am encountering the following problem with trying to evaluate
>> objective functions written up under different sorts of evaluators in
>> mata. The problem is, one can easily evaluate functions written for d0
>> evaluators through direct application of the function, but this
>> doesn't appear to be the case. That is, if I've constructed a model
>> statement M to go with a d0 evaluator and a function d0eval(), I can
>> do:
>> d0eval(0,M,params,val=.,g=.,H=.)
>>
>> and val contains the value of the function evaluated at the
>> parameters. If I try this with a type lf evaluator lfeval(), and do:
>> lfeval(0,M,params)
>> the function is stuck at a previously determined value. My question:
>> is there a way to get a quick function evaluation in the lfeval()
>> situation, as in the d0eval() situation? Perhaps the following coded
>> example will illustrate the problem:
>>
>> (example omitted)
>>
>> Any advice? I suspect that the optimization is overwriting some aspect
>> of the structure underlying the problem and just uses that once
>> overwritten.
>
> This kind of thing is just not possible with the 'lf' evaluator, but it is
> possible with 'lf0' evaluators.  Here is a modified version of Matthew's
> example using an 'lf0' evaluator:
>
> ***** BEGIN:
> /* Now, a type lf0 evaluator */
> function lregeval_lf0(M,todo,b,crit,s,H)
> {
>         real colvector p1, p2
>         real colvector y1
>
>         p1=moptimize_util_xb(M,b,1)
>         p2=moptimize_util_xb(M,b,2)
>         y1=moptimize_util_depvar(M,1)
>         crit=-(y1:-p1):^2:/(2*exp(p2)):-1/2*p2
> }
> Q=moptimize_init()
> moptimize_init_evaluator(Q,&lregeval_lf0())
> moptimize_init_evaluatortype(Q,"lf0")
> moptimize_init_depvar(Q,1,"mpg")
> moptimize_init_eq_indepvars(Q,1,"price weight displacement")
> moptimize_init_eq_indepvars(Q,2,"")
> moptimize(Q)
> lregeval_lf0(Q,0,J(1,5,0),lnf1=.,s=.,H=.)
> sum(lnf1)
> lregeval_lf0(Q,0,runiform(1,5),lnf2=.,s=.,H=.)
> sum(lnf2)
> ***** END:
>
> --Jeff
> jpitblado@stata.com
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/



-- 
Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index