chiark / gitweb /
added verbose mode to Octave/Matlab plugin, for convenience
authorstevenj <stevenj@alum.mit.edu>
Sun, 9 Sep 2007 01:24:01 +0000 (21:24 -0400)
committerstevenj <stevenj@alum.mit.edu>
Sun, 9 Sep 2007 01:24:01 +0000 (21:24 -0400)
darcs-hash:20070909012401-c8de0-02cf1c2c437a62a20ce7bdd0950499e4c6b19ba6.gz

octave/nlopt_minimize-mex.c
octave/nlopt_minimize-oct.cc
octave/nlopt_minimize.m

index 1d9a6000896f92de8ab2d50b26f2fdd53d786f24..68696f6127a203746b31d56aeea038c4db9bf0e3 100644 (file)
@@ -31,6 +31,7 @@ typedef struct {
      mxArray *plhs[2];
      mxArray *prhs[MAXRHS];
      int xrhs, nrhs;
+     int verbose, neval;
 } user_function_data;
 
 static double user_function(int n, const double *x,
@@ -60,6 +61,8 @@ static double user_function(int n, const double *x,
      memcpy(gradient, mxGetPr(d->plhs[1]), n * sizeof(double));
      mxDestroyArray(d->plhs[1]);
   }
+  d->neval++;
+  if (d->verbose) mexPrintf("nlopt_minimize eval #%d: %g\n", d->neval, f);
   return f;
 }                               
 
@@ -139,6 +142,8 @@ void mexFunction(int nlhs, mxArray *plhs[],
      xtol_rel = struct_val_default(prhs[6], "xtol_rel", 0);
      maxeval = (int) (struct_val_default(prhs[6], "maxeval", -1) + 0.5);
      maxtime = struct_val_default(prhs[6], "maxtime", -1);
+     d.verbose = (int) struct_val_default(prhs[6], "verbose", 0);
+     d.neval = 0;
      {
          mxArray *val = mxGetField(prhs[6], 0, "xtol_abs");
          if (val) {
index 678c74db3fe61dd6f0c9e26728e7031064431217..3c9a4efc72cccee59e8c10d74846dad51b22dbc1 100644 (file)
@@ -34,6 +34,7 @@ static Matrix struct_val_default(Octave_map &m, const std::string& k,
 typedef struct {
   octave_function *f;
   Cell f_data;
+  int neval, verbose;
 } user_function_data;
 
 static double user_function(int n, const double *x,
@@ -65,6 +66,9 @@ static double user_function(int n, const double *x,
          gradient[i] = grad(i);
       }
     }
+    data->neval++;
+    if (data->verbose) printf("nlopt_minimize eval #%d: %g\n", 
+                             data->neval, res(0).double_value());
     return res(0).double_value();
   }
   return 0;
index 68fec7530c5a17a08adfe749c777791d650b93b5..43f69750d6dc6296287a0462077e65c7363b25a7 100644 (file)
@@ -39,6 +39,7 @@
 %     stop.fmin_max = stop when f < fmin_max is found
 %     stop.maxeval = maximum number of function evaluations
 %     stop.maxtime = maximum run time in seconds
+%     stop.verbose = > 0 indicates verbose output
 % Minimization stops when any one of these conditions is met; any
 % condition that is omitted from stop will be ignored.  WARNING:
 % not all algorithms interpret the stopping criteria in exactly the