Skip to content

Commit

Permalink
dwelltime: add discrete variant of profile test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Jul 25, 2023
1 parent 9156d60 commit be6f9d9
Showing 1 changed file with 47 additions and 17 deletions.
64 changes: 47 additions & 17 deletions lumicks/pylake/population/tests/test_dwelltimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,59 @@ def test_bootstrap(exponential_data):


@pytest.mark.slow
def test_dwelltime_profiles(exponential_data):
dataset = exponential_data["dataset_2exp"]
fit = DwelltimeModel(dataset["data"], 2, **dataset["parameters"].observation_limits)
@pytest.mark.parametrize(
# fmt:off
"exp_name, reference_bounds, reinterpolated_bounds",
[
(
"dataset_2exp",
(
(("amplitude", 0), (0.27856180571381217, 0.6778544935946536)),
(("amplitude", 1), (0.32214149274534964, 0.7214348170795223)),
(("lifetime", 0), (0.9845032769688804, 2.1800140645034936)),
(("lifetime", 1), (4.46449516635929, 7.154597435928374)),
),
(
(("amplitude", 0, 0.1), (0.306689101929755, 0.6422341656495031)),
(("amplitude", 1, 0.1), (0.3577572065740722, 0.6931158491955579)),
(("lifetime", 0, 0.1), (1.0609315961590462, 2.0595268935375497)),
(("lifetime", 1, 0.1), (4.598956971935465, 6.800809271638815)),
)
),
(
"dataset_2exp_discrete",
(
(("amplitude", 0), (0.19692513156203056, 0.5858259764323379)),
(("amplitude", 1), (0.4142575322804725, 0.8031067269150349)),
(("lifetime", 0), (0.6343614880907876, 1.9640893892023412)),
(("lifetime", 1), (4.293821879001909, 6.540141703753125)),
),
(
(("amplitude", 0, 0.1), (0.21986074314508786, 0.545534289263808)),
(("amplitude", 1, 0.1), (0.4544671041056059, 0.7801490242435826)),
(("lifetime", 0, 0.1), (0.7123775517046405, 1.8247849344610243)),
(("lifetime", 1, 0.1), (4.4060218782497556, 6.243393362264368)),
),
),
],
# fmt:on
)
def test_dwelltime_profiles(exponential_data, exp_name, reference_bounds, reinterpolated_bounds):
dataset = exponential_data[exp_name]

profiles = fit.profile_likelihood(max_chi2_step=0.25)
reference_bounds = [
(("amplitude", 0), (0.27856180571381217, 0.6778544935946536)),
(("amplitude", 1), (0.32214149274534964, 0.7214348170795223)),
(("lifetime", 0), (0.9845032769688804, 2.1800140645034936)),
(("lifetime", 1), (4.46449516635929, 7.154597435928374)),
]
fit = DwelltimeModel(
dataset["data"],
n_components=2,
**dataset["parameters"].observation_limits,
discretization_timestep=dataset["parameters"].dt
)

profiles = fit.profile_likelihood(max_chi2_step=0.25)
for (name, component), ref_interval in reference_bounds:
np.testing.assert_allclose(profiles.get_interval(name, component), ref_interval, rtol=1e-3)

# Re-interpolated confidence level (different significance level than originally profiled).
reference_bounds = [
(("amplitude", 0, 0.1), (0.306689101929755, 0.6422341656495031)),
(("amplitude", 1, 0.1), (0.3577572065740722, 0.6931158491955579)),
(("lifetime", 0, 0.1), (1.0609315961590462, 2.0595268935375497)),
(("lifetime", 1, 0.1), (4.598956971935465, 6.800809271638815)),
]
for (name, component, significance), ref_interval in reference_bounds:
for (name, component, significance), ref_interval in reinterpolated_bounds:
np.testing.assert_allclose(
profiles.get_interval(name, component, significance), ref_interval, rtol=1e-3
)
Expand Down

0 comments on commit be6f9d9

Please sign in to comment.