aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-08-31 11:51:42 -0500
committertlatorre <tlatorre@uchicago.edu>2018-08-31 11:51:42 -0500
commit7b7d0182d316d4ee2ec664b28d7da23e0210f3c3 (patch)
tree775a9883efe36e891b09352b512b5260d7bb5bda /src
parenta339a46fb952c13dbe4fe85e4bc5d81bf5948953 (diff)
downloadsddm-7b7d0182d316d4ee2ec664b28d7da23e0210f3c3.tar.gz
sddm-7b7d0182d316d4ee2ec664b28d7da23e0210f3c3.tar.bz2
sddm-7b7d0182d316d4ee2ec664b28d7da23e0210f3c3.zip
fit in a do while loop until the fit converges to the same likelihood value
Diffstat (limited to 'src')
-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));