width-debias 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ """width-debias: correcting the noise bias in fitted profile widths.
2
+
3
+ A width fitted to a noisy profile scatters about the true width, so the fitted
4
+ variance exceeds the true one on average by the width's estimation variance,
5
+ which grows as the per-frame CNR falls. In a diffusion measurement the CNR
6
+ falls frame by frame, so the bias rises over time, leaks through the MSD fit,
7
+ and inflates the extracted diffusion coefficient D. Standard inverse-variance
8
+ weighting corrects the unequal noise across frames but cannot remove a mean
9
+ bias from a slope fit.
10
+
11
+ The package subtracts a calibrated bias ``var_bias(CNR)`` from each frame's
12
+ fitted variance, then weights by inverse variance; the MSD and D corrections
13
+ follow from the corrected widths. ``docs/DERIVATION.md`` derives the additive
14
+ form from a folded-normal model of the fitted width. The per-frame CNR (from
15
+ the ``fft-cnr`` package) is the input.
16
+
17
+ Typical use::
18
+
19
+ import numpy as np
20
+ from width_debias import Experiment, calibrate_d_free, evaluate
21
+ from width_debias.fit import fit_D
22
+ from width_debias.weights import msd_and_weights
23
+
24
+ cnr0 = np.array([5, 8, 13, 21, 34, 55, 90])
25
+ lookup = calibrate_d_free(cnr0) # D-free lookup var_bias(CNR)
26
+
27
+ # Monte Carlo bias curves <D_est>/D_ref for ols, inverse_variance,
28
+ # subtract, and mas
29
+ results = evaluate(Experiment(D=0.02), cnr0, lookup)
30
+
31
+ # A measurement: fitted widths in units of sigma_0^2 and per-frame CNR
32
+ msd, w = msd_and_weights("subtract", variance, cnr, lookup)
33
+ w = np.where(cnr >= 1.3, w, 0.0) # drop frames below the floor
34
+ D = fit_D(times, msd, w).D
35
+
36
+ ``subtract`` is the recommended scheme and :func:`calibrate_d_free` the
37
+ recommended calibration. The README states the conditions for real data: a
38
+ calibration that matches the data's geometry and units, and the per-frame CNR
39
+ floor.
40
+ """
41
+ from .simulate import (AnomalousExperiment, Experiment, MultiExpExperiment,
42
+ cnr_per_frame, noisy_series)
43
+ from .models import (GaussianModel, GeneralizedGaussianModel, MODELS,
44
+ MomentModel, UnboundedGaussianModel, VoigtModel,
45
+ model_from_spec, spec_tag)
46
+ from .montecarlo import Ensemble, run_ensemble
47
+ from .bias_lookup import FrameStats, BiasLookup, frame_stats
48
+ from .weights import (SCHEMES, calibration_D_se, corrected_variance,
49
+ msd_and_weights)
50
+ from .validate import (FrameDiagnostic, SchemeResult, calibrate,
51
+ calibrate_d_free, calibrate_fisher, evaluate,
52
+ per_frame_diagnostic, sweep_stats)
53
+ from .calibration import (CalibrationCells, CalibrationGrid, calibrate_cells,
54
+ calibrate_cnr_sigma2)
55
+ from .fisher import LeadingOrderTerms, leading_order_terms
56
+
57
+ __version__ = "0.4.0"
58
+
59
+ __all__ = [
60
+ "Experiment", "AnomalousExperiment", "MultiExpExperiment",
61
+ "cnr_per_frame", "noisy_series",
62
+ "GaussianModel", "VoigtModel", "GeneralizedGaussianModel", "MomentModel",
63
+ "UnboundedGaussianModel", "MODELS", "model_from_spec", "spec_tag",
64
+ "Ensemble", "run_ensemble",
65
+ "FrameStats", "BiasLookup", "frame_stats",
66
+ "SCHEMES", "msd_and_weights", "corrected_variance", "calibration_D_se",
67
+ "SchemeResult", "calibrate", "calibrate_d_free", "calibrate_fisher",
68
+ "evaluate", "sweep_stats",
69
+ "FrameDiagnostic", "per_frame_diagnostic",
70
+ "CalibrationGrid", "calibrate_cnr_sigma2",
71
+ "CalibrationCells", "calibrate_cells",
72
+ "LeadingOrderTerms", "leading_order_terms",
73
+ ]