diff options
author | tlatorre <tlatorre@uchicago.edu> | 2018-08-31 11:51:42 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2018-08-31 11:51:42 -0500 |
commit | 7b7d0182d316d4ee2ec664b28d7da23e0210f3c3 (patch) | |
tree | 775a9883efe36e891b09352b512b5260d7bb5bda /src/fit.c | |
parent | a339a46fb952c13dbe4fe85e4bc5d81bf5948953 (diff) | |
download | sddm-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/fit.c')
-rw-r--r-- | src/fit.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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)); |