Skip to content

fix bug that mistakenly checks for positive ndts on missing data#782

Merged
AlexanderFengler merged 20 commits intomainfrom
fix-opns
Sep 26, 2025
Merged

fix bug that mistakenly checks for positive ndts on missing data#782
AlexanderFengler merged 20 commits intomainfrom
fix-opns

Conversation

@AlexanderFengler
Copy link
Copy Markdown
Member

This fixes an issue where we mistakenly check for ndt - rt > 0 for missing data, which wrongly set the log likelihood to the lower bound in those cases.

Copy link
Copy Markdown
Collaborator

@cpaniaguam cpaniaguam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few observations to consider for readability and maintainability:

  • Possibly refactor some conditionals and logic for clarity
  • Could be worth adjusting logging to defer string formatting

Comment on lines +786 to +789
if params_is_reg is not None:
params_only = True if (not any(params_is_reg)) else False
else:
params_only = False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if params_is_reg is not None:
params_only = True if (not any(params_is_reg)) else False
else:
params_only = False
params_only = params_is_reg is not None and not any(params_is_reg)

if missing_data and not deadline:
network = MissingDataNetwork.CPN
elif not missing_data and deadline:
elif missing_data and deadline:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a change in logic here. Is it intentional?

src/hssm/hssm.py Outdated
Comment on lines 1924 to 1933
if self.model_config.backend != "pytensor":
missing_data_callable = make_missing_data_callable(
self.loglik_missing_data, "jax", params_is_reg, params_only
self.loglik_missing_data, "jax", params_is_reg, None
)
else:
missing_data_callable = make_missing_data_callable(
self.loglik_missing_data,
self.model_config.backend,
params_is_reg,
None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not determine the backend first and keep a single call to make_missing_data_callable? It could look like this:

backend = "jax" if self.model_config.backend != "pytensor" else self.model_config.backend
missing_data_callable = make_missing_data_callable(
    self.loglik_missing_data,
    backend,
    params_is_reg,
    None,
)

Comment on lines +1946 to +1950
_logger.info(
f"Re-arranging data to put split missing and observed datapoints. "
f"Missing data (rt == {self.missing_data_value}) will be on top, "
f"observed datapoints follow."
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_logger.info(
f"Re-arranging data to put split missing and observed datapoints. "
f"Missing data (rt == {self.missing_data_value}) will be on top, "
f"observed datapoints follow."
)
_logger.info(
"Re-arranging data to put split missing and observed datapoints. "
"Missing data (rt == %s) will be on top, observed datapoints follow.",
self.missing_data_value
)

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 24, 2025

Codecov Report

❌ Patch coverage is 97.50000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/hssm/hssm.py 71.42% 6 Missing ⚠️
src/hssm/distribution_utils/dist.py 87.50% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/hssm/data_validator.py 96.29% <100.00%> (-1.33%) ⬇️
src/hssm/distribution_utils/onnx.py 94.82% <ø> (-1.61%) ⬇️
src/hssm/param/regression_param.py 94.57% <100.00%> (+0.08%) ⬆️
src/hssm/plotting/model_cartoon.py 91.45% <ø> (ø)
tests/slow/test_mcmc.py 100.00% <100.00%> (ø)
tests/slow/test_missing_data_and_deadline_mcmc.py 100.00% <100.00%> (ø)
tests/slow/test_missing_data_and_deadline_vi.py 100.00% <100.00%> (ø)
tests/slow/test_missing_data_mcmc.py 100.00% <100.00%> (ø)
tests/slow/test_missing_data_vi.py 100.00% <100.00%> (ø)
tests/slow/test_vi.py 100.00% <ø> (ø)
... and 9 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@digicosmos86 digicosmos86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have forgotten what conversations we had about go-nogo and how to branch different use cases, but as far as this PR goes, this looks good


@pytest.mark.slow
@pytest.mark.parametrize(parameter_names, parameter_grid)
@pytest.mark.parametrize(PARAMETER_NAMES, PARAMETER_GRID)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a stylistic choice, but why we are using all caps for variables that are not constants?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm from my perspective these are global constants, defined up top.
weird case.

match="You have no missing data in your dataset, "
+ "which is not allowed when `missing_data` or `deadline` is set to "
+ "True.",
match=r"Missing data is provided as True, "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use missing_data to signify that it is an argument?

)
with pytest.raises(
ValueError,
match="Missing data provided as False. \n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this

@AlexanderFengler AlexanderFengler merged commit a72abb6 into main Sep 26, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants