Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Patrick Roland <patrick.rolande@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Mata computes the second derivative of x^2 as 1.9. |

Date |
Sun, 5 Aug 2012 12:09:41 -0700 |

Sure, but i) it is disturbing that the default parameters work so poorly on such a simple problem and ii) in more problems where the derivatives are not known, one does not have the option of choosing the tuning parameters so that the procedure matches the known results as closely as possible. On Sat, Aug 4, 2012 at 11:15 PM, Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> wrote: > As with any numerical approximation procedure, there are tuning > parameters. Resetting the bounds for the optimal parameter (scale) > search works for your simple example > > *--------------------------------------- > mata: > mata clear > void f(p,v){ > v = p^2 > } > D = deriv_init() > deriv_init_bounds(D, (1e-5, 1e-4)) > deriv_init_evaluator(D, &f()) > deriv_init_params(D, 0.5) > deriv(D,2) > deriv_result_delta(D) > end > *--------------------------------------- > > [M] and the references there contain more information. For more > complex multiparameter nonlinear problems, you should look at a > numerical analysis text. > > T > > On Sat, Aug 4, 2012 at 8:22 PM, Patrick Roland > <patrick.rolande@gmail.com> wrote: >> Perhaps someone might be able to explain this anomaly. The following >> code finds the second derivative of x^2 evaluated at 0.5, which should >> of course be 2. >> >> >> mata: >> >> void f(p,v){ >> v = p^2 >> } >> D = deriv_init() >> deriv_init_evaluator(D, &f()) >> deriv_init_params(D, 0.5) >> deriv(D,2) >> >> end >> >> Instead, in both Stata 11.2 and 12.1, the answer is 1.906569171. >> >> I'm trying to compute the Hessian of a complicated nonlinear function >> of several hundred arguments. It appears that Mata cannot correctly >> find the second derivative of x^2. This does not inspire confidence. >> >> Hopefully I'm overlooking something simple here, in which case I would >> greatly appreciate a correction. >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ > > > > -- > Tirthankar Chakravarty > tchakravarty@ucsd.edu > tirthankar.chakravarty@gmail.com > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Mata computes the second derivative of x^2 as 1.9.***From:*Patrick Roland <patrick.rolande@gmail.com>

**Re: st: Mata computes the second derivative of x^2 as 1.9.***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

- Prev by Date:
**Re: st: Warning convergence not achieved** - Next by Date:
**st: Summary stats table in a particular format** - Previous by thread:
**Re: st: Mata computes the second derivative of x^2 as 1.9.** - Next by thread:
**st: invalid syntex error in executing tobithetm command** - Index(es):