Calculate the numerical hessian

Hello!
I have the following function with the two variables alha and beta:
function MSE=mseFunction(alpha,beta,Donnee_6_jours)
moyenneMobile=zeros(240,1);
%Calcul de la moyenne mobile
for i=1:240
moyenneMobile(i)=1/48.*((Donnee_6_jours(i)/2)+sum(Donnee_6_jours(i+1:i+47))+(Donnee_6_jours(i+48)/2));
end
moyenneMobileCentree = padarray(moyenneMobile,24,'both');
composanteSaisonniaire=Donnee_6_jours(25:264)./moyenneMobileCentree(25:264);
composanteSaisonniaireV2 = padarray(composanteSaisonniaire,24,'both');
MatriceComposanteSaisonniaire = reshape(composanteSaisonniaireV2,[48,6]);
MatriceComposanteSaisonniaire(1:24,1)=NaN;
MatriceComposanteSaisonniaire(25:48,6)=NaN;
MedianneComposantsSaisonniers = nanmedian(MatriceComposanteSaisonniaire,2);
LES=zeros(288,1);
LES(25)=moyenneMobileCentree(25);
for i=26:264;
LES(i)=alpha.*moyenneMobileCentree(i)+(1-alpha).*LES(i-1);
end
S=zeros(264,1);
S(1:48,:)=MedianneComposantsSaisonniers;
for j=49:264;
S(j)=beta.*(Donnee_6_jours(j)./LES(j))+(1-beta).*S(j-48);
end
PREV=zeros(264,1);
PREV(26:264)=S(26:264).*LES(25:263);
PREV2=padarray(PREV(:),24,'post');
MSE = mean((Donnee_6_jours(26:264)-PREV2(26:264)).^2);
is there a way to calculate the numerical hessian.
Thanks!

Réponses (2)

Walter Roberson
Walter Roberson le 6 Nov 2016

0 votes

4 commentaires

amine&&
amine&& le 6 Nov 2016
Hello Roberson, in the link you gave me this is calculated Hessian of an image, my goal is to get the Hessian of a function.
Thanks!
It does not make sense to calculate the numeric Hessian of a function: it only makes sense to calculate the symbolic Hessian, or to calculate the numeric Hessian of a function that has been calculated at particular locations.
For example,
alpha_vals = linspace(.2, .87, 13);
beta_vals = logspace(-3, 2, 19);
[ALPHA, BETA] = ndgrid(alpha_vals, beta_vals);
mse = arrayfun(@alpha,beta) mseFunction(alpha, beta, Donnee_6_jours), ALPHA, BETA);
[gx, gy] = gradient(mse, alpha_vals, beta_vals);
[gxx, gxy] = gradient(gx, alpha_vals, beta_vals);
[gyx, gyy] = gradient(gy, alpha_vals, beta_vals);
subplot(1,5,1)
pcolor(ALPHA, BETA, mse);
title('MSE')
subplot(1,5,2)
pcolor(ALPHA, BETA, gxx)
title('D alpha alpha');
subplot(1,5,3)
pcolor(ALPHA, BETA, gxy)
title('D alpha beta')
and so on.
Hello Roberson,
the fourth line generates an error
mse = arrayfun(@alpha,beta) mseFunction(alpha, beta, Donnee_6_jours), ALPHA, BETA);
|
Error: Unexpected MATLAB expression.
what you think of the following function use to compute the gradient :
function grad_x=gradIent(x1,x2,Donnee_6_jours)
x=zeros(2,1);
x(1)=x1;
x(2)=x2;
h=1*10^-2;
v=eye(2,2);
grad_x=zeros(2,1);
for i=1:2
T1=x+h.*v(:,i);
T2=x-h.*v(:,i);
grad_x(i)=(mseFunction(T1(1),T1(2),Donnee_6_jours)-mseFunction(T2(1),T2(2),Donnee_6_jours))/(2*h);
end
Thanks Roberson.
mse = arrayfun(@(alpha,beta) mseFunction(alpha, beta, Donnee_6_jours), ALPHA, BETA);

Connectez-vous pour commenter.

Matt J
Matt J le 7 Nov 2016

0 votes

Have a look at this FEX submission, in particular at hessian(fun,x0).

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by