ls_criterion#
- cbclib.bin.ls_criterion(x: numpy.ndarray, ij: numpy.ndarray, shape: Tuple[int, int], I0: numpy.ndarray, bgd: numpy.ndarray, xtal_bi: numpy.ndarray, prof: numpy.ndarray, fidxs: numpy.ndarray, idxs: numpy.ndarray, hkl_idxs: numpy.ndarray, oidxs: Optional[numpy.ndarray] = None, loss: str = 'l2', num_threads: int = 1)[source]#
Calculate the least-squares error between the measured intensities
I0and the modelled intenisty profiles of Bragg reflections.- Parameters
x (numpy.ndarray) – Current estimate of crystal structure factors and intercept values.
ij (numpy.ndarray) – Detector coordinates.
I0 (numpy.ndarray) – Measured diffracted signal.
bgd (numpy.ndarray) – Background level.
xtal_bi (numpy.ndarray) – Sample’s projection maps.
prof (numpy.ndarray) – Standard profiles.
fidxs (numpy.ndarray) – Frame indices.
idxs (numpy.ndarray) – Streak indices.
hkl_idxs (numpy.ndarray) – Set of indices that numerate different Bragg reflections.
oidxs (Optional[numpy.ndarray]) – Output criterion indices.
loss (str) –
Loss function used to calculate the MSE. The following keyword arguments are allowed:
l1: L1 loss (absolute) function.
l2 : L2 loss (squared) function.
Huber : Huber loss function.
num_threads (int) – Number of threads used in the calculations.
Notes
The intensity profile \(I_{hkl}(\mathbf{x})\) of a particular Bragg reflection captured on the detector is given by:
\[I_{hkl}(\mathbf{x}) = |q_{hkl}|^2 \chi(\mathbf{u}(\mathbf{x})) f^2_{hkl}(\mathbf{x})\]where \(q_{hkl}\) are the structure factors and \(\chi(\mathbf{u}(\mathbf{x}))\) are the projection maps of the sample, and \(f_{hkl}(\mathbf{x})\) are the standard reflection profiles.
The least squares criterion is given by:
\[\epsilon^{LS} = \sum_{ni} f\left( \frac{I_n(\mathbf{x}_i) - I_{hkl}(\mathbf{x}_i) - I_{bgd}}{\sigma_I^2} \right),\]where \(f(x)\) is either l2, l1, or Huber loss function, and \(\sigma_I\) is the standard deviation of measured photon counts for a given diffraction streak.
- Returns
The least squares criterion and gradient arrays.
- Return type
Tuple[numpy.ndarray, numpy.ndarray]