diff options
Diffstat (limited to 'gsl-1.9/min')
-rw-r--r-- | gsl-1.9/min/ChangeLog | 77 | ||||
-rw-r--r-- | gsl-1.9/min/Makefile.am | 16 | ||||
-rw-r--r-- | gsl-1.9/min/Makefile.in | 545 | ||||
-rw-r--r-- | gsl-1.9/min/bracketing.c | 125 | ||||
-rw-r--r-- | gsl-1.9/min/brent.c | 223 | ||||
-rw-r--r-- | gsl-1.9/min/convergence.c | 61 | ||||
-rw-r--r-- | gsl-1.9/min/fsolver.c | 200 | ||||
-rw-r--r-- | gsl-1.9/min/golden.c | 120 | ||||
-rw-r--r-- | gsl-1.9/min/gsl_min.h | 110 | ||||
-rw-r--r-- | gsl-1.9/min/min.h | 25 | ||||
-rw-r--r-- | gsl-1.9/min/test.c | 215 | ||||
-rw-r--r-- | gsl-1.9/min/test.h | 42 | ||||
-rw-r--r-- | gsl-1.9/min/test_funcs.c | 85 |
13 files changed, 1844 insertions, 0 deletions
diff --git a/gsl-1.9/min/ChangeLog b/gsl-1.9/min/ChangeLog new file mode 100644 index 0000000..8fc94c7 --- /dev/null +++ b/gsl-1.9/min/ChangeLog @@ -0,0 +1,77 @@ +2005-09-09 Brian Gough <bjg@network-theory.co.uk> + + * min.h: improved error message, function can be discontinuous + despite what error message said. + +2005-04-28 Brian Gough <bjg@network-theory.co.uk> + + * brent.c (brent_iterate): fixed error in ordering of tests for + updates so that it agrees with Brent's book. + +2004-04-13 Brian Gough <bjg@network-theory.co.uk> + + * brent.c (brent_iterate): corrected condition for setting to + +/-tolerance. + +Sun Apr 7 15:22:11 2002 Brian Gough <bjg@network-theory.co.uk> + + * fsolver.c (gsl_min_fminimizer_x_minimum): new function, + obsoletes gsl_min_fminimizer_minimum. + (gsl_min_fminimizer_f_minimum): new function for accessing + function values + (gsl_min_fminimizer_f_lower): new function for accessing function + values + (gsl_min_fminimizer_f_upper): new function for accessing function + values + + * renamed minimum to x_minimum throughout + +Wed Oct 3 11:35:45 2001 Brian Gough <bjg@network-theory.co.uk> + + * test.c (main): added an extra test + +Sun Jul 15 17:53:26 2001 Brian Gough <bjg@network-theory.co.uk> + + * eliminated interval type, changed order of arguments to set + functions + +Tue Apr 17 22:13:58 2001 Brian Gough <bjg@network-theory.co.uk> + + * fsolver.c (gsl_min_fminimizer_alloc): removed unnecessary status + variable + +Mon Apr 2 14:54:33 2001 Brian Gough <bjg@network-theory.co.uk> + + * brent.c (brent_init): fixed incorrect value for golden ratio + (brent_iterate): fixed incorrect value for golden ratio + + * golden.c (goldensection_iterate): fixed incorrect value for + golden ratio + + * bracketing.c (gsl_min_find_bracket): fixed incorrect value for + golden ratio + +Sun Feb 18 11:43:04 2001 Brian Gough <bjg@network-theory.co.uk> + + * fsolver.c: changed so that the solver _alloc function no longer + calls _set, the user must do that separately. + +Fri May 5 16:09:11 2000 Brian Gough <bjg@network-theory.co.uk> + + * test.c (test_bracket): fixed warning about "control reaches end + of non-void function" by changing return type to void + +Tue Feb 15 16:32:55 2000 Brian Gough <bjg@network-theory.co.uk> + + * bracketing.c (gsl_min_find_bracket): changed counter nb_eval + from type int to type size_t in order to avoid comparison between + signed and unsigned, (nb_eval < eval_max). + +Mon Feb 14 13:07:43 2000 Brian Gough <bjg@network-theory.co.uk> + + * made all internal functions static + +Wed Oct 13 16:08:03 1999 Brian Gough <bjg@network-theory.co.uk> + + * rewritten to allow initial values to be specified + diff --git a/gsl-1.9/min/Makefile.am b/gsl-1.9/min/Makefile.am new file mode 100644 index 0000000..37d8304 --- /dev/null +++ b/gsl-1.9/min/Makefile.am @@ -0,0 +1,16 @@ +noinst_LTLIBRARIES = libgslmin.la + +pkginclude_HEADERS = gsl_min.h + +noinst_HEADERS = min.h + +INCLUDES= -I$(top_builddir) + +libgslmin_la_SOURCES = fsolver.c golden.c brent.c convergence.c bracketing.c + +check_PROGRAMS = test + +TESTS = $(check_PROGRAMS) + +test_SOURCES = test.c test_funcs.c test.h +test_LDADD = libgslmin.la ../ieee-utils/libgslieeeutils.la ../err/libgslerr.la ../test/libgsltest.la ../utils/libutils.la ../sys/libgslsys.la diff --git a/gsl-1.9/min/Makefile.in b/gsl-1.9/min/Makefile.in new file mode 100644 index 0000000..046e78d --- /dev/null +++ b/gsl-1.9/min/Makefile.in @@ -0,0 +1,545 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +check_PROGRAMS = test$(EXEEXT) +subdir = min +DIST_COMMON = $(noinst_HEADERS) $(pkginclude_HEADERS) \ + $(srcdir)/Makefile.am $(srcdir)/Makefile.in ChangeLog +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libgslmin_la_LIBADD = +am_libgslmin_la_OBJECTS = fsolver.lo golden.lo brent.lo convergence.lo \ + bracketing.lo +libgslmin_la_OBJECTS = $(am_libgslmin_la_OBJECTS) +am_test_OBJECTS = test.$(OBJEXT) test_funcs.$(OBJEXT) +test_OBJECTS = $(am_test_OBJECTS) +test_DEPENDENCIES = libgslmin.la ../ieee-utils/libgslieeeutils.la \ + ../err/libgslerr.la ../test/libgsltest.la ../utils/libutils.la \ + ../sys/libgslsys.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libgslmin_la_SOURCES) $(test_SOURCES) +DIST_SOURCES = $(libgslmin_la_SOURCES) $(test_SOURCES) +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(pkgincludedir)" +pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GSL_CFLAGS = @GSL_CFLAGS@ +GSL_LIBS = @GSL_LIBS@ +GSL_LT_CBLAS_VERSION = @GSL_LT_CBLAS_VERSION@ +GSL_LT_VERSION = @GSL_LT_VERSION@ +HAVE_AIX_IEEE_INTERFACE = @HAVE_AIX_IEEE_INTERFACE@ +HAVE_DARWIN86_IEEE_INTERFACE = @HAVE_DARWIN86_IEEE_INTERFACE@ +HAVE_DARWIN_IEEE_INTERFACE = @HAVE_DARWIN_IEEE_INTERFACE@ +HAVE_EXTENDED_PRECISION_REGISTERS = @HAVE_EXTENDED_PRECISION_REGISTERS@ +HAVE_FREEBSD_IEEE_INTERFACE = @HAVE_FREEBSD_IEEE_INTERFACE@ +HAVE_GNUM68K_IEEE_INTERFACE = @HAVE_GNUM68K_IEEE_INTERFACE@ +HAVE_GNUPPC_IEEE_INTERFACE = @HAVE_GNUPPC_IEEE_INTERFACE@ +HAVE_GNUSPARC_IEEE_INTERFACE = @HAVE_GNUSPARC_IEEE_INTERFACE@ +HAVE_GNUX86_IEEE_INTERFACE = @HAVE_GNUX86_IEEE_INTERFACE@ +HAVE_HPUX11_IEEE_INTERFACE = @HAVE_HPUX11_IEEE_INTERFACE@ +HAVE_HPUX_IEEE_INTERFACE = @HAVE_HPUX_IEEE_INTERFACE@ +HAVE_IEEE_COMPARISONS = @HAVE_IEEE_COMPARISONS@ +HAVE_IEEE_DENORMALS = @HAVE_IEEE_DENORMALS@ +HAVE_INLINE = @HAVE_INLINE@ +HAVE_IRIX_IEEE_INTERFACE = @HAVE_IRIX_IEEE_INTERFACE@ +HAVE_NETBSD_IEEE_INTERFACE = @HAVE_NETBSD_IEEE_INTERFACE@ +HAVE_OPENBSD_IEEE_INTERFACE = @HAVE_OPENBSD_IEEE_INTERFACE@ +HAVE_OS2EMX_IEEE_INTERFACE = @HAVE_OS2EMX_IEEE_INTERFACE@ +HAVE_PRINTF_LONGDOUBLE = @HAVE_PRINTF_LONGDOUBLE@ +HAVE_SOLARIS_IEEE_INTERFACE = @HAVE_SOLARIS_IEEE_INTERFACE@ +HAVE_SUNOS4_IEEE_INTERFACE = @HAVE_SUNOS4_IEEE_INTERFACE@ +HAVE_TRU64_IEEE_INTERFACE = @HAVE_TRU64_IEEE_INTERFACE@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ +MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +RELEASED = @RELEASED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__leading_dot = @am__leading_dot@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +noinst_LTLIBRARIES = libgslmin.la +pkginclude_HEADERS = gsl_min.h +noinst_HEADERS = min.h +INCLUDES = -I$(top_builddir) +libgslmin_la_SOURCES = fsolver.c golden.c brent.c convergence.c bracketing.c +TESTS = $(check_PROGRAMS) +test_SOURCES = test.c test_funcs.c test.h +test_LDADD = libgslmin.la ../ieee-utils/libgslieeeutils.la ../err/libgslerr.la ../test/libgsltest.la ../utils/libutils.la ../sys/libgslsys.la +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu --ignore-deps min/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu --ignore-deps min/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgslmin.la: $(libgslmin_la_OBJECTS) $(libgslmin_la_DEPENDENCIES) + $(LINK) $(libgslmin_la_LDFLAGS) $(libgslmin_la_OBJECTS) $(libgslmin_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +test$(EXEEXT): $(test_OBJECTS) $(test_DEPENDENCIES) + @rm -f test$(EXEEXT) + $(LINK) $(test_LDFLAGS) $(test_OBJECTS) $(test_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.c.o: + $(COMPILE) -c $< + +.c.obj: + $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: + $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(pkgincludedir)" || $(mkdir_p) "$(DESTDIR)$(pkgincludedir)" + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(pkgincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgincludedir)/$$f'"; \ + $(pkgincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgincludedir)/$$f"; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(pkgincludedir)/$$f'"; \ + rm -f "$(DESTDIR)$(pkgincludedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkgincludedir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-pkgincludeHEADERS + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-exec install-exec-am \ + install-info install-info-am install-man \ + install-pkgincludeHEADERS install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-pkgincludeHEADERS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/gsl-1.9/min/bracketing.c b/gsl-1.9/min/bracketing.c new file mode 100644 index 0000000..f3ceaf4 --- /dev/null +++ b/gsl-1.9/min/bracketing.c @@ -0,0 +1,125 @@ +/* min/bracketing.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Fabrice Rossi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/* bracketing.c -- find an initial bracketing interval for a function to minimize */ + +#include <config.h> +#include <gsl/gsl_math.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_min.h> +#include <gsl/gsl_machine.h> + +#include "min.h" + +int +gsl_min_find_bracket(gsl_function *f,double *x_minimum,double * f_minimum, + double * x_lower, double * f_lower, + double * x_upper, double * f_upper, + size_t eval_max) +{ + /* The three following variables must be declared volatile to avoid storage + in extended precision registers available on some architecture. The code + relies on the ability to compare double values. As the values will be + store in regular memory, the extended precision will then be lost and + values that are different in extended precision might have equal + representation in double precision. This behavior might break the + algorithm. + */ + volatile double f_left = *f_lower; + volatile double f_right = *f_upper; + volatile double f_center; + double x_left = *x_lower; + double x_right= *x_upper; + double x_center; + const double golden = 0.3819660; /* golden = (3 - sqrt(5))/2 */ + size_t nb_eval = 0; + + + if (f_right >= f_left) + { + x_center = (x_right - x_left) * golden + x_left; + nb_eval++; + SAFE_FUNC_CALL (f, x_center, &f_center); + } + else + { + x_center = x_right ; + f_center = f_right ; + x_right = (x_center - x_left) / golden + x_left; + nb_eval++; + SAFE_FUNC_CALL (f, x_right, &f_right); + } + + do + { + if (f_center < f_left ) + { + if (f_center < f_right) + { + *x_lower = x_left; + *x_upper = x_right; + *x_minimum = x_center; + *f_lower = f_left; + *f_upper = f_right; + *f_minimum = f_center; +/* gsl_ieee_printf_double (&f_left); + printf(" "); + gsl_ieee_printf_double (&f_center); + printf("\n");*/ + return GSL_SUCCESS; + } + else if (f_center > f_right) + { + x_left = x_center; + f_left = f_center; + x_center = x_right; + f_center = f_right; + x_right = (x_center - x_left) / golden + x_left; + nb_eval++; + SAFE_FUNC_CALL (f, x_right, &f_right); + } + else /* f_center == f_right */ + { + x_right = x_center; + f_right = f_center; + x_center = (x_right - x_left) * golden + x_left; + nb_eval++; + SAFE_FUNC_CALL (f, x_center, &f_center); + } + } + else /* f_center >= f_left */ + { + x_right = x_center; + f_right = f_center; + x_center = (x_right - x_left) * golden + x_left; + nb_eval++; + SAFE_FUNC_CALL (f, x_center, &f_center); + } + } + while (nb_eval < eval_max + && (x_right - x_left) > GSL_SQRT_DBL_EPSILON * ( (x_right + x_left) * 0.5 ) + GSL_SQRT_DBL_EPSILON); + *x_lower = x_left; + *x_upper = x_right; + *x_minimum = x_center; + *f_lower = f_left; + *f_upper = f_right; + *f_minimum = f_center; + return GSL_FAILURE; +} + diff --git a/gsl-1.9/min/brent.c b/gsl-1.9/min/brent.c new file mode 100644 index 0000000..499e015 --- /dev/null +++ b/gsl-1.9/min/brent.c @@ -0,0 +1,223 @@ +/* min/brent.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/* brent.c -- brent minimum finding algorithm */ + +#include <config.h> + +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <float.h> + +#include <gsl/gsl_math.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_min.h> + +#include "min.h" + +typedef struct + { + double d, e, v, w; + double f_v, f_w; + } +brent_state_t; + +static int brent_init (void *vstate, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper); +static int brent_iterate (void *vstate, gsl_function * f, double *x_minimum, double * f_minimum, double * x_lower, double * f_lower, double * x_upper, double * f_upper); + +static int +brent_init (void *vstate, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper) +{ + brent_state_t *state = (brent_state_t *) vstate; + + const double golden = 0.3819660; /* golden = (3 - sqrt(5))/2 */ + + double v = x_lower + golden * (x_upper - x_lower); + double w = v; + + double f_vw; + + x_minimum = 0 ; /* avoid warnings about unused varibles */ + f_minimum = 0 ; + f_lower = 0 ; + f_upper = 0 ; + + state->v = v; + state->w = w; + + state->d = 0; + state->e = 0; + + SAFE_FUNC_CALL (f, v, &f_vw); + + state->f_v = f_vw; + state->f_w = f_vw; + + return GSL_SUCCESS; +} + +static int +brent_iterate (void *vstate, gsl_function * f, double *x_minimum, double * f_minimum, double * x_lower, double * f_lower, double * x_upper, double * f_upper) +{ + brent_state_t *state = (brent_state_t *) vstate; + + const double x_left = *x_lower; + const double x_right = *x_upper; + + const double z = *x_minimum; + double d = state->e; + double e = state->d; + double u, f_u; + const double v = state->v; + const double w = state->w; + const double f_v = state->f_v; + const double f_w = state->f_w; + const double f_z = *f_minimum; + + const double golden = 0.3819660; /* golden = (3 - sqrt(5))/2 */ + + const double w_lower = (z - x_left); + const double w_upper = (x_right - z); + + const double tolerance = GSL_SQRT_DBL_EPSILON * fabs (z); + + double p = 0, q = 0, r = 0; + + const double midpoint = 0.5 * (x_left + x_right); + + if (fabs (e) > tolerance) + { + /* fit parabola */ + + r = (z - w) * (f_z - f_v); + q = (z - v) * (f_z - f_w); + p = (z - v) * q - (z - w) * r; + q = 2 * (q - r); + + if (q > 0) + { + p = -p; + } + else + { + q = -q; + } + + r = e; + e = d; + } + + if (fabs (p) < fabs (0.5 * q * r) && p < q * w_lower && p < q * w_upper) + { + double t2 = 2 * tolerance ; + + d = p / q; + u = z + d; + + if ((u - x_left) < t2 || (x_right - u) < t2) + { + d = (z < midpoint) ? tolerance : -tolerance ; + } + } + else + { + e = (z < midpoint) ? x_right - z : -(z - x_left) ; + d = golden * e; + } + + + if (fabs (d) >= tolerance) + { + u = z + d; + } + else + { + u = z + ((d > 0) ? tolerance : -tolerance) ; + } + + state->e = e; + state->d = d; + + SAFE_FUNC_CALL(f, u, &f_u); + + if (f_u <= f_z) + { + if (u < z) + { + *x_upper = z; + *f_upper = f_z; + } + else + { + *x_lower = z; + *f_lower = f_z; + } + + state->v = w; + state->f_v = f_w; + state->w = z; + state->f_w = f_z; + *x_minimum = u; + *f_minimum = f_u; + return GSL_SUCCESS; + } + else + { + if (u < z) + { + *x_lower = u; + *f_lower = f_u; + return GSL_SUCCESS; + } + else + { + *x_upper = u; + *f_upper = f_u; + return GSL_SUCCESS; + } + + if (f_u <= f_w || w == z) + { + state->v = w; + state->f_v = f_w; + state->w = u; + state->f_w = f_u; + return GSL_SUCCESS; + } + else if (f_u <= f_v || v == z || v == w) + { + state->v = u; + state->f_v = f_u; + return GSL_SUCCESS; + } + } + + return GSL_FAILURE; +} + + +static const gsl_min_fminimizer_type brent_type = +{"brent", /* name */ + sizeof (brent_state_t), + &brent_init, + &brent_iterate}; + +const gsl_min_fminimizer_type *gsl_min_fminimizer_brent = &brent_type; diff --git a/gsl-1.9/min/convergence.c b/gsl-1.9/min/convergence.c new file mode 100644 index 0000000..8bb630d --- /dev/null +++ b/gsl-1.9/min/convergence.c @@ -0,0 +1,61 @@ +/* min/convergence.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <config.h> +#include <gsl/gsl_math.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_min.h> + +int +gsl_min_test_interval (double x_lower, double x_upper, double epsabs, double epsrel) +{ + const double lower = x_lower; + const double upper = x_upper; + + const double abs_lower = fabs(lower) ; + const double abs_upper = fabs(upper) ; + + double min_abs, tolerance; + + if (epsrel < 0.0) + GSL_ERROR ("relative tolerance is negative", GSL_EBADTOL); + + if (epsabs < 0.0) + GSL_ERROR ("absolute tolerance is negative", GSL_EBADTOL); + + if (lower > upper) + GSL_ERROR ("lower bound larger than upper_bound", GSL_EINVAL); + + if ((lower > 0 && upper > 0) || (lower < 0 && upper < 0)) + { + min_abs = GSL_MIN_DBL(abs_lower, abs_upper) ; + } + else + { + min_abs = 0; + } + + tolerance = epsabs + epsrel * min_abs ; + + if (fabs(upper - lower) < tolerance) + return GSL_SUCCESS; + + return GSL_CONTINUE ; +} + diff --git a/gsl-1.9/min/fsolver.c b/gsl-1.9/min/fsolver.c new file mode 100644 index 0000000..36feb91 --- /dev/null +++ b/gsl-1.9/min/fsolver.c @@ -0,0 +1,200 @@ +/* min/fsolver.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <config.h> +#include <stdlib.h> +#include <string.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_min.h> + +#include "min.h" + +static int +compute_f_values (gsl_function * f, double x_minimum, double * f_minimum, + double x_lower, double * f_lower, + double x_upper, double * f_upper); + + +static int +compute_f_values (gsl_function * f, double x_minimum, double * f_minimum, + double x_lower, double * f_lower, + double x_upper, double * f_upper) +{ + SAFE_FUNC_CALL(f, x_lower, f_lower); + SAFE_FUNC_CALL(f, x_upper, f_upper); + SAFE_FUNC_CALL(f, x_minimum, f_minimum); + + return GSL_SUCCESS; +} + +int +gsl_min_fminimizer_set (gsl_min_fminimizer * s, + gsl_function * f, + double x_minimum, double x_lower, double x_upper) +{ + int status ; + + double f_minimum, f_lower, f_upper; + + status = compute_f_values (f, x_minimum, &f_minimum, + x_lower, &f_lower, + x_upper, &f_upper); + + if (status != GSL_SUCCESS) + { + return status ; + } + + status = gsl_min_fminimizer_set_with_values (s, f, x_minimum, f_minimum, + x_lower, f_lower, + x_upper, f_upper); + return status; +} + +gsl_min_fminimizer * +gsl_min_fminimizer_alloc (const gsl_min_fminimizer_type * T) +{ + gsl_min_fminimizer * s = + (gsl_min_fminimizer *) malloc (sizeof (gsl_min_fminimizer)); + + if (s == 0) + { + GSL_ERROR_VAL ("failed to allocate space for minimizer struct", + GSL_ENOMEM, 0); + }; + + s->state = malloc (T->size); + + if (s->state == 0) + { + free (s); /* exception in constructor, avoid memory leak */ + + GSL_ERROR_VAL ("failed to allocate space for minimizer state", + GSL_ENOMEM, 0); + }; + + s->type = T ; + s->function = NULL; + + return s; +} + +int +gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * s, gsl_function * f, + double x_minimum, double f_minimum, + double x_lower, double f_lower, + double x_upper, double f_upper) +{ + s->function = f; + s->x_minimum = x_minimum; + s->x_lower = x_lower; + s->x_upper = x_upper; + + if (x_lower > x_upper) + { + GSL_ERROR ("invalid interval (lower > upper)", GSL_EINVAL); + } + + if (x_minimum >= x_upper || x_minimum <= x_lower) + { + GSL_ERROR ("x_minimum must lie inside interval (lower < x < upper)", + GSL_EINVAL); + } + + s->f_lower = f_lower; + s->f_upper = f_upper; + s->f_minimum = f_minimum; + + if (f_minimum >= f_lower || f_minimum >= f_upper) + { + GSL_ERROR ("endpoints do not enclose a minimum", GSL_EINVAL); + } + + return (s->type->set) (s->state, s->function, + x_minimum, f_minimum, + x_lower, f_lower, + x_upper, f_upper); +} + + +int +gsl_min_fminimizer_iterate (gsl_min_fminimizer * s) +{ + return (s->type->iterate) (s->state, s->function, + &(s->x_minimum), &(s->f_minimum), + &(s->x_lower), &(s->f_lower), + &(s->x_upper), &(s->f_upper)); +} + +void +gsl_min_fminimizer_free (gsl_min_fminimizer * s) +{ + free (s->state); + free (s); +} + +const char * +gsl_min_fminimizer_name (const gsl_min_fminimizer * s) +{ + return s->type->name; +} + +/* Deprecated, use x_minimum instead */ +double +gsl_min_fminimizer_minimum (const gsl_min_fminimizer * s) +{ + return s->x_minimum; +} + +double +gsl_min_fminimizer_x_minimum (const gsl_min_fminimizer * s) +{ + return s->x_minimum; +} + +double +gsl_min_fminimizer_x_lower (const gsl_min_fminimizer * s) +{ + return s->x_lower; +} + +double +gsl_min_fminimizer_x_upper (const gsl_min_fminimizer * s) +{ + return s->x_upper; +} + +double +gsl_min_fminimizer_f_minimum (const gsl_min_fminimizer * s) +{ + return s->f_minimum; +} + +double +gsl_min_fminimizer_f_lower (const gsl_min_fminimizer * s) +{ + return s->f_lower; +} + +double +gsl_min_fminimizer_f_upper (const gsl_min_fminimizer * s) +{ + return s->f_upper; +} + diff --git a/gsl-1.9/min/golden.c b/gsl-1.9/min/golden.c new file mode 100644 index 0000000..49dfddb --- /dev/null +++ b/gsl-1.9/min/golden.c @@ -0,0 +1,120 @@ +/* min/golden.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +/* goldensection.c -- goldensection minimum finding algorithm */ + +#include <config.h> + +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <float.h> + +#include <gsl/gsl_math.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_min.h> + +#include "min.h" + +typedef struct + { + double dummy; + } +goldensection_state_t; + +static int goldensection_init (void * vstate, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper); +static int goldensection_iterate (void * vstate, gsl_function * f, double * x_minimum, double * f_minimum, double * x_lower, double * f_lower, double * x_upper, double * f_upper); + +static int +goldensection_init (void * vstate, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper) +{ + goldensection_state_t * state = (goldensection_state_t *) vstate; + + /* no initialization required, prevent warnings about unused variables */ + + state = 0; + f = 0; + x_minimum = 0; + f_minimum = 0; + x_lower = 0; + f_lower = 0; + x_upper = 0; + f_upper = 0; + + return GSL_SUCCESS; +} + +static int +goldensection_iterate (void * vstate, gsl_function * f, double * x_minimum, double * f_minimum, double * x_lower, double * f_lower, double * x_upper, double * f_upper) +{ + goldensection_state_t * state = (goldensection_state_t *) vstate; + + const double x_center = *x_minimum ; + const double x_left = *x_lower ; + const double x_right = *x_upper ; + + const double f_min = *f_minimum; + + const double golden = 0.3819660; /* golden = (3 - sqrt(5))/2 */ + + const double w_lower = (x_center - x_left); + const double w_upper = (x_right - x_center); + + double x_new, f_new; + + state = 0 ; /* avoid warning about unused parameters */ + + x_new = x_center + golden * ((w_upper > w_lower) ? w_upper : -w_lower) ; + + SAFE_FUNC_CALL (f, x_new, &f_new); + + if (f_new < f_min) + { + *x_minimum = x_new ; + *f_minimum = f_new ; + return GSL_SUCCESS; + } + else if (x_new < x_center && f_new > f_min) + { + *x_lower = x_new ; + *f_lower = f_new ; + return GSL_SUCCESS; + } + else if (x_new > x_center && f_new > f_min) + { + *x_upper = x_new ; + *f_upper = f_new ; + return GSL_SUCCESS; + } + else + { + return GSL_FAILURE; + } +} + + +static const gsl_min_fminimizer_type goldensection_type = +{"goldensection", /* name */ + sizeof (goldensection_state_t), + &goldensection_init, + &goldensection_iterate}; + +const gsl_min_fminimizer_type * gsl_min_fminimizer_goldensection = &goldensection_type; diff --git a/gsl-1.9/min/gsl_min.h b/gsl-1.9/min/gsl_min.h new file mode 100644 index 0000000..88fe640 --- /dev/null +++ b/gsl-1.9/min/gsl_min.h @@ -0,0 +1,110 @@ +/* min/gsl_min.h + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __GSL_MIN_H__ +#define __GSL_MIN_H__ + +#include <stdlib.h> +#include <gsl/gsl_types.h> +#include <gsl/gsl_math.h> + +#undef __BEGIN_DECLS +#undef __END_DECLS +#ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# define __END_DECLS } +#else +# define __BEGIN_DECLS /* empty */ +# define __END_DECLS /* empty */ +#endif + +__BEGIN_DECLS + +typedef struct + { + const char *name; + size_t size; + int (*set) (void *state, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper); + int (*iterate) (void *state, gsl_function * f, double * x_minimum, double * f_minimum, double * x_lower, double * f_lower, double * x_upper, double * f_upper); + } +gsl_min_fminimizer_type; + +typedef struct + { + const gsl_min_fminimizer_type * type; + gsl_function * function ; + double x_minimum ; + double x_lower ; + double x_upper ; + double f_minimum, f_lower, f_upper; + void *state; + } +gsl_min_fminimizer; + +gsl_min_fminimizer * +gsl_min_fminimizer_alloc (const gsl_min_fminimizer_type * T) ; + +void gsl_min_fminimizer_free (gsl_min_fminimizer * s); + +int gsl_min_fminimizer_set (gsl_min_fminimizer * s, + gsl_function * f, double x_minimum, + double x_lower, double x_upper); + +int gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * s, + gsl_function * f, + double x_minimum, double f_minimum, + double x_lower, double f_lower, + double x_upper, double f_upper); + +int gsl_min_fminimizer_iterate (gsl_min_fminimizer * s); + +const char * gsl_min_fminimizer_name (const gsl_min_fminimizer * s); + +double gsl_min_fminimizer_x_minimum (const gsl_min_fminimizer * s); +double gsl_min_fminimizer_x_lower (const gsl_min_fminimizer * s); +double gsl_min_fminimizer_x_upper (const gsl_min_fminimizer * s); +double gsl_min_fminimizer_f_minimum (const gsl_min_fminimizer * s); +double gsl_min_fminimizer_f_lower (const gsl_min_fminimizer * s); +double gsl_min_fminimizer_f_upper (const gsl_min_fminimizer * s); + +/* Deprecated, use x_minimum instead */ +double gsl_min_fminimizer_minimum (const gsl_min_fminimizer * s); + +int +gsl_min_test_interval (double x_lower, double x_upper, double epsabs, double epsrel); + +GSL_VAR const gsl_min_fminimizer_type * gsl_min_fminimizer_goldensection; +GSL_VAR const gsl_min_fminimizer_type * gsl_min_fminimizer_brent; + +typedef +int (*gsl_min_bracketing_function)(gsl_function *f, + double *x_minimum,double * f_minimum, + double *x_lower, double * f_lower, + double *x_upper, double * f_upper, + size_t eval_max); + +int +gsl_min_find_bracket(gsl_function *f,double *x_minimum,double * f_minimum, + double *x_lower, double * f_lower, + double *x_upper, double * f_upper, + size_t eval_max); + +__END_DECLS + +#endif /* __GSL_MIN_H__ */ diff --git a/gsl-1.9/min/min.h b/gsl-1.9/min/min.h new file mode 100644 index 0000000..e2dd45f --- /dev/null +++ b/gsl-1.9/min/min.h @@ -0,0 +1,25 @@ +/* min/min.h + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#define SAFE_FUNC_CALL(f, x, yp) \ +do { \ + *yp = GSL_FN_EVAL(f,x); \ + if (!finite(*yp)) \ + GSL_ERROR("computed function value is infinite or NaN", GSL_EBADFUNC); \ +} while (0) diff --git a/gsl-1.9/min/test.c b/gsl-1.9/min/test.c new file mode 100644 index 0000000..4493a0e --- /dev/null +++ b/gsl-1.9/min/test.c @@ -0,0 +1,215 @@ +/* min/test.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include <config.h> +#include <stdlib.h> +#include <gsl/gsl_math.h> +#include <gsl/gsl_min.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_test.h> +#include <gsl/gsl_ieee_utils.h> + +#include "test.h" +#include "min.h" + +/* stopping parameters */ + +const double EPSABS = 0.001 ; +const double EPSREL = 0.001 ; + +const unsigned int MAX_ITERATIONS = 100; + +void my_error_handler (const char *reason, const char *file, + int line, int err); + +#define WITHIN_TOL(a, b, epsrel, epsabs) \ + (fabs((a) - (b)) < (epsrel) * GSL_MIN(fabs(a), fabs(b)) + (epsabs)) + +int +main (void) +{ + gsl_function F_cos, F_func1, F_func2, F_func3, F_func4; + + const gsl_min_fminimizer_type * fminimizer[4] ; + const gsl_min_fminimizer_type ** T; + + gsl_ieee_env_setup (); + + fminimizer[0] = gsl_min_fminimizer_goldensection; + fminimizer[1] = gsl_min_fminimizer_brent; + fminimizer[2] = 0; + + F_cos = create_function (f_cos) ; + F_func1 = create_function (func1) ; + F_func2 = create_function (func2) ; + F_func3 = create_function (func3) ; + F_func4 = create_function (func4) ; + + gsl_set_error_handler (&my_error_handler); + + for (T = fminimizer ; *T != 0 ; T++) + { + test_f (*T, "cos(x) [0 (3) 6]", &F_cos, 0.0, 3.0, 6.0, M_PI); + test_f (*T, "x^4 - 1 [-3 (-1) 17]", &F_func1, -3.0, -1.0, 17.0, 0.0); + test_f (*T, "sqrt(|x|) [-2 (-1) 1.5]", &F_func2, -2.0, -1.0, 1.5, 0.0); + test_f (*T, "func3(x) [-2 (3) 4]", &F_func3, -2.0, 3.0, 4.0, 1.0); + test_f (*T, "func4(x) [0 (0.782) 1]", &F_func4, 0, 0.782, 1.0, 0.8); + + test_f_e (*T, "invalid range check [4, 0]", &F_cos, 4.0, 3.0, 0.0, M_PI); + test_f_e (*T, "invalid range check [1, 1]", &F_cos, 1.0, 1.0, 1.0, M_PI); + test_f_e (*T, "invalid range check [-1, 1]", &F_cos, -1.0, 0.0, 1.0, M_PI); + } + test_bracket("cos(x) [1,2]",&F_cos,1.0,2.0,15); + test_bracket("sqrt(|x|) [-1,0]",&F_func2,-1.0,0.0,15); + test_bracket("sqrt(|x|) [-1,-0.6]",&F_func2,-1.0,-0.6,15); + test_bracket("sqrt(|x|) [-1,1]",&F_func2,-1.0,1.0,15); + + exit (gsl_test_summary ()); +} + +void +test_f (const gsl_min_fminimizer_type * T, + const char * description, gsl_function *f, + double lower_bound, double middle, double upper_bound, + double correct_minimum) +{ + int status; + size_t iterations = 0; + double m, a, b; + double x_lower, x_upper; + gsl_min_fminimizer * s; + + x_lower = lower_bound; + x_upper = upper_bound; + + s = gsl_min_fminimizer_alloc (T) ; + gsl_min_fminimizer_set (s, f, middle, x_lower, x_upper) ; + + do + { + iterations++ ; + + status = gsl_min_fminimizer_iterate (s); + + m = gsl_min_fminimizer_x_minimum(s); + a = gsl_min_fminimizer_x_lower(s); + b = gsl_min_fminimizer_x_upper(s); + +#ifdef DEBUG + printf("%.12f %.18f %.12f %.18f %.12f %.18f\n", + a, GSL_FN_EVAL(f, a), m, GSL_FN_EVAL(f, m), b, GSL_FN_EVAL(f, b)); +#endif + + if (a > b) + gsl_test (GSL_FAILURE, "interval is invalid (%g,%g)", a, b); + + if (m < a || m > b) + gsl_test (GSL_FAILURE, "m lies outside interval %g (%g,%g)", m, a, b); + + if (status) break ; + + status = gsl_min_test_interval (a, b, EPSABS, EPSREL); + } + while (status == GSL_CONTINUE && iterations < MAX_ITERATIONS); + + gsl_test (status, "%s, %s (%g obs vs %g expected) ", + gsl_min_fminimizer_name(s), description, + gsl_min_fminimizer_x_minimum(s), correct_minimum); + + /* check the validity of the returned result */ + + if (!WITHIN_TOL (m, correct_minimum, EPSREL, EPSABS)) + { + gsl_test (GSL_FAILURE, "incorrect precision (%g obs vs %g expected)", + m, correct_minimum); + } + + gsl_min_fminimizer_free (s); + +} + +void +test_f_e (const gsl_min_fminimizer_type * T, + const char * description, gsl_function *f, + double lower_bound, double middle, double upper_bound, + double correct_minimum) +{ + int status; + size_t iterations = 0; + double x_lower, x_upper; + double a, b; + gsl_min_fminimizer * s; + + x_lower = lower_bound; + x_upper = upper_bound; + + s = gsl_min_fminimizer_alloc (T) ; + status = gsl_min_fminimizer_set (s, f, middle, x_lower, x_upper) ; + + if (status != GSL_SUCCESS) + { + gsl_min_fminimizer_free (s) ; + gsl_test (status == GSL_SUCCESS, "%s, %s", T->name, description); + return ; + } + + do + { + iterations++ ; + gsl_min_fminimizer_iterate (s); + a = gsl_min_fminimizer_x_lower(s); + b = gsl_min_fminimizer_x_upper(s); + + status = gsl_min_test_interval (a, b, EPSABS, EPSREL); + } + while (status == GSL_CONTINUE && iterations < MAX_ITERATIONS); + + gsl_test (!status, "%s, %s", gsl_min_fminimizer_name(s), description, + gsl_min_fminimizer_x_minimum(s) - correct_minimum); + + gsl_min_fminimizer_free (s); +} + +void +my_error_handler (const char *reason, const char *file, int line, int err) +{ + if (0) + printf ("(caught [%s:%d: %s (%d)])\n", file, line, reason, err); +} + +int +test_bracket (const char * description,gsl_function *f,double lower_bound, + double upper_bound, unsigned int max) +{ + int status; + double x_lower, x_upper; + double f_upper,f_lower,f_minimum; + double x_minimum; + + x_lower=lower_bound; + x_upper=upper_bound; + SAFE_FUNC_CALL (f,x_lower,&f_lower); + SAFE_FUNC_CALL (f,x_upper,&f_upper); + status=gsl_min_find_bracket(f,&x_minimum,&f_minimum,&x_lower,&f_lower,&x_upper,&f_upper,max); + gsl_test (status,"%s, interval: [%g,%g], values: (%g,%g), minimum at: %g, value: %g", + description,x_lower,x_upper,f_lower,f_upper,x_minimum,f_minimum); + return status; +} + + + diff --git a/gsl-1.9/min/test.h b/gsl-1.9/min/test.h new file mode 100644 index 0000000..24fa8c5 --- /dev/null +++ b/gsl-1.9/min/test.h @@ -0,0 +1,42 @@ +/* min/test.h + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +gsl_function create_function (double (*f)(double, void *)); + +void +test_f_e (const gsl_min_fminimizer_type * T, + const char * description, gsl_function *f, + double lower_bound, double minimum, double upper_bound, + double correct_minimum); + +void +test_f (const gsl_min_fminimizer_type * T, + const char * description, gsl_function *f, + double lower_bound, double middle, double upper_bound, + double correct_minimum); + +int +test_bracket (const char * description,gsl_function *f,double lower_bound, + double upper_bound, unsigned int max); + +double f_cos (double x, void * p); +double func1 (double x, void * p); +double func2 (double x, void * p); +double func3 (double x, void * p); +double func4 (double x, void * p); diff --git a/gsl-1.9/min/test_funcs.c b/gsl-1.9/min/test_funcs.c new file mode 100644 index 0000000..9d45be2 --- /dev/null +++ b/gsl-1.9/min/test_funcs.c @@ -0,0 +1,85 @@ +/* min/test_funcs.c + * + * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <gsl/gsl_math.h> +#include <gsl/gsl_min.h> + +#include "test.h" + +gsl_function create_function (double (*f)(double, void *)) +{ + gsl_function F ; + F.function = f ; + F.params = 0 ; + return F ; +} + +double +f_cos (double x, void * p) +{ + p = 0; /* avoid warning about unused parameter */ + return cos(x); +} + +/* f(x) = x^4 - 1 */ +/* minimum at x = 0 */ + +double +func1 (double x, void * p) +{ + p = 0; /* avoid warning about unused parameter */ + return pow (x, 4.0) - 1; +} + +/* f(x) = sqrt(|x|) */ +/* minimum at x = 0 */ + +double +func2 (double x, void * p) +{ + p = 0; /* avoid warning about unused parameter */ + return sqrt(fabs(x)); +} + + +/* f(x) = 1 for x < 1 and -exp(-x) for x >= 1 */ +/* minimum at x = 1 */ + +double +func3 (double x, void * p) +{ + p = 0; /* avoid warning about unused parameter */ + + if (x < 1) + return 1 ; + else + return - exp(-x) ; +} + +/* f(x) = x - 30/(1+1e5*(x-0.8)**2) */ +/* minimum near x = 0.8 */ + +double +func4 (double x, void * p) +{ + p = 0; /* avoid warning about unused parameter */ + + return x - 30.0 / (1.0 + 1e5 * pow(x-0.8, 2.0)); +} + |