Unfortunately, SAS does not provide gradian and hessian for a given function. If the function is explicitly defined, one could provide the information(simple math mostly) to some sas procs. Otherwise most sas procs will calculate it for you WITHIN those procs using finite difference method.
Here is an example of the Newton-Raphson methed in Finite difference formulae for a quadratic equation. I hope this sheds light on the approach.
HTH.
501 ****Newton's Method;
502 ***Finite difference formulae;
503 ***example f(x)=x^2 + x -3;
504
505 ***min f(-0.5) = -3.25 ;
506
507 %macro f(x);
508 (&x)**2+(&x)-3
509 %mend;
510
511 %macro f1st(x, h);
512 ( ( %f(&x+&h) ) - ( %f(&x-&h) ) )/(2*&h)
513 %mend;
514
515 %macro f2nd(x, h);
516 ( ( %f(&x+&h) ) - 2*( %f(&x) ) + ( %f(&x-&h) ) )/(&h**2)
517 %mend;
518
519 data _null_;
520
521 x0=90;h=0.006;
522 do i = 1 to 100;
523 z1=%f1st(x0, h); z2=%f2nd(x0, h);
524
525 x=x0 - z1 /z2;
526 if abs ( %f1st(x, h) ) <1e-6 then do;
527 *evaluate function values at optimal point;
528 z0=%f(x); z1=%f1st(x, h); z2=%f2nd(x, h);
529 put i= x= z0= z1= z2=;
530 stop;
531 end;
532 else x0=x;
533 end;
534 run;
i=1 x=-0.499999835 z0=-3.25 z1=3.2998479E-7 z2=2
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


雷达卡



京公网安备 11010802022788号







