summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/gsl-aux.c
diff options
context:
space:
mode:
authorKristof Bastiaensen <kristof@vleeuwen.org>2013-08-16 14:16:32 +0200
committerKristof Bastiaensen <kristof@vleeuwen.org>2013-08-16 14:16:32 +0200
commite208b972e38eff84c0287ae6bf32db7b42cce0f6 (patch)
tree82a65722ae7a8fd67fd60a47e74d0d8c2bb358a5 /lib/Numeric/GSL/gsl-aux.c
parent374194ee454622e66c931dce8f315c68167c7ac9 (diff)
Added onedimensional minimization.
Diffstat (limited to 'lib/Numeric/GSL/gsl-aux.c')
-rw-r--r--lib/Numeric/GSL/gsl-aux.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c
index e727c91..58bccb3 100644
--- a/lib/Numeric/GSL/gsl-aux.c
+++ b/lib/Numeric/GSL/gsl-aux.c
@@ -29,6 +29,7 @@
29#include <gsl/gsl_poly.h> 29#include <gsl/gsl_poly.h>
30#include <gsl/gsl_multimin.h> 30#include <gsl/gsl_multimin.h>
31#include <gsl/gsl_multiroots.h> 31#include <gsl/gsl_multiroots.h>
32#include <gsl/gsl_min.h>
32#include <gsl/gsl_complex_math.h> 33#include <gsl/gsl_complex_math.h>
33#include <gsl/gsl_rng.h> 34#include <gsl/gsl_rng.h>
34#include <gsl/gsl_randist.h> 35#include <gsl/gsl_randist.h>
@@ -892,6 +893,59 @@ double only_f_aux_min(const gsl_vector*x, void *pars) {
892 return res; 893 return res;
893} 894}
894 895
896double only_f_aux_root(double x, void *pars);
897int uniMinimize(int method, double f(double),
898 double epsrel, int maxit, double min,
899 double xl, double xu, RMAT(sol)) {
900 REQUIRES(solr == maxit && solc == 4,BAD_SIZE);
901 DEBUGMSG("minimize_only_f");
902 gsl_function my_func;
903 my_func.function = only_f_aux_root;
904 my_func.params = f;
905 size_t iter = 0;
906 int status;
907 const gsl_min_fminimizer_type *T;
908 gsl_min_fminimizer *s;
909 // Starting point
910 switch(method) {
911 case 0 : {T = gsl_min_fminimizer_goldensection; break; }
912 case 1 : {T = gsl_min_fminimizer_brent; break; }
913 case 2 : {T = gsl_min_fminimizer_quad_golden; break; }
914 default: ERROR(BAD_CODE);
915 }
916 s = gsl_min_fminimizer_alloc (T);
917 gsl_min_fminimizer_set (s, &my_func, min, xl, xu);
918 do {
919 double current_min, current_lo, current_hi;
920 status = gsl_min_fminimizer_iterate (s);
921 current_min = gsl_min_fminimizer_x_minimum (s);
922 current_lo = gsl_min_fminimizer_x_lower (s);
923 current_hi = gsl_min_fminimizer_x_upper (s);
924 solp[iter*solc] = iter + 1;
925 solp[iter*solc+1] = current_min;
926 solp[iter*solc+2] = current_lo;
927 solp[iter*solc+3] = current_hi;
928 iter++;
929 if (status) /* check if solver is stuck */
930 break;
931
932 status =
933 gsl_min_test_interval (current_lo, current_hi, 0, epsrel);
934 }
935 while (status == GSL_CONTINUE && iter < maxit);
936 int i;
937 for (i=iter; i<solr; i++) {
938 solp[i*solc+0] = iter;
939 solp[i*solc+1]=0.;
940 solp[i*solc+2]=0.;
941 solp[i*solc+3]=0.;
942 }
943 gsl_min_fminimizer_free(s);
944 OK
945}
946
947
948
895// this version returns info about intermediate steps 949// this version returns info about intermediate steps
896int minimize(int method, double f(int, double*), double tolsize, int maxit, 950int minimize(int method, double f(int, double*), double tolsize, int maxit,
897 KRVEC(xi), KRVEC(sz), RMAT(sol)) { 951 KRVEC(xi), KRVEC(sz), RMAT(sol)) {