MDMC.refinement.FoM package
Submodules
MDMC.refinement.FoM.ChiSquared_experror module
The class for Chi Squared figure of merit calculation with errors
- class MDMC.refinement.FoM.ChiSquared_experror.ChiSquaredExpError(obs_pairs: list[ObservablePair], norm: str = 'data_points', n_parameters: int = None)[source]
Bases:
FigureOfMeritCalculates the figure of merit as a sum of the square difference between data points for a single pair of observables, normalised by the errors and the number of data points, i.e. the reduced chi-squared.
Please see the documentation page explanation/figure-of-merit for mathematical details.
- calculate_single_FoM(obs_pair: ObservablePair)[source]
Calculates the chi-squared figure of merit for a single pair of observables, potentially rescaled if the experimental observable is not on an absolute scale.
- Parameters:
obs_pair (ObservablePair) – An
ObservablePairfor which the FoM is calculated- Returns:
The FoM for the obs_pair
- Return type:
MDMC.refinement.FoM.FoM_abs module
A module for Figure of Merits
- class MDMC.refinement.FoM.FoM_abs.FigureOfMerit(obs_pairs: list[ObservablePair], norm: str = 'data_points', n_parameters: int = None)[source]
Bases:
ABCAbstract class that defines methods common to all figure of merit calculators
- Parameters:
obs_pairs (list) – A list of
ObservablePairsnorm ({'data_points', 'dof', 'none'}, optional) – What method of normalisation to use when calculating the FoM for a single dataset. Default is ‘data_points’.
n_parameters (int, optional) – The number of parameters being refined. Optional if
normis either ‘data_points’ or ‘none’, but required when ‘dof’. Default is None.
- calculate() float[source]
Calculates the FoM value by calculating the FoM for every
ObservablePair- Returns:
A non-negative float Figure of Merit
- Return type:
- Raises:
ValueError – If calculated value of Figure of Merit is negative
- abstract calculate_single_FoM(obs_pair: ObservablePair) float[source]
Performs the FoM calculation specific to each FoM
- Parameters:
obs_pair (ObservablePair) – An
ObservablePairfor which the FoM is calculated- Returns:
The FoM for the
obs_pair- Return type:
- data_norm_factor(obs_pair: ObservablePair) int[source]
Calculates the normalisation factor for
obs_pair. Ifself.normis True, then returns the number of data points less the number of refinement parameters if ‘dof’ normalisation was chosen, or just the number of data points for the default ‘data_points’ normalisation. Ifself.normis False, then returns 1.- Parameters:
obs_pair (ObservablePair) – An
ObservablePairfor which the normalisation factor is calculated- Returns:
The normalisation factor
- Return type:
- class MDMC.refinement.FoM.FoM_abs.ObservablePair(exp_obs: Observable, MD_obs: Observable, weight: float, rescale_factor: float = 1.0, auto_scale: bool = False)[source]
Bases:
objectContains a pair of observables for calculating the FoM
Checks the validity of observables
- Parameters:
exp_obs (Observable) – An
ObservablewithObservable.origin == 'experiment'MD_obs (Observable) – An
ObservablewithObservable.origin == 'MD'weight (float) – The relative weight of this pair on a total FoM
rescale_factor (float, optional) – Factor applied to
exp_obswhen calculating the FoM to ensure it is on the same scale asMD_obs. Default is 1..auto_scale (bool, optional) – If True,
rescale_factoris set automatically to minimise the FoM for each step of the refinement, overriding a user specified value if set. Note that this process is purely statistical and does not account for physical effects that might impact the scaling. Default is False.
- property MD_obs: Observable
Get or set the MD
ObservableSetting the
Observablechecks its validity- Returns:
The MD
Observable- Return type:
- calculate_difference() ndarray[source]
Assumes a single dependent variable for each
Observable- Returns:
An array with the same dimensions as the
dependent_variablesof theexp_obsandMD_obs. The array contains the difference between thedependent_variablestaking therescale_factorinto account.- Return type:
- calculate_errors() ndarray[source]
Assumes a single dependent variable error for each
Observable- Returns:
An array with the same dimensions as the
errorsof theexp_obsandMD_obs. The array contains the combination of theerrorsin quadrature, taking therescale_factorinto account.- Return type:
- calculate_exp_errors() ndarray[source]
Assumes a single dependent variable error for each
Observable. Calculates only the experimental errors.- Returns:
An array with the same dimensions as the
errorsof theexp_obs, taking therescale_factorinto account.- Return type:
- check_dep_var() None[source]
Checks that
Observableobjects have the samedependent_variablesand that are finite
- check_errors() None[source]
Checks that an
Observablehas errors on thedependent_variableand that these are float and not NaN
- check_indep_var() None[source]
Checks that
Observableobjects have the sameindependent_variablesand that are finite
- check_origin(origin: str) None[source]
Checks that the
Observable.originis correct- Parameters:
origin (str) – A string consisting of either
'experiment'or'MD'
- property exp_obs: Observable
Get or set the experimental
ObservableSetting the
Observablechecks its validity- Returns:
The experimental
Observable- Return type:
- property n_averages: dict[str, int]
The number of separate, complete dependent variable calculations we have been able to perform for the
Observable- Returns:
Each key represents a dependent variable, and the value is the number of times we have calculated it
- Return type:
- validate_obs(obs: Observable, origin: str) None[source]
Performs checks to test the validity of an
ObservableTests that the
Observable.originis as expected. If theObservablePairhas anotherObservable(i.e. the otherorigin), then this tests that theindependent_variablesare identical, thedependent_variableshave the same shape, theerrorshave the same shape, and that theObservableobjects are of the same type.- Parameters:
obs (Observable) – The
Observableto validateorigin (str) – The
Observable.origin('experiment'or'MD')
- Raises:
AssertionError – If the
Observable.originis not the same as theoriginParameterAssertionError – If
Observabledoes not have identicalindependent_variablesto anyObservableof the otherObservable.originthat already exists in theObservablePairAssertionError – If
Observabledoes not have identicaldependent_variablesto anyObservableof the otherObservable.originthat already exists in theObservablePairAssertionError – If
Observabledoes not have identicalerrorsto anyObservableof the otherObservable.originthat already exists in theObservablePairAssertionError – If
Observabledoes not have identical type to anyObservableof the otherObservable.originthat already exists in theObservablePair
MDMC.refinement.FoM.FoM_factory module
Factory class for generating Figure of Merits And ObservablePair class fro defining the obseravble pairs used to calculate the Figure of Merit
- class MDMC.refinement.FoM.FoM_factory.FoMFactory[source]
Bases:
ModuleFactory[FigureOfMerit]Provides a factory for creating a
Figure of Meritalso called FoM.Any FoM within the FoM folder can be created with a string of the class name, as long as it is a subclass of
FigureOfMerit.- curr_path: Path = PosixPath('/home/runner/work/MDMCv0.2_pilot/MDMCv0.2_pilot/MDMC/refinement/FoM')
- exclude: Sequence[Path] = (PosixPath('/home/runner/work/MDMCv0.2_pilot/MDMCv0.2_pilot/MDMC/refinement/FoM/__init__.py'), PosixPath('/home/runner/work/MDMCv0.2_pilot/MDMCv0.2_pilot/MDMC/refinement/FoM/FoM_factory.py'))
- registry: dict[str, FigureOfMerit] = {'ChiSquaredExpError': <class 'MDMC.refinement.FoM.ChiSquared_experror.ChiSquaredExpError'>, 'ChiSquared_experror': <class 'MDMC.refinement.FoM.ChiSquared_experror.ChiSquaredExpError'>, 'RSquared_noneerror': <class 'MDMC.refinement.FoM.RSquared_noneerror.RSquared_noneerror'>, 'exp': <class 'MDMC.refinement.FoM.ChiSquared_experror.ChiSquaredExpError'>, 'none': <class 'MDMC.refinement.FoM.RSquared_noneerror.RSquared_noneerror'>}
MDMC.refinement.FoM.RSquared_noneerror module
The class for R Squared figure of merit calculation with no errors
- class MDMC.refinement.FoM.RSquared_noneerror.RSquared_noneerror(obs_pairs: list[ObservablePair], norm: str = 'data_points', n_parameters: int = None)[source]
Bases:
FigureOfMeritCalculates the weighted sum of the Figure of Merits for a number of datasets:
\[FoM_{total} = \frac{\sum_{i} FoM_{i}}{\sum_{i} w_{i}}\]Here the weighted Figure of Merit for the \(i\)-th dataset, \(FoM_{i}\), is given by the sum of the square difference between data points for a single
ObservablePair, i.e. the reduced chi-squared:\[FoM_{i} = \frac{w_{i}}{\nu_{i}} \sum_{j} (D_{j}^{exp} - D_{j}^{sim})^2\]where the sum is over the \(N_{i}\) data points in the
ObservablePaircorresponding to the \(i\)-th dataset, and the normalisation factor \(\nu_{i}\) is either \(N_{i}\), \(N_{i} - M\) where \(M\) is the number of fitting parameters, or \(1\). \(w_{i}\) is an importance weighting assigned to the \(i\)-th dataset. \(D_{j}\) are the individual data points in the 1-D or 2-D array of the experimentalObservable(\(exp\)) or simulatedObservable(\(sim\)). Note that the subtraction and division over the arrays are element-wise. Note also that if the experimentalObservableis not on an absolute scale, an additionalrescale_factorcan be specified (or automatically determined) by theObservablePairto scale the experimental data points and errors by a simple linear scaling.- calculate_single_FoM(obs_pair: ObservablePair)[source]
Performs the square difference for an
ObservablePairIfobs_pair.auto_scaleis True, then this will also setobs_pair.rescaleto the value which minimizes the FoM. If we labelrescale_factor\(=\lambda\) then the minimum of the FoM is obtained as:\[\begin{split}FoM_{i}(\lambda) &=& w_{i} \sum_{j} \left(\lambda*D_{j}^{exp} - D_{j}^{sim}\right)^2 \\\\ \left. \frac{dFoM_{i}}{d\lambda}\right|_{\lambda=\lambda_{min}} &=& 0 \\\\ \lambda_{min} &=& \frac{A}{B} \\\\\end{split}\]where we have:
\[\begin{split}A &=& \sum_{j} D_{j}^{exp}*D_{j}^{sim} \\\\ B &=& \sum_{j}\left(D_{j}^{exp}\right)^2\end{split}\]- Parameters:
obs_pair (ObservablePair) – An
ObservablePairfor which the FoM is calculated- Returns:
The FoM for the obs_pair
- Return type:
Module contents
A module for Figure of Merit calculation