Fitter

This is the handle class definition.

class @LocMoFit.LocMoFit(varargin)

Bases: matlab.mixin.Copyable

This is the class for fitting a set of geometric models to SMLM data.

This class help user to set up and handle the model fitting.

If you would like to perform multi-step fitting, please create one SMLMModelFit object for each step.

Copy right:

Yu-Le Wu, 2022

License:

GPLv3

Version:

1.0.1

Pleas cite:

Wu, Y.-L. et al. Maximum-likelihood model fitting for quantitative analysis of SMLM data. 2021.08.30.456756. bioRxiv (2021) doi:10.1101/2021.08.30.456756.

Last update:

25.07.2022

dimension = None

??? The dimension of the data.

allParsArg = None

All arguments of the parameters.

parsInit = None

???

fitInfo = None

Additional information acquired by fitting.

externalInfo = '[]'

External info, which were not acquired by the fit but rather used for alignment or so.

model = None

The model objects.

solver = None

The solver options.

converterRules = None

The defined conversion rules.

converterUserDefined = None

The temporary variables that the user defined.

roiSize = '300'

The size of region of interest in unit of nm.

imgExtension = '0'

The extention of image size than the roi size.

dataDim = '3'

The dimension of the data.

allModelLayer = None

The unique numbers of layers used by models.

modelLayer = None

The layer for the corresponding model.

modelVerCascade = '1'

For locs model only. Allow the user to specify different versions of the same model for different cascade steps.

refPoint_spacing = '0.75'

The spacing bwteen sampled ref points. In the unit of sigma.

numOfLocsPerLayer = None

The numbers of localizations per layer.

representiveLocprec = None

The representative localization precision.

display = None

Settings for displaying figures.

lutLayer = "'likelihood'"

The type of the objective function.

compensationFactor = '1'

The weights of layers.

fitterInfo = "'finished'"

can be ‘initial’, ‘iterative’ or ‘finished’

advanceSetting = None

Advanced settings are defined here.

linkedGUI = None

If GUI is used, it will be saved here.

converterSource = None

The information source for the converter.

locs = None

the current parameters of the model being evaluated.

handles = None

handles to graphic objects

temp = None

all temp info is saved here.

numOfModel = None

The number of models used in this fitting step.

numOfLayer = None

The number of layers.

roiAreaVol = None

The area/volume of the roi;

sigmaCascade = None

The sigma factor for each step of the sequential cascade fit.

LocMoFit(varargin)

Construct the object of the class ‘LocMoFit’

Usage:

obj = LocMoFit(Name-value)

Parameters

pairs (Name-value) –

  • ‘SolverName’: one of ‘fmincon’, ‘fminsearchbnd’, and ‘particleswarm’.

  • ’SolverOptions’:

  • ’DataDim’:

  • ’TestLocs’:

Returns

obj – an LocMoFit object.

Note

Please create an LocMoFit object for each step of fitting.

See also

setModel()

setModel(model, modelId)

Setting one single model of the LocMoFit object according to the modelId. Initiation of all arguments of the parameters (allParsArg).

Usage:

setModel(obj,model,modelId)

Parameters
  • obj – an LocMoFit object.

  • model – an SMLMModel object or sub-object.

  • modelId – the ID of the model being added.

addModel(model)

Add a specified model to the end of the list of models.

Usage:

addModel(obj,model)

Parameters
  • obj – an LocMoFit object.

  • model – an SMLMModel object or sub-object.

changeModel(newModel, modelNumber)

Remove the old corresponding parameters and add a new model to overwrite the old model with the same ID.

Usage:

changeModel(obj, newModel, modelNumber)

Parameters
  • obj – an LocMoFit object.

  • newModel – an SMLMModel object or sub-object being added.

  • modelNumberRemove – the ID of the model being added.

rmLastModel()

Remove the last model (in terms of the order).

Usage:

rmLastModel(obj)

Parameters

obj – an LocMoFit object.

updateModel(modelNumber)

Respond to the change of any internal setting of the geometric model.

getImage(modelNumber, varargin)

Get an image of the specified model at the best parameters.

updateLayer()

Manage layer-dependent offsets.

prepFit()

Reshape arguments of fit pars: lb, ub, init(value), and min/max

viewPars()

Display the parsArg as a table.

exportPars(modelID, type)

Get parameters for a specific model.

— Syntax — pars = exportPars(obj, modelID, type)

— Description — pars: a structral array with parameter names as field names. obj: an LocMoFit object. modelID: the ID of the model where you want to get parameters. type: either ‘lPar’, ‘mPar’ or ‘allPar’, specifying the type of parameters you want to get.

wherePar(parId)

[Replaced] see getVariable(). 200731: this function has been replaced getVariable().

getVariable(ID)

Search for a variable in which info is potentially stored and report its location and value. ID shold look like par.m1.lPar.x or directly the variable name.

setParArg(parId, varargin)

parId looks like this: ‘m1.lPar.x’, where m1 means model 1, and x can be any name of the parameters

addPar(parArg)

Add a parameter. Usage:

obj.addPar(parArg)

Arg:

*parArg: a cell in the order of ‘model’,’type’,’name’, ‘lb’,’ub’,’value’,’fix’,’label’,’min’ and ‘max’

rmPar(parId)

Remove a parameter

getAllParId(modelnumber, varargin)

Export Id for all parameters given a model number Show all parId when modelnumber is not specified.

Usage:

[parId,subParsArgTemp] = obj.getAllParId(modelnumber, varargin)

Parameters
  • modelnumber – an LocMoFit object.

  • pairs (Name-value) – ‘form’: either ‘short’, ‘long’, ‘auxiliary’

Returns

modCoord – reference coordinates.

convert2InteralLPar(lPars)

TODO: define the conversion for lPars in the furture Now this is just a placeholder

convert2InteralOffset(offset)

This function converts any valid offset to the interanl offset (weight)

getBGDensity()

density here is defined as the projected density. this unit is locs/um^2

convertBG(queriedForm, layer, val)

convert from one parameterization to another.

getLocsInfo()

Get locs counts per layer

lParSelector(parameterType, parameterForm)

Defines the form of parameters to be used It reacts when a certain form of lPar is selected.

initLParSelector(modelnumber, isBackground)

Initiates the form of parameters to be used

matchAllPar(modelId, refObj, refModelId, varargin)

matchAllPar() matches the parameters with the same names.

Uasage:

obj.matchAllPar(refObj, modelId, except)

Parameters
  • obj (LocMoFit) – an object created by LocMoFit().

  • modelId (numeric scalar) – the model ID that identifies the target model.

  • refObj (LocMoFit) – an object created by LocMoFit(). The referece that the parameters matches

  • to.

  • refModelId (numeric scalar) – the model ID that identifies the reference model.

  • pairs (Name-value) –

    • except (character vector | cell array of character vectors): parameter IDs (parIds) of the parameters to exclude from the matching.

Returns

Nothing.

Last update:

03.05.2022

reactToSet_advanceSetting()

reactToSet_advanceSetting() defines how LoMoFit reacts when advanceSetting is set.

assignParsVal()

In the given range, assign values to the parameters randomly.

Usage:

obj.assignParsVal

Parameters

obj – an LocMoFit object.

Returns

Parameter values saved in obj.allParsArg.

getSimRef(varargin)

Get simulation reference based on the allArgVal.

Usage:

modCoord = obj.getSimRef(Name-value)

Parameters
  • obj – an LocMoFit object.

  • pairs (Name-value) –

    • ‘finalROISize’: the final ROI size for fitting. the

    ROI size for simulations is usually larger than this value to make sure the background fills everywhere. * ‘depth’: the final depth. This option determines the axial range of the background.

Returns

modCoord – reference coordinates.

getLLExpDist(n)

Get the labels of the model.

saveHandles(pard, tag)
if isempty(varargin) || rem(length(varargin),2)>0

error(‘Wrong pair(s) of field names and handles.’)

end fn = varargin(1:2:end); h = varargin(2:2:end); for k = 1:length(fn)

obj.handles.(fn{k}) = h{k};

end

loglikelihoodFun(fitPars, compensationFactor, locs, varargin)

loglikelihoodFun computes the log-likelihood value of the fit.

getOFLL(compensationFactor)

get overfitted log-likelihood

getDerivedPars(varargin)

Get derived parameters of all (default) or a specific model. :param obj: an LocMoFit object.

Returns:

getModelInternalSettingList(modelID)

Get the list of the internal settings’ name.

— Syntax — settings = getModelInternalSettingList(obj, modelInd).

— Description— settings: a list (string array) of the internal settings’ name. obj: an LocMoFit object. modelID: the ID of the model.

getAllModelInternalSetting()

Get the list of the internal settings’ name.

— Syntax — settings = getModelInternalSettingList(obj, modelInd).

— Description— settings: a list (string array) of the internal settings’ name. obj: an LocMoFit object. modelID: the ID of the model.

setAllModelInternalSetting(settings)

Get the list of the internal settings’ name.

— Syntax — settings = getModelInternalSettingList(obj, modelInd).

— Description— settings: a list (string array) of the internal settings’ name. obj: an LocMoFit object. modelID: the ID of the model.

setModelInternalSetting(modelInd, setting, value)

Set the value of a model internal settings.

getModelInternalSetting(modelInd, setting)

Get the value of a model internal settings.

updateVersion()

This function is for necessary updates. Structral changes leading to failed runs have to be fixed here.

@LocMoFit.fit(obj, locs, varargin)

FIT Perform fitting based on the option values fit() performs fitting based on the options.

Usage:

fit(obj, locs, varargin)

Parameters
  • obj – a SMLMModelFit object.

  • locs – a struct with fields of xnm, ynm, znm, locprecnm.

  • pairs (Name-value) – *’locs2’: a struct with fields of xnm, ynm, znm, locprecnm. This is the

second set of locs for particle fusion.