aboutsummaryrefslogtreecommitdiff
path: root/src/fit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fit.c')
-rw-r--r--src/fit.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/fit.c b/src/fit.c
index 5733ee8..a8af643 100644
--- a/src/fit.c
+++ b/src/fit.c
@@ -18,11 +18,12 @@
#define EV_RECORD 0x45562020 // 'EV ' (as written to ZDAB file)
+static size_t iter;
+
double nll(unsigned int n, const double *x, double *grad, void *params)
{
double T, theta, phi, t0;
double pos[3], dir[3];
- static size_t iter;
double fval;
double z1[1], z2[1];
struct timeval tv_start, tv_stop;
@@ -69,7 +70,7 @@ double nll(unsigned int n, const double *x, double *grad, void *params)
int fit_event(event *ev, double *xopt, double *fmin)
{
- double x[9], ss[9], lb[9], ub[9];
+ double x[9], ss[9], lb[9], ub[9], fval;
int rv;
nlopt_opt opt = nlopt_create(NLOPT_LN_BOBYQA, 9);
@@ -121,7 +122,13 @@ int fit_event(event *ev, double *xopt, double *fmin)
nlopt_set_initial_step(opt, ss);
- rv = nlopt_optimize(opt,x,fmin);
+ iter = 0;
+ rv = nlopt_optimize(opt,x,&fval);
+
+ do {
+ *fmin = fval;
+ rv = nlopt_optimize(opt,x,&fval);
+ } while (fabs(fval-*fmin) > 1e-9);
memcpy(xopt,x,sizeof(x));