function [thhat,thini,tseiter,scl,L,gam,hes]=diagnos(fname,ddir) % [thhat,thini,tseiter,scl,L,gam,hes]=DIAGNOS(fname,ddir) % % Reads in a single file with diagnostics from MLEOS. % % INPUT: % % ddir A directory name, e.g. OLHEDE/Simulations-lemaitre % fname A file name, e.g. diagn_29-June-2010 % % OUTPUT: % % See MLEOS: % % thhat The maximum-likelihood estimate of the vector with elements: % [D f2 s2 nu rho], in Nm, and "nothing", see SIMULOS % thini The starting guess used in the optimization % tseiter Time taken, error code, number of iterations % scl The scaling applied as part of the optimization procedure % L The likelihood of this solution % gam The score, or first derivative of the likelihood % hes The hessian, second derivative of the likelihood % % Last modified by fjsimons-at-alum.mit.edu, 12/09/2010 defval('ddir','/u/fjsimons/MyPapers/OLHEDE/Simulations-lemaitre') defval('fname','diagn_29-June-2010') % The number of parameters to solve for np=5; % The number of unique entries in an np*np symmetric matrix npp=np*(np+1)/2; % Get a rough estimate of the number of estimates from the size ndim=ceil(fsize(fullfile(ddir,fname))/560); tseiter=nan(ndim,3); L=nan(ndim,1); [thhat,thini,gam]=deal(nan(ndim,np)); hes=nan(ndim,npp); % Read the contents fid=fopen(fullfile(ddir,fname),'r'); for index=1:ndim try % The estimate thhat(index,:)=fscanf(fid,'%e',np); catch index=index-1; break end % The initial guess thini(index,:)=fscanf(fid,'%e',np); % The diagnostics tseiter(index,:)=fscanf(fid,'%i',3); % The likelihood L(index)=fscanf(fid,'%e',1); % The scalings scl(index,:)=fscanf(fid,'%e',np); % The scores gam(index,:)=fscanf(fid,'%e',np); % The Hessian elements hes(index,:)=fscanf(fid,'%f',npp); end fclose(fid); % Trim the possibly wrongly preallocated arrays thhat=thhat(1:index,:); thini=thini(1:index,:); tseiter=tseiter(1:index,:); scl=scl(1:index,:); L=L(1:index,:); gam=gam(1:index,:); hes=hes(1:index,:); % Put out varns={thhat,thini,tseiter,scl,L,gam,hes}; varargout=varns(1:nargout);