1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## Test whether d2_min() functions correctly, with two args
18 ## Gives a simple quadratic programming problem (function ff below).
20 ## Sets a ok variable to 1 in case of success, 0 in case of failure
22 ## If a variables "verbose" is set, then some comments are output.
28 if ! exist ("verbose"), verbose = 0; end
31 printf ("\n Testing d2_min () on a quadratic programming problem\n\n");
34 P = 10+floor(30*rand(1)) ; # Nparams
35 R = P+floor(30*rand(1)) ; # Nobses
41 obses = obsmat*truep ;
42 if noise, obses = adnois(obses,noise); end
47 function v = ff (x, y)
48 v = msq( y.obses - y.obsmat*x ) ;
52 function [v,dv,d2v] = d2ff (x, y)
53 er = -y.obses + y.obsmat*x ;
56 d2v = pinv( y.obsmat'*y.obsmat ) ;
61 ## Returns the cputime since last call to 'mytic'.
64 persistent last_mytic = 0 ;
70 ## s = msq(x) - Mean squared value, ignoring nans
72 ## s == mean(x(:).^2) , but ignores NaN's
77 s = mean(x(find(!isnan(x))).^2);
84 ctl = nan*zeros(1,5); ctl(5) = 1;
86 if verbose, printf ( "Going to call d2_min()\n"); end
88 [xlev,vlev,nev] = d2_min ("ff", "d2ff", {xinit,y}, ctl) ;
92 printf("d2_min should find in one iteration + one more to check\n");
93 printf(["d2_min : niter=%-4d nev=%-4d nobs=%-4d nparams=%-4d\n",\
94 " time=%-8.3g errx=%-8.3g minv=%-8.3g\n"],...
95 nev([2,1]), R, P, tlev, max (abs (xlev-truep)), vlev);
101 printf ( "Too many iterations for this function\n");
106 if max (abs(xlev-truep )) > sqrt (eps),
108 printf ( "Error is too big : %-8.3g\n", max (abs (xlev-truep)));
114 printf ( "All tests ok\n");