Syntax:

-nonlinfit function paramlist ["linfit" linfitparams] ["errors" error_expr] ["covariance" < "squareexp" amp_var rho_var | "exp" amp_var rho_var | "matern" amp_var rho_var nu_var>] ["priors" priorlist] ["constraints" constraintlist] < "amoeba" ["tolerance" tol] ["maxsteps" steps] | "mcmc" ["Naccept" N | "Nlinkstotal" N] ["fracburnin" frac] ["eps" eps] ["skipamoeba"] ["chainstats" exprlist statslist] ["maxmemstore" maxmem] ["outchains" outdir ["format" format] ["printevery" N]] > ["modelvar" varname] ["correctlc"] ["omodel" model_outdir ["format" nameformat]]

Example 1.
./vartools -i EXAMPLES/3 \
    -stats t min,max \
    -expr t1=STATS_t_MIN_0 \
    -expr 'Dt=(STATS_t_MAX_0-STATS_t_MIN_0)' \
    -expr 'mag=mag+0.1*exp(-0.5*((t-(t1+Dt*0.2))/(Dt*0.05))^2)' \
    -nonlinfit 'a+b*exp(-(t-c)^2/(2*d^2))' \
        'c=(t1+Dt*0.3):(0.1*Dt),d=(Dt*0.1):(0.1*Dt)' \
        linfit a,b amoeba omodel EXAMPLES/OUTDIR1/ \
    -oneline

Name                     = EXAMPLES/3
STATS_t_MIN_0            = 53725.173920000001
STATS_t_MAX_0            = 53756.281021000003
Nonlinfit_HasConverged_4 = 1
Nonlinfit_c_BestFit_4    = 53731.405628420733
Nonlinfit_c_Err_4        = 0.00090197861656010614
Nonlinfit_d_BestFit_4    = 1.4997722086319381
Nonlinfit_d_Err_4        = 0.0011353562531547948
Nonlinfit_a_BestFit_4    = 10.167328282857785
Nonlinfit_a_Err_4        = 1.7957444863607521e-05
Nonlinfit_b_BestFit_4    = 0.10065045055297883
Nonlinfit_b_Err_4        = 4.8262250106865319e-05
Nonlinfit_BestFit_Chi2_4 = 90077.830712742856

Add a Gaussian function to a light curve (done with the third '-expr' call), and then fit a Gaussian to the light curve using the -nonlinfit command. We first determine the minimum and maximum time values using the -stats commands. The parameters of the injected Gaussian (the peak time, and the standard deviation) are then given in terms of these parameters. For the -nonlinfit command we fit a function of the form 'a+b*exp(-(t-c)^2/(2*d^2))' with the free parameters being a, b, c and d. Two of these parameters, c and d, enter in a nonlinear way into the function and thus must be varied using a nonlinear fitting algorithm. After the function we list these two nonlinear parameters, together with initial guesses for the optimal values and initial step-sizes to use in the search. For 'c' the initial value is '(t1+Dt*0.3)' while the step-size is '(0.1*Dt)'. For 'd' the initial value is '(Dt*0.1)' with a step-size of '(0.1*Dt)'. Obviously for this artificial example we could have simply set the initial values to the values used in creating the artificial signal, but we choose slightly different values to illustrate the search procedure. Because the parameters 'a' and 'b' enter linearly into the model, we can optimize these parameters using linear least squares. We do this by giving the 'linfit' keyword and then listing the two parameters. Note that we could also have varied all four parameters a,b,c,d through the non-linear algorithm (in which case we would need to provide initial guesses and step-sizes for a and b on the non-linear parameter string, and we would not provide the 'linfit' keyword or the parameter string following it). We use the 'amoeba' algorithm to perform the non-linear search. This is an implementation of the downhill simplex method, a greedy optimization algorithm which will find a local χ² minimum that is close to the initial starting values. We output the model to the directory 'EXAMPLES/OUTDIR1'. In this case the model will be in the file 'EXAMPLES/OUTDIR1/3.nonlinfit.model'.

Example 2.
./vartools -i EXAMPLES/3 \
    -stats t min,max \
    -expr t1=STATS_t_MIN_0 \
    -expr 'Dt=(STATS_t_MAX_0-STATS_t_MIN_0)' \
    -expr 'mag=mag+0.1*exp(-0.5*((t-(t1+Dt*0.2))/(Dt*0.05))^2)' \
    -nonlinfit 'a+b*exp(-(t-c)^2/(2*d^2))' \
        'a=10.167:0.0002,b=0.1:0.0008,c=(t1+Dt*0.2):(0.005),d=(Dt*0.05):(0.016)' \
        mcmc Nlinkstotal 10000 outchains EXAMPLES/OUTDIR1/ \
    -oneline

Name                     = EXAMPLES/3
STATS_t_MIN_0            = 53725.173920000001
STATS_t_MAX_0            = 53756.281021000003
Nonlinfit_a_BestFit_4    = 10.16733595824326
Nonlinfit_b_BestFit_4    = 0.10068199797234947
Nonlinfit_c_BestFit_4    = 53731.405627923843
Nonlinfit_d_BestFit_4    = 1.4997732382607727
Nonlinfit_BestFit_Chi2_4 = 90077.83071503813
Nonlinfit_a_MEDIAN_4     = 10.167339206527549
Nonlinfit_a_STDDEV_4     = 2.1634712351800478e-05
Nonlinfit_b_MEDIAN_4     = 0.10071313795015273
Nonlinfit_b_STDDEV_4     = 7.5501039462404719e-05
Nonlinfit_c_MEDIAN_4     = 53731.40592424116
Nonlinfit_c_STDDEV_4     = 0.0010974050260291169
Nonlinfit_d_MEDIAN_4     = 1.4987003116627102
Nonlinfit_d_STDDEV_4     = 0.001632159684888244

Similar to Example 1, in this case we use an MCMC procedure to explore the χ² landscape. We will run a total of 10000 links in the MCMC chain, and output the chain to the directory EXAMPLES/OUTDIR1. The file will be EXAMPLES/OUTDIR1/3.mcmc in this case.