pyfli.solver.base_fitter#

Implement the shared least-squares FLI fitter used by CPU, GPU, and model-comparison workflows.

This module belongs to pyfli.solver and is part of PyFLI least-squares, maximum- likelihood, CPU, GPU, binned, and global FLI fitting routines. Public API includes classes BaseFLIFitter.

Classes

BaseFLIFitter(freq, decay_px, irf_px[, ...])

Run the base flifitter routine.

class BaseFLIFitter(freq, decay_px, irf_px, white_noise=0.1, guess_plugin=moment_based_guess, custom_funcs=None, shift_method='zero_pad', fit_indices=None)[source]#

Bases: object

Run the base flifitter routine. base class handles model construction, fit ranges, parameter guesses, bounds, post- processing, and model comparison support.

Parameters:
  • freq (float) – Acquisition frequency information used to derive timing constants.

  • decay_px (np.ndarray) – Per-pixel fluorescence decay trace supplied to the fitter.

  • irf_px (np.ndarray) – Per-pixel instrument response function supplied to the fitter.

  • white_noise (float) – White-noise estimate used to weight residuals.

  • guess_plugin (np.ndarray) – Optional callable that supplies initial parameter guesses.

  • custom_funcs (np.ndarray | None) – Optional custom model functions used by the fitter.

  • shift_method (str) – Method used to align the IRF and decay traces.

  • fit_indices (tuple[int, int] | None) – Optional (gate_num_start, gate_num_end) gate range to fit over, e.g. to focus on the tail of the decay. None fits the full trace.

fit_with_estimator(estimator_type='least_squares', model_type='bi-exponential', p0=None, bounds=None, **kwargs)[source]#

Unified entry point for all NLSF estimators.

Parameters:
Return type:

Any

least_squares_fit(p0, bounds, model_type, use_weights=True, **kwargs)[source]#

Run the least squares fit routine.

Parameters:
  • p0 (Any) – Initial parameter vector supplied to the optimizer.

  • bounds (np.ndarray) – Lower and upper parameter bounds supplied to the optimizer.

  • model_type (str) – FLI model family, such as mono- or bi-exponential.

  • use_weights (bool) – Whether residuals are weighted during least-squares fitting.

  • **kwargs (Any) – Additional keyword options forwarded to the underlying implementation.

Returns:

Object produced by least squares fit.

Return type:

Any

trust_region(p0, bounds, model_type, **kwargs)[source]#

Run the trust region routine.

Parameters:
  • p0 (Any) – Initial parameter vector supplied to the optimizer.

  • bounds (np.ndarray) – Lower and upper parameter bounds supplied to the optimizer.

  • model_type (str) – FLI model family, such as mono- or bi-exponential.

  • **kwargs (Any) – Additional keyword options forwarded to the underlying implementation.

Returns:

Object produced by trust region.

Return type:

Any

unconstrained(p0, bounds, model_type, **kwargs)[source]#

Run the unconstrained routine.

Parameters:
  • p0 (Any) – Initial parameter vector supplied to the optimizer.

  • bounds (np.ndarray) – Lower and upper parameter bounds supplied to the optimizer.

  • model_type (str) – FLI model family, such as mono- or bi-exponential.

  • **kwargs (Any) – Additional keyword options forwarded to the underlying implementation.

Returns:

Object produced by unconstrained.

Return type:

Any

model_fit(t, params, model_type='mono-exponential')[source]#

Run the model fit routine.

Parameters:
  • t (np.ndarray) – Time axis or acquisition period used by the calculation.

  • params (Any) – Model, detector, or plotting parameters used by the routine.

  • model_type (str) – FLI model family, such as mono- or bi-exponential.

Returns:

Object produced by model fit.

Return type:

Any

calculate_uncertainties(jacobian, chi_sq, n_data, n_params)[source]#

Calculate uncertainties.

Parameters:
  • jacobian (Any) – Jacobian matrix used to estimate parameter uncertainty.

  • chi_sq (np.ndarray) – Chi-square statistic used to scale uncertainty estimates.

  • n_data (int) – Number of samples, components, gates, or iterations used by the routine.

  • n_params (int) – Number of fitted model parameters.

Returns:

Object produced by calculate uncertainties.

Return type:

Any

compare_models(alpha=0.05)[source]#

Compare models.

Parameters:

alpha (float) – Regularization strength, fraction value, or significance threshold used by the routine.

Returns:

Tuple containing model-comparison statistics and selected fit results.

Return type:

tuple[Any, ]

get_average_lifetime(popt)[source]#

Return average lifetime.

Parameters:

popt (np.ndarray) – Optimized model parameter vector.

Returns:

Object produced by get average lifetime.

Return type:

Any

get_fret_efficiency(popt)[source]#

Return fret efficiency.

Parameters:

popt (np.ndarray) – Optimized model parameter vector.

Returns:

Object produced by get FRET efficiency.

Return type:

Any

set_fit_range(start_pct=0, end_pct=100)[source]#

Set fit range.

Parameters:
  • start_pct (int) – Start percentage of the decay range used for fitting.

  • end_pct (int) – End percentage of the decay range used for fitting.

Returns:

No object is returned; the function set fit range.

Return type:

None