[Index for tmp_for_tar/quad_min.doc]
[Return to Master Index]
test_quad_min
(tmp_for_tar/quad_min.doc/test_quad_min.m)
Function Synopsis
[v,dv,d2v] = d2ff(x)
Help text
Test whether quad_min() functions correctly, with two args
Gives a simple quadratic programming problem (function ff below).
Sets a ok variable to 1 in case of success, 0 in case of failure
If a variables "verbose" is set, then some comments are output.
Last modified: October 2000
Cross-Reference Information
This function calls
- sayif tmp_for_tar/quad_min.doc/sayif.m
Listing of function file tmp_for_tar/quad_min.doc/test_quad_min.m
## Test whether quad_min() functions correctly, with two args
##
## Gives a simple quadratic programming problem (function ff below).
##
## Sets a ok variable to 1 in case of success, 0 in case of failure
##
## If a variables "verbose" is set, then some comments are output.
## Author: Etienne Grossmann <etienne@isr.ist.utl.pt>
## Last modified: October 2000
1 ;
ok = 0;
if ! exist ("verbose"), verbose = 0; end
P = 10+floor(30*rand(1)) ; # Nparams
R = P+floor(30*rand(1)) ; # Nobses
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 ) ;
endfunction
function [v,dv,d2v] = d2ff(x)
global obsmat;
global obses;
er = -obses + obsmat*x ;
dv = er'*obsmat ;
v = msq( er ) ;
d2v = pinv( obsmat'*obsmat ) ;
endfunction
sayif(verbose, "gonna do : quad_min\n");
mytic() ;
[xlev,vlev,nlev] = quad_min("ff","d2ff",xinit) ;
tlev = mytic() ;
if verbose,
printf("Quad should find in one iteration + one more to check\n");
printf(["QUAD : niter=%4d nobs=%4d,nparams=%4d\n",...
" time=%8.3g errx=%8.3g minv=%8.3g\n"],...
nlev,R,P,tlev,max(abs( xlev-truep )),vlev);
end
ok = 1;
if nlev != 2,
sayif (verbose, "Too many iterations for this function\n");
ok = 0;
end
if max (abs(xlev-truep )) > sqrt (eps),
sayif (verbose, "Error is too big : %8.3g\n", max (abs (xlev-truep)));
ok = 0;
end
sayif (verbose && ok, "All tests ok\n");
Produced by oct2html on Tue Oct 10 18:28:41 2000
Cross-Directory links are: ON