[Index for tmp_for_tar/deriv_min.doc] [Return to Master Index]

test_conjgrad_min_1

(tmp_for_tar/deriv_min.doc/test_conjgrad_min_1.m)


Function Synopsis

dv = dff(x)

Help text

 ok = test_conjgrad_min       - Test that conjgrad_min works

 Defines some simple functions and verifies that calling

 conjgrad_min on them returns the correct minimum.

 Sets 'ok' to 1 if success, 0 otherwise

 Last modified: October 2000



Cross-Reference Information

This function calls

Listing of function file tmp_for_tar/deriv_min.doc/test_conjgrad_min_1.m

## ok = test_conjgrad_min       - Test that conjgrad_min works
##
## Defines some simple functions and verifies that calling
## 
## conjgrad_min on them returns the correct minimum.
##
## Sets 'ok' to 1 if success, 0 otherwise



## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: October 2000

ok = 1;

if ! exist ("verbose"), verbose = 0; end

if 0,
  P = 10+floor(30*rand(1)) ;	# Nparams
  R = P+floor(30*rand(1)) ;	# Nobses
else
  P = 2;
  R = 3;
end

noise = 0 ;
global obsmat ;
obsmat = randn(R,P) ;
global truep ;
truep = randn(P,1) ;
xinit = randn(P,1) ;

global obses ;
obses = obsmat*truep ;
if noise, obses = adnois(obses,noise); end


function v = ff(x)
  global obsmat;
  global obses;
  v = msq( obses - obsmat*x ) + 1 ;
endfunction


function dv = dff(x)
  global obsmat;
  global obses;
  er = -obses + obsmat*x ;
  dv = 2*er'*obsmat / rows(obses) ;
  ## dv = 2*er'*obsmat ;
endfunction



sayif(verbose, "gonna do : conjgrad_min\n");
if verbose,
  printf ("Nparams = P = %i,  Nobses = R = %i\n",P,R);
end


mytic() ;
[xlev,vlev,nlev] = conjgrad_min("ff","dff",xinit) ;
tlev = mytic() ;


if max (abs(xlev-truep)) > 100*sqrt (eps),
  if verbose, 
    printf ("Error is too big : %8.3g\n", max (abs (xlev-truep)));
  end
  ok = 0;
end
if verbose,
  printf ("  Costs :     init=%8.3g, final=%8.3g, best=%8.3g\n",\
	  ff(xinit), vlev, ff(truep));    
end
sayif (verbose, "   time : %8.3g\n",tlev);
sayif (verbose && ok, "All tests ok\n");

Produced by oct2html on Tue Oct 17 10:08:37 2000
Cross-Directory links are: ON