Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error in posterior updates with multiple children that have unobserved values #208

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/pyhgf/updates/posterior/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def posterior_update_mean_continuous_node(
# expected precisions from the value children
# sum the precision weigthed prediction errors over all children
value_precision_weigthed_prediction_error += (
(value_coupling * attributes[value_child_idx]["expected_precision"])
/ node_precision
(
(value_coupling * attributes[value_child_idx]["expected_precision"])
/ node_precision
)
) * value_prediction_error

# Volatility coupling updates - update the mean of a volatility parent
Expand Down Expand Up @@ -286,14 +288,10 @@ def posterior_update_precision_continuous_node(
edges[node_idx].value_children, # type: ignore
attributes[node_idx]["value_coupling_children"],
):
# cancel the prediction error if the child value was not observed
precision_weigthed_prediction_error += (
value_coupling**2 * attributes[value_child_idx]["expected_precision"]
)

# cancel the prediction error if the child value was not observed
precision_weigthed_prediction_error *= attributes[value_child_idx][
"observed"
]
) * attributes[value_child_idx]["observed"]

# Volatility coupling updates - update the precision of a volatility parent
# -------------------------------------------------------------------------
Expand All @@ -313,6 +311,7 @@ def posterior_update_precision_continuous_node(
]

# sum over all volatility children
# cancel the prediction error if the child value was not observed
precision_weigthed_prediction_error += (
0.5 * (volatility_coupling * effective_precision) ** 2
+ (volatility_coupling * effective_precision) ** 2
Expand All @@ -321,12 +320,7 @@ def posterior_update_precision_continuous_node(
* volatility_coupling**2
* effective_precision
* volatility_prediction_error
)

# cancel the prediction error if the child value was not observed
precision_weigthed_prediction_error *= attributes[volatility_child_idx][
"observed"
]
) * attributes[volatility_child_idx]["observed"]

# Compute the new posterior precision
# using value prediction errors from both value and volatility coupling
Expand Down
Loading