Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [a7cc88] default Maximize Restore History

Cleaned up INDEX and removed unused internal functions.

Olaf Till Olaf Till 2014-01-08

removed inst/__semi_bracket.m
removed inst/test_fminunc_1.m
changed INDEX
copied inst/__bracket_min.m -> inst/private/__bracket_min.m
copied inst/__poly_2_extrema.m -> inst/private/__semi_bracket.m
inst/__semi_bracket.m
File was removed.
inst/test_fminunc_1.m
File was removed.
INDEX Diff Switch to side-by-side view
Loading...
inst/__bracket_min.m to inst/private/__bracket_min.m
File was copied or renamed.
inst/__poly_2_extrema.m to inst/private/__semi_bracket.m
--- a/inst/__poly_2_extrema.m
+++ b/inst/private/__semi_bracket.m
@@ -14,41 +14,37 @@
 ## You should have received a copy of the GNU General Public License along with
 ## this program; if not, see <http://www.gnu.org/licenses/>.
 
-##  ex = poly_2_ex (l, f)       - Extremum of a 1-var deg-2 polynomial
+## [a, b, ga, gb, nev] = semi_bracket (f, dx, a, narg, args)
 ##
-## l  : 3 : variable values
-## f  : 3 : f(i) = value of polynomial at l(i)
-## 
-## ex : 1 : Value at which f reaches an extremum
-## 
-## Assuming that f(i) = a*l(i)^2 + b* l(i) + c = P(l(i)) for some a, b, c,
-## ex is the extremum of the polynome P.
+## Find an interval containing a local minimum of the function 
+## g : h in [a, inf[ ---> f (x+h*dx) where x = args{narg}
+##
+## The local minimum may be in a.
+## a < b.
+## nev is the number of function evaluations.
 
-function ex = __poly_2_extrema (l, f)
+function [a,b,ga,gb,n] = __semi_bracket (f, dx, a, narg, args)
 
-### This somewhat helps if solution is very close to one of the points.
-[f,i] = sort (f);
-l = l(i); 
+step = 1;
 
+x = args{narg};
+args{narg} =  x+a*dx; ga = feval (f, args );
+b = a + step;
+args{narg} =  x+b*dx; gb = feval (f, args );
+n = 2;
 
-m = (l(2) - l(1))/(l(3) - l(1));
-d = (2*(f(1)*(m-1)+f(2)-f(3)*m));
-if abs (d) < eps,
-  printf ("poly_2_ex : divisor is small (solution at infinity)\n");
-  printf ("%8.3e %8.3e %8.3e, %8.3e %8.3e\n",...
-	  f(1), diff (f), diff (sort (l)));
+if gb >= ga, return ; end
 
-  ex = (2*(l(1)>l(2))-1)*inf;
-  ## keyboard
-else
-  ex  =  ((l(3) - l(1))*((f(1)*(m^2-1) + f(2) - f(3)*m^2))) / d ;
+while 1,
 
-## Not an improvement
-#  n = ((l(2)+l(3))*(l(2)-l(3)) + 2*(l(3)-l(2))*l(1)) / (l(3)-l(1))^2 ;
-#  ex =  ((l(3) - l(1))*((f(1)*n + f(2) - f(3)*m^2))) / \
-#      (2*(f(1)*(m-1)+f(2)-f(3)*m));
-#  if ex != ex0,
-#    ex -  ex0
-#  end
-  ex = l(1) + ex;
+  c = b + step;
+  args{narg} = x+c*dx; gc = feval( f, args );
+  n++;
+
+  if gc >= gb,			# ga >= gb <= gc
+    gb = gc; b = c;
+    return;
+  end
+  step *= 2;
+  a = b; b = c; ga = gb; gb = gc;
 end