void cmd_nlls() { Real *work, *y, *bounds, *covar, *p; int nQ = count_data(); int ndim = fit[0].pars.n; int i; /* Allocate storage: y, covar, bounds, p */ work = (Real *)malloc(sizeof(Real)*(nQ + ndim*ndim + 3*ndim)); assert(work != NULL); y = work; bounds = y + nQ; covar = bounds + 2*ndim; p = covar + ndim*ndim; write_pop(&set); /* In case fit crashes */ /* Record what we are doing */ if (parFD != NULL) { fprintf(parFD,"# %15d Starting Levenberg-Marquardt\n", GetGen(&set)); fflush(parFD); } /* Copy normalized data values */ copy_normalized_data(y); /* Set bounds */ for (i=0; i < ndim; i++) { bounds[i] = 0.; bounds[i+ndim] = 1.; } /* Get best into p */ pars_set(&fit[0].pars, bestpars); pars_get01(&fit[0].pars, p); /* Call nlls */ tic(); #if 1 box_nlls(step_nlls, ndim, nQ, fit, y, bounds, p, covar); #else nlls(step_nlls, ndim, nQ, fit, y, p, covar); #endif printf("Done LM\n");fflush(stdout); toc(); print_covar(ndim,covar); /* Record LM results */ log_best(); /* Inject new p into the GA */ setChromosome(&set, 0, p); /* Done */ free(work); }
void ex_set_pars(fitinfo fit[], const Real p[]) { pars_set(&fit[0].pars, p); }