Fitting Utility API¶
LMFIT supplement functions¶
- mrsimulator.utils.spectral_fitting.make_LMFIT_params(sim: Simulator = Simulator(name=None, description=None, label=None, property_units={}, spin_systems=[], spin_system_models=[], methods=[], config=ConfigSimulator(name=None, description=None, label=None, property_units={}, number_of_sidebands=64, number_of_gamma_angles=1, integration_volume='octant', integration_density=70, decompose_spectrum='none', isotropic_interpolation='linear', custom_sampling=None, is_complex=True)), processors: Optional[list] = None, spin_system_models: list = [], include={})¶
Parse the Simulator and PostSimulator objects for a list of LMFIT parameters.
- Parameters:
sim (Simulator) – Simulator object.
processors (list) – List of SignalProcessor objects. The order must match the order of methods within the simulator object.
include (set) – Set of keywords from the method object to include as a fitting parameter. Default is {}.
The parameter name associated with the spin system within the Simulator object is generated using the following nomenclature- sys_i_site_j_attribute1_attribute2 for attribute with signature
sim.spin_systems[i].sites[j].attribute1.attribute2
Here, sys_i refers to the spin system at index i, site_j refers to the site at index j within the :math:i^text{th} spin system, and attribute1 and attribute2 are the site attributes.
For examples:
sim.spin_systems[1].sites[0].isotropic_chemical_shift
parametrizes to sys_1_site_0_isotropic_chemical_shift whilesim.spin_systems[0].sites[1].quadrupolar.Cq
to sys_0_site_1_quadrupolar_Cq.- Returns:
LMFIT Parameters object.
- mrsimulator.utils.spectral_fitting.LMFIT_min_function(params: Parameters, sim: Simulator, processors: Optional[list] = None, sigma: Optional[list] = None, **sim_kwargs)¶
The simulation routine to calculate the vector difference between simulation and experiment based on the parameters update.
- Parameters:
params – Parameters object containing parameters for OLS minimization.
sim – Simulator object.
processors – A list of :py:class:~`mrsimulator.signal_processor.Processor` objects to apply post-simulation processing to the simulated spectra.
sigma – A list of standard deviations corresponding to the experiments in the :py:attr:~`mrsimulator.Simulator.methods` attribute.
sim_kwargs – Keyword arguments to pass to the :py:mth:~`mrsimulator.Simulator.run()` method.
- Returns:
Array of the differences between the simulation and the experimental datasets.
- mrsimulator.utils.spectral_fitting.bestfit(sim: Simulator, processors: Optional[list] = None)¶
Return a list of best-fit spectrum ordered relative to the methods in the simulator object.
- Parameters:
sim (Simulator) – The simulator object.
processors (list) – List of SignalProcessor objects ordered according to the methods in the simulator object.
- mrsimulator.utils.spectral_fitting.residuals(sim: Simulator, processors: Optional[list] = None)¶
Return a list of residuals corresponding to the best-fit spectrum. The list is based on the order of methods in the simulator object.
- Parameters:
sim (Simulator) – The simulator object.
processors (list) – List of SignalProcessor objects ordered according to the methods in the simulator object.