Skip to content

Commit

Permalink
Begin adding skip_fit hook into diffmah_fitter
Browse files Browse the repository at this point in the history
  • Loading branch information
aphearin committed Nov 13, 2024
1 parent 6000300 commit 1353e18
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 11 additions & 6 deletions diffmah/fitting_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ def diffmah_fitter(
u_p_init, loss_data, skip_fit = get_loss_data(
t_sim, log_mah_sim, lgm_min, dlogm_cut, t_fit_min
)
_res = bfgs_adam_fallback(loss_and_grads_kern, u_p_init, loss_data, nstep, n_warmup)
u_p_best, loss_best, fit_terminates, code_used = _res
u_t_peak = loss_data[2]
u_p_best = dk.DEFAULT_MAH_U_PARAMS._make((*u_p_best, u_t_peak))
p_best = dk.get_bounded_mah_params(u_p_best)
return p_best, loss_best, fit_terminates, code_used, loss_data
if skip_fit:
raise NotImplementedError
else:
_res = bfgs_adam_fallback(
loss_and_grads_kern, u_p_init, loss_data, nstep, n_warmup
)
u_p_best, loss_best, fit_terminates, code_used = _res
u_t_peak = loss_data[2]
u_p_best = dk.DEFAULT_MAH_U_PARAMS._make((*u_p_best, u_t_peak))
p_best = dk.get_bounded_mah_params(u_p_best)
return p_best, loss_best, fit_terminates, code_used, loss_data


def write_collated_data(outname, fit_data_strings, chunk_arr=None):
Expand Down
8 changes: 8 additions & 0 deletions diffmah/tests/test_fitting_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def test_diffmah_fitter():
assert loss_check < 0.01


def test_diffmah_fitter_skips_mahs_with_insufficient_data():
t_sim = np.linspace(0.1, 13.8, 100)
log_mah_sim = np.linspace(1, 14, t_sim.size)
_res = fithelp.diffmah_fitter(t_sim, log_mah_sim)
p_best, loss_best, fit_terminates, code_used, loss_data = _res
raise NotImplementedError()


def test_get_target_data():
t_sim = np.linspace(0.1, 13.8, 100)
log_mah_sim = np.linspace(1, 14, t_sim.size)
Expand Down

0 comments on commit 1353e18

Please sign in to comment.