Home > tt2 > misc > tt_hess.m

tt_hess

PURPOSE ^

Numerical Hessian in a given point

SYNOPSIS ^

function [Hess]=tt_hess(tt, indext, h)

DESCRIPTION ^

Numerical Hessian in a given point
   [HESS]=TT_HESS(TT, INDEXT, H) Computes the numerical Hessian of the
   TT-tensor TT computed at INDEXT. The grid size is supposed to be equal
   to H


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Hess]=tt_hess(tt, indext, h)
0002 %Numerical Hessian in a given point
0003 %   [HESS]=TT_HESS(TT, INDEXT, H) Computes the numerical Hessian of the
0004 %   TT-tensor TT computed at INDEXT. The grid size is supposed to be equal
0005 %   to H
0006 %
0007 %
0008 % TT-Toolbox 2.2, 2009-2012
0009 %
0010 %This is TT Toolbox, written by Ivan Oseledets et al.
0011 %Institute of Numerical Mathematics, Moscow, Russia
0012 %webpage: http://spring.inm.ras.ru/osel
0013 %
0014 %For all questions, bugs and suggestions please mail
0015 %ivan.oseledets@gmail.com
0016 %---------------------------
0017 tt=core(tt); 
0018 d = max(size(tt));
0019 if (max(size(h))==1)
0020     h = h*ones(d,1);
0021 end;
0022 if (max(size(indext))==1)
0023     indext = indext*ones(d,1);
0024 end;
0025 
0026 % curind = cell(d,1);
0027 
0028 Hess = zeros(d,d);
0029 for i=1:d
0030     for j=1:d
0031 %         for k=1:d
0032 %             curind{k}=indext(k);
0033 %         end;
0034         curhess = tt;
0035         if (i==j) % Laplace_i
0036 %             curind{i}=indext(i)-1:indext(i)+1;
0037 %             curhess = tt_elem3(tt, curind);
0038 %             core=tt{i};
0039 %             n = size(core,1); r1=size(core,2); r2=size(core,3);
0040 %             core = reshape(core, n, r1*r2);
0041 %             lp = spdiags(ones(n,1)*[1,-2,1], [-1,0,1], n, n)/(h(i)^2);
0042 %             core = lp*core;
0043 %             core = sum(core,1)*h(i);
0044 %             curhess{i}=reshape(core, 1, r1, r2);
0045             curhess{i}=(1/(h(i)^2))*(curhess{i}(indext(i)-1,:,:)-2*curhess{i}(indext(i),:,:)+curhess{i}(indext(i)+1,:,:));
0046             for k=1:d
0047                 if (k~=i)
0048 %                     curhess{k}=sum(curhess{k},1)*h(k);
0049                     curhess{k}=curhess{k}(indext(k),:,:);
0050                 end;
0051             end;
0052             Hess(i,i)=full(tt_tensor(curhess));
0053         else % Grad_i * Grad_j
0054 %             corei=tt{i};
0055 %             ni = size(corei,1); r1i=size(corei,2); r2i=size(corei,3);
0056 %             corei = reshape(corei, ni, r1i*r2i);
0057 %             gradi = spdiags(ones(ni,1)*[-0.5,0,0.5], [-1,0,1], ni, ni)/h(i);
0058 %             corei = gradi*corei;
0059 %             corei = sum(corei,1)*h(i);
0060 %             curhess{i}=reshape(corei, 1, r1i, r2i);
0061 %             corej=tt{j};
0062 %             nj = size(corej,1); r1j=size(corej,2); r2j=size(corej,3);
0063 %             corej = reshape(corej, nj, r1j*r2j);
0064 %             gradj = spdiags(ones(nj,1)*[-0.5,0,0.5], [-1,0,1], nj, nj)/h(j);
0065 %             corej = gradj*corej;
0066 %             corej = sum(corej,1)*h(j);
0067 %             curhess{j}=reshape(corej, 1, r1j, r2j);
0068 %             curind{i}=indext(i)-1:indext(i)+1;
0069 %             curind{j}=indext(j)-1:indext(j)+1;
0070 %             curhess = tt_elem3(tt, curind);
0071             curhess{i}=(0.5/h(i))*(curhess{i}(indext(i)+1,:,:)-curhess{i}(indext(i)-1,:,:));
0072             curhess{j}=(0.5/h(j))*(curhess{j}(indext(j)+1,:,:)-curhess{j}(indext(j)-1,:,:));            
0073             for k=1:d
0074                 if (k~=i)&&(k~=j)
0075 %                     curhess{k}=sum(curhess{k},1)*h(k);
0076                     curhess{k}=curhess{k}(indext(k),:,:);
0077                 end;
0078             end;            
0079             Hess(i,j)=tt_to_full(curhess);
0080         end;
0081     end;
0082 end;
0083 
0084 end

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005