Re: How to calculate Hessian Matrix
- From: fj <francois.jacq@xxxxxxx>
- Date: Tue, 5 Aug 2008 00:39:59 -0700 (PDT)
On 5 août, 09:32, fj <francois.j...@xxxxxxx> wrote:
On 5 août, 04:45, John <john131...@xxxxxxxxx> wrote:
Hi,
Does anyone know where there is any function/subroutine can compute
the Hessian Matrix of a multivariable function? Thanks a lot!
John
First of all, your are not posting in the right group.
It is very easy to compute an Hessian matrix using numerical
derivatives. The only problem is the cost especially if the multi
variable function is itself a "vector" function.
The simplest way consists in writing a routine computing the gradient.
After that, you write the function computing the Hessian in the same
way. Let us assume the the function is only scalar :
double precision function f(n,x)
subroutine gradient(n,x,f,df)
subroutine hessian(n,x,f,h)
implicit none
integer,intent(in) :: n
double precision,intent(in) :: x(n)
double precision,intent(out) :: h(n,n)
external :: f,gradient
double precision :: xx(n),df0(n),df(n),xx0
double precision,parameter :: epsilon=1.d-5
integer :: j
call gradient(n,x,f,df0)
xx=x
do j=1,n
xx0=xx(j)+epsilon
call gradient(n,xx,f,df)
h(:,j)=(df-df0)/epsilon
enddo
end subroutine
Of course, you might improve this simple solution : the parameter
"epsilon" may be passed as argument and may be a vector. You might
also prefer central derivatives rather than "right" derivatives and
define routines f and gradient using interfaces rather than EXTERNAL
declaration ...
Oups ! The instructions in the loop are wrong and should be replaced
by :
do j=1,n
xx0=xx(j)
xx(j)=xx0+epsilon
call gradient(n,xx,f,df)
h(:,j)=(df-df0)/epsilon
xx(j)=xx0
enddo
Sorry, I was not awake !
.
- Follow-Ups:
- Re: How to calculate Hessian Matrix
- From: John
- Re: How to calculate Hessian Matrix
- From: fj
- Re: How to calculate Hessian Matrix
- References:
- How to calculate Hessian Matrix
- From: John
- Re: How to calculate Hessian Matrix
- From: fj
- How to calculate Hessian Matrix
- Prev by Date: Re: How to calculate Hessian Matrix
- Next by Date: Re: How to calculate Hessian Matrix
- Previous by thread: Re: How to calculate Hessian Matrix
- Next by thread: Re: How to calculate Hessian Matrix
- Index(es):
Relevant Pages
|