Fitting - vanTeeffelenLab/ExTrack GitHub Wiki

Once they have been instanciated (see https://github.com/vanTeeffelenLab/ExTrack/wiki/Parameters-for-fitting), parameters can be fitted using extrack.tracking.param_fitting

Function extrack.tracking.param_fitting

model_fit = extrack.tracking.param_fitting(all_tracks,
                                           dt
                                           params = None,
                                           cell_dims = [100],
                                           nb_substeps = 1,
                                           nb_states = 2,
                                           frame_len = 4,
                                           verbose = 0,
                                           workers = 1,
                                           Matrix_type = 1,
                                           input_LocErr = None,
                                           method = 'powell',
                                           steady_state = False)

Arguments:

  • all_tracks: dictionary describing the tracks with track length as keys (number of time positions, e.g. '23') of 3D arrays: dim 0 = track, dim 1 = time position, dim 2 = x, y position. This means 15 tracks of 7 time points in 2D will correspond to an array of shape [15,7,2].
  • dt: time in between frames (s).
  • params: Parameters previously instanciated.
  • nb_states: number of states. estimated_vals, min_values, max_values should be changed accordingly to describe all states and transitions.
  • nb_substeps: number of considered transition steps in between consecutive 2 positions.
  • frame_len: number of frames for which the probability is perfectly computed. See method of the paper for more details.
  • verbose: if 1, print the intermediate values for each iteration of the fit.
  • steady_state: True if tracks are considered at steady state (fractions independent of time), this is most likely not true as tracks join and leave the FOV.
  • workers: number of workers used for the fitting, allows to speed up computation. Do not work from windows or Mac OS at the moment.
  • Matrix_type: return transitions rates assuming the following relationship between transition rate per time step k, transition probability p and number of sub-steps u: k = p if Matrix_type = 0, k = (1 - exp(-p * u))/u if Matrix_type = 1, using the generator matrix assumption if Matrix_type = 2.
  • cell_dims: dimension limits (um) (default [1], can also be [1,2] for instance).
  • input_LocErr: Must be None if fitting localization error. If the user aims to imput localization error infered from a prior method based of peak shape, input_LocErr must be a dictionary of same format than all_tracks (dict with number of time positions as keys (ex. '23') of 3D arrays: dim 0 = track, dim 1 = time step, dim 2 = spatial dimensions). input_LocErr can be extracted from tables/csv or trackmate xml files just like all_tracks using the readers functions (see https://github.com/vanTeeffelenLab/ExTrack/wiki/Loading-data-sets).

Outputs:

  • model_fit: lmfit model

model_fit has the class MinimizerResult from the package lmfit (see https://github.com/lmfit/lmfit-py fro more details)

model_fit has interesting attributes:

  • model_fit.params: the most likely set of parameters found by the fitting method.
  • model_fit.residual: the likelihood of the model for the best set of parameters (highest likelihood).

model_fit contains several interesting methods such as model_fit.params the set of parameters maximizing the likelihood of the data set. model_fit.residual allows to see the maximum likelihood.

params and nb_states must match for relevant fits.

The more states, the longer convergeance may take. Slow increase of the likelihood can lead to premature stop of the fitting function. One can thus fit the parameters several times by replacing params with model_fit.params until convergeance is reached.