chiark / gitweb /
add get/set subspace dimension for low-storage quasi-Newton methods
authorstevenj <stevenj@alum.mit.edu>
Thu, 18 Nov 2010 23:42:23 +0000 (18:42 -0500)
committerstevenj <stevenj@alum.mit.edu>
Thu, 18 Nov 2010 23:42:23 +0000 (18:42 -0500)
darcs-hash:20101118234223-c8de0-d7c2ef4736197f0a7e56a568a5987b3a7b5cea7e.gz

13 files changed:
api/f77funcs_.h
api/nlopt-in.hpp
api/nlopt-internal.h
api/nlopt.h
api/optimize.c
api/options.c
luksan/luksan.h
luksan/plip.c
luksan/plis.c
luksan/pnet.c
octave/nlopt_optimize-mex.c
octave/nlopt_optimize-oct.cc
swig/nlopt-exceptions.i

index 8641535cafd372e46c81a950bb040f66521605c3..9a2dd94dc80c869dcb6f77e2ed83cccda39708b9 100644 (file)
@@ -157,6 +157,7 @@ void F77_(nlo_force_stop,NLO_FORCE_STOP)(int *ret, nlopt_opt *opt) {
 
 F77_SET(local_optimizer, LOCAL_OPTIMIZER, nlopt_opt)
 F77_GETSET(population, POPULATION, unsigned)
+F77_GETSET(subspace_dim, SUBSPACE_DIM, unsigned)
 
 F77_SETA(default_initial_step, DEFAULT_INITIAL_STEP, double)
 F77_SETA(initial_step, INITIAL_STEP, double)
index 22251a23c1ae409545cb73cbc145b6ff4d617072..09215fdc9fcd51eecf79788452fc01c161bb9a0a 100644 (file)
@@ -476,6 +476,7 @@ namespace nlopt {
     }
 
     NLOPT_GETSET(unsigned, population)
+    NLOPT_GETSET(unsigned, subspace_dim)
     NLOPT_GETSET_VEC(initial_step)
 
     void set_default_initial_step(const std::vector<double> &x) {
index 7de7c550e8f2dc9bea666e299ae9a0cb542e7273..388d4e5b014226a515033d9b059533e0d45f7167 100644 (file)
@@ -69,6 +69,7 @@ struct nlopt_opt_s {
      nlopt_opt local_opt; /* local optimizer */
      unsigned stochastic_population; /* population size for stochastic algs */
      double *dx; /* initial step sizes (length n) for nonderivative algs */
+     unsigned subspace_dim; /* max subspace dimension (0 for default) */
 
      double *work; /* algorithm-specific workspace during optimization */
 };
index 2e5fc4ba63b9a444bf2d98aaee044584c033b037..5f09f2a0b0e44d09725e56bd198984e7963e5f7e 100644 (file)
@@ -268,6 +268,9 @@ NLOPT_EXTERN(nlopt_result) nlopt_set_local_optimizer(nlopt_opt opt,
 NLOPT_EXTERN(nlopt_result) nlopt_set_population(nlopt_opt opt, unsigned pop);
 NLOPT_EXTERN(unsigned) nlopt_get_population(const nlopt_opt opt);
 
+NLOPT_EXTERN(nlopt_result) nlopt_set_subspace_dim(nlopt_opt opt, unsigned dim);
+NLOPT_EXTERN(unsigned) nlopt_get_subspace_dim(const nlopt_opt opt);
+
 NLOPT_EXTERN(nlopt_result) nlopt_set_default_initial_step(nlopt_opt opt, 
                                                         const double *x);
 NLOPT_EXTERN(nlopt_result) nlopt_set_initial_step(nlopt_opt opt, 
index 25e08527783dd4ed29998d5b04c801e78e036bc7..8c8612c3cdd86da6f9ac8d1673d07b45fc8038c2 100644 (file)
@@ -349,18 +349,21 @@ static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
 #endif
 
         case NLOPT_LD_LBFGS: 
-             return luksan_plis(ni, f, f_data, lb, ub, x, minf, &stop);
+             return luksan_plis(ni, f, f_data, lb, ub, x, minf, 
+                                &stop, opt->subspace_dim);
 
         case NLOPT_LD_VAR1: 
         case NLOPT_LD_VAR2: 
-             return luksan_plip(ni, f, f_data, lb, ub, x, minf, &stop,
-                  algorithm == NLOPT_LD_VAR1 ? 1 : 2);
+             return luksan_plip(ni, f, f_data, lb, ub, x, minf, 
+                                &stop, opt->subspace_dim,
+                                algorithm == NLOPT_LD_VAR1 ? 1 : 2);
 
         case NLOPT_LD_TNEWTON: 
         case NLOPT_LD_TNEWTON_RESTART: 
         case NLOPT_LD_TNEWTON_PRECOND: 
         case NLOPT_LD_TNEWTON_PRECOND_RESTART: 
-             return luksan_pnet(ni, f, f_data, lb, ub, x, minf, &stop,
+             return luksan_pnet(ni, f, f_data, lb, ub, x, minf,
+                                &stop, opt->subspace_dim,
                                 1 + (algorithm - NLOPT_LD_TNEWTON) % 2,
                                 1 + (algorithm - NLOPT_LD_TNEWTON) / 2);
 
index 3749b7bcbac60a6bcc3e083e2d9fb02e44dac57c..19df40dc486c95e6ea71e330302751d5001fe8dd 100644 (file)
@@ -88,6 +88,7 @@ nlopt_opt NLOPT_STDCALL nlopt_create(nlopt_algorithm algorithm, unsigned n)
 
          opt->local_opt = NULL;
          opt->stochastic_population = 0;
+         opt->subspace_dim = 0;
          opt->dx = NULL;
          opt->work = NULL;
 
@@ -588,6 +589,7 @@ NLOPT_STDCALL nlopt_set_local_optimizer(nlopt_opt opt,
 /*************************************************************************/
 
 GETSET(population, unsigned, stochastic_population)
+GETSET(subspace_dim, unsigned, subspace_dim)
 
 /*************************************************************************/
 
index 9e375577a71e7527b1d3d4754fc9824099145e75..66b9281b5bb4c5ea06d1589e61b6d14970026632 100644 (file)
@@ -13,13 +13,15 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
                   const double *lb, const double *ub, /* bounds */
                   double *x, /* in: initial guess, out: minimizer */
                   double *minf,
-                  nlopt_stopping *stop);
+                 nlopt_stopping *stop,
+                        int mf);
 
 nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
                         const double *lb, const double *ub, /* bounds */
                         double *x, /* in: initial guess, out: minimizer */
                         double *minf,
                         nlopt_stopping *stop,
+                        int mf,
                         int method);
 
 nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
@@ -27,6 +29,7 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
                         double *x, /* in: initial guess, out: minimizer */
                         double *minf, 
                         nlopt_stopping *stop,
+                        int mf,
                         int mos1, int mos2);
 
 /*****************************  internal routines *************************/
index 7d4e59990ec518aafa482393e7eac3a8582a8f3e..2527dde85e79d9b91c3a8139a6301c7783c78bb7 100644 (file)
@@ -427,6 +427,7 @@ nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
                         double *x, /* in: initial guess, out: minimizer */
                         double *minf,
                         nlopt_stopping *stop,
+                        int mf, /* subspace dimension (0 for default) */
                         int method) /* 1 or 2, see below */
 {
      int i, *ix, nb = 1;
@@ -439,7 +440,6 @@ nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
      int mfv = stop->maxeval;
      stat_common stat;
      int iterm;
-     int mf;
 
      ix = (int*) malloc(sizeof(int) * n);
      if (!ix) return NLOPT_OUT_OF_MEMORY;
@@ -451,9 +451,11 @@ nlopt_result luksan_plip(int n, nlopt_func f, void *f_data,
        and we'll assume that the main limiting factor is the memory.
        We'll assume that at least MEMAVAIL memory, or 4*n memory, whichever
        is bigger, is available. */
-     mf = MAX2(MEMAVAIL/n, 4);
-     if (stop->maxeval && stop->maxeval <= mf)
-         mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     if (mf <= 0) {
+         mf = MAX2(MEMAVAIL/n, 4);
+         if (stop->maxeval && stop->maxeval <= mf)
+              mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     }
 
  retry_alloc:
      work = (double*) malloc(sizeof(double) * (n * 7 + MAX2(n,n*mf) + 
index 03552f0413e7d96b59e807aa05686dede7d81b32..e3bcde3d94431c445c0c3fb43cb93bd32e7c6361 100644 (file)
@@ -422,7 +422,8 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
                  const double *lb, const double *ub, /* bounds */
                  double *x, /* in: initial guess, out: minimizer */
                  double *minf,
-                 nlopt_stopping *stop)
+                 nlopt_stopping *stop,
+                        int mf) /* subspace dimension, 0 for default */
 {
      int i, *ix, nb = 1;
      double *work, *xl, *xu, *xo, *gf, *s, *go, *uo, *vo;
@@ -434,7 +435,6 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
      int mfv = stop->maxeval;
      stat_common stat;
      int iterm;
-     int mf;
 
      ix = (int*) malloc(sizeof(int) * n);
      if (!ix) return NLOPT_OUT_OF_MEMORY;
@@ -446,9 +446,11 @@ nlopt_result luksan_plis(int n, nlopt_func f, void *f_data,
        and we'll assume that the main limiting factor is the memory.
        We'll assume that at least MEMAVAIL memory, or 4*n memory, whichever
        is bigger, is available. */
-     mf = MAX2(MEMAVAIL/n, 4);
-     if (stop->maxeval && stop->maxeval <= mf)
-         mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     if (mf <= 0) {
+         mf = MAX2(MEMAVAIL/n, 4);
+         if (stop->maxeval && stop->maxeval <= mf)
+              mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     }
 
  retry_alloc:
      work = (double*) malloc(sizeof(double) * (n * 4 + MAX2(n,n*mf)*2 + 
index ac009c74847828c68712a4d36b5f974776e60d29..d8d7ac80e11b6c7e4ceb17fc034dda4261c0fc3f 100644 (file)
@@ -569,6 +569,7 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
                         double *x, /* in: initial guess, out: minimizer */
                         double *minf, 
                         nlopt_stopping *stop,
+                        int mf, /* subspace dimension (0 for default) */
                         int mos1, int mos2) /* 1 or 2 */
 {
      int i, *ix, nb = 1;
@@ -582,7 +583,6 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
      int mfv = stop->maxeval;
      stat_common stat;
      int iterm;
-     int mf;
 
      ix = (int*) malloc(sizeof(int) * n);
      if (!ix) return NLOPT_OUT_OF_MEMORY;
@@ -594,9 +594,11 @@ nlopt_result luksan_pnet(int n, nlopt_func f, void *f_data,
        and we'll assume that the main limiting factor is the memory.
        We'll assume that at least MEMAVAIL memory, or 4*n memory, whichever
        is bigger, is available. */
-     mf = MAX2(MEMAVAIL/n, 4);
-     if (stop->maxeval && stop->maxeval <= mf)
-         mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     if (mf <= 0) {
+         mf = MAX2(MEMAVAIL/n, 4);
+         if (stop->maxeval && stop->maxeval <= mf)
+              mf = MAX2(stop->maxeval - 5, 1); /* mf > maxeval seems not good */
+     }
 
  retry_alloc:
      work = (double*) malloc(sizeof(double) * (n * 9 + MAX2(n,n*mf)*2 + 
index 56ca0d98164b82e3d682ac3051646d63e7206a77..40af9011fe892fd8d55b580c450d7eec5e229ccb 100644 (file)
@@ -151,6 +151,7 @@ nlopt_opt make_opt(const mxArray *opts, unsigned n)
      nlopt_set_maxtime(opt, struct_val_default(opts, "maxtime", 0.0));
 
      nlopt_set_population(opt, struct_val_default(opts, "population", 0));
+     nlopt_set_subspace_dim(opt, struct_val_default(opts, "subspace_dim", 0));
 
      if (struct_arrval(opts, "initial_step", n, NULL))
          nlopt_set_initial_step(opt,
index f5b1dd62eca258b4f156cb657ce3ce8149d4eee5..9e11c4995dc505adebd0952e6b0235a97edfc481 100644 (file)
@@ -177,6 +177,7 @@ nlopt_opt make_opt(Octave_map &opts, int n)
   nlopt_set_maxtime(opt, struct_val_default(opts, "maxtime", 0.0));
 
   nlopt_set_population(opt, struct_val_default(opts, "population", 0));
+  nlopt_set_subspace_dim(opt, struct_val_default(opts, "subspace_dim", 0));
 
   if (opts.contains("initial_step")) {
     Matrix zeros(1, n, 0.0);
index 0eb1942e06c45a84a42406c9a95ecb12bf72bffb..6dac57a6d4a317784abce9757a1d204eadb4a822 100644 (file)
@@ -61,7 +61,8 @@ GETSET_EXCEPT(force_stop, int)
 
 %catches(std::bad_alloc,std::invalid_argument) nlopt::opt::set_local_optimizer(const opt &lo);
 
-GETSET_EXCEPT(local_population, unsigned)
+GETSET_EXCEPT(population, unsigned)
+GETSET_EXCEPT(subspace_dim, unsigned)
 GETSETVEC_EXCEPT(initial_step)
 
 %catches(std::bad_alloc,std::invalid_argument) nlopt::opt::set_default_initial_step(const std::vector<double> &x);