A Closer Look at the Controls Class#
We have already seen in previous sections that once the problem has been defined in the projectClass, it is necessary to define a controls class which, as its name suggests, tells RAT what we want to do with the project.
Making an instance of the controls class is quite simple:-
controls = controlsClass();
controls = RAT.Controls()
This then creates an instance of controls class with a number of options defined:
controlsClass with properties:
parallel: 'single'
procedure: 'calculate'
calcSldDuringFit: 0
display: 'iter'
resampleMinAngle: 0.9000
resampleNPoints: 50
+------------------+-----------+
| Property | Value |
+------------------+-----------+
| procedure | calculate |
| parallel | single |
| calcSldDuringFit | False |
| resampleMinAngle | 0.9 |
| resampleNPoints | 50 |
| display | iter |
+------------------+-----------+
We will look at each of these in more detail below. Note that the options that are visible depend on the algorithm selected. So, at the moment the controls are set to ‘calculate’, which will simply calculate the reflectivity and SLD with any associated problem. If we select ‘simplex’ as the algorithm, a different set of options appears:-
controls.procedure = 'simplex';
controls = RAT.Controls(procedure='simplex')
controlsClass with properties:
parallel: 'single'
procedure: 'simplex'
calcSldDuringFit: 0
display: 'iter'
xTolerance: 1.0000e-06
funcTolerance: 1.0000e-06
maxFuncEvals: 10000
maxIterations: 1000
updateFreq: 1
updatePlotFreq: 20
resampleMinAngle: 0.9000
resampleNPoints: 50
+------------------+---------+
| Property | Value |
+------------------+---------+
| procedure | simplex |
| parallel | single |
| calcSldDuringFit | False |
| resampleMinAngle | 0.9 |
| resampleNPoints | 50 |
| display | iter |
| xTolerance | 1e-06 |
| funcTolerance | 1e-06 |
| maxFuncEvals | 10000 |
| maxIterations | 1000 |
| updateFreq | 1 |
| updatePlotFreq | 20 |
+------------------+---------+
which allow the user to set things such as tolerance targets and so on. There is a different set of options for each algorithm. We will now look at each of the available options in turn.
General parameters for the controls class#
These are the general parameters for the controls class. For algorithm-specific parameters see the page for each algorithm in the algorithms section.
procedure
#
Which algorithm RAT should run. Currently the options are:
"calculate"
: A simple Abelès calculation of reflectivity for the model, with chi-squared fit calculated between the model and the data."simplex"
: Optimisation via the Nelder-Mead simplex method."de"
: Optimisation via differential evolution."ns"
: Bayesian optimisation via nested sampling."dream"
: Bayesian optimisation via the DREAM algorithm.
parallel
#
How the calculation should be parallelised. Currently the options are:
"single"
: do not parallelise."contrasts"
: each contrast gets its own calculation thread."points"
: each contrast is split into a number of sections, and each section gets its own calculation thread.
Which option is more efficient will depend on the number of contrasts and the size of your data.
calcSldDuringFit
#
A boolean (true or false) value which determines whether SLD will be calculated during the fit (for live plotting etc.)
display
#
How much RAT should print to the terminal. The current options are:
"off"
: No display."iter"
: Give information after every iteration for iterative algorithms."notify"
:"final"
: Just provide information when the calculation has finished.
Resampling parameters (resampleMinAngle
and resampleNPoints
)#
The two parameters resampleMinAngle
and resampleNPoints
decide how
adaptive resampling will be used on the SLD profiles.
See the resampling page for more details. In short:
resampleMinAngle
: For each data point, the algorithm draws two lines from that data point to its neighbouring points on either side. If the angle between those lines is smaller thanresampleMinAngle
, then the algorithm will refine over that point.In practice, this means that resampling happens for points which are significantly higher or lower than their neighbours (i.e. the gradient of the function has changed rapidly) and
resampleMinAngle
controls the sensitivity of this.resampleMinAngle
is defined in the units of ‘radians divided by pi’, i.e.resampleMinAngle = 0.9
refines where the adjacent points form an angle smaller than \(0.9 \pi\) radians.resampleNPoints
: The initial number of domain points (layers) sampled by the algorithm at the start.