garefl - Adaptor for garefl models


Load garefl models into refl1d.

The models themselves don’t need to be modified. See the garefl documentation for setting up the model.

One extension provided to refl1d that is not available in garefl is the use of penalty values in the constraints. The model constraints is able to set:

fit[0].penalty = FIT_REJECT_PENALTY + distance

Here, distance is the distance to the valid region of the search space so that any fitter that gets lost in a penalty region can more quickly return to the valid region. Any penalty value above FIT_REJECT_PENALTY will suppress the evaluation of the model at that point during the fit.

Consider a model with layers (Si | Au | FeNi | air) and the constraint that d_Au + d_FeNi < 200 A. The constraints function would be written something like:

double excess = fit[0].m.d[1] + fit[0].m.d[2] - 200;
fit[0].penalty = excess > 0 ? excess*excess+FIT_REJECT_PENALTY : 0.;

Then, if the fit algorithm proposes a value such as Au=125, FeNi=90, the excess will be 15, and the penalty will be FIT_REJECT_PENALTY+225.

You can use penalties less than FIT_REJECT_PENALTY, but these should correspond to the negative log likelihood of seeing that constraint value within the model in order for the MCMC uncertainty analysis to work correctly. FIT_REJECT_PENALTY is set to 1e6, which should be high enough that it doesn’t perturb the fit.