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

Add separated prior and likelihood groups #53

Merged
merged 2 commits into from
Jan 29, 2025
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
44 changes: 32 additions & 12 deletions src/arviz_stats/psense.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ def psense_summary(
sample_dims=None,
threshold=0.05,
alphas=(0.99, 1.01),
group_var_names=None,
group_coords=None,
prior_var_names=None,
likelihood_var_names=None,
prior_coords=None,
likelihood_coords=None,
round_to=3,
):
"""
Expand All @@ -146,11 +148,16 @@ def psense_summary(
Threshold value to determine the sensitivity diagnosis. Default is 0.05.
alphas : tuple
Lower and upper alpha values for gradient calculation. Defaults to (0.99, 1.01).
group_var_names : str, optional
Name of the prior or log likelihood variables to use
group_coords : dict, optional
prior_var_names : str, optional
Name of the log-prior variables to include in the power scaling sensitivity diagnostic
likelihood_var_names : str, optional
Name of the log-likelihood variables to include in the power scaling sensitivity diagnostic
prior_coords : dict, optional
Coordinates defining a subset over the group element for which to
compute the prior sensitivity diagnostic
compute the log-prior sensitivity diagnostic
likelihood_coords : dict, optional
Coordinates defining a subset over the group element for which to
compute the log-likelihood sensitivity diagnostic
round_to : int, optional
Number of decimal places to round the sensitivity values. Default is 3.

Expand Down Expand Up @@ -181,8 +188,8 @@ def psense_summary(
sample_dims=sample_dims,
coords=coords,
alphas=alphas,
group_var_names=group_var_names,
group_coords=group_coords,
group_var_names=prior_var_names,
group_coords=prior_coords,
)
pssdl = psense(
data,
Expand All @@ -192,8 +199,8 @@ def psense_summary(
coords=coords,
sample_dims=sample_dims,
alphas=alphas,
group_var_names=group_var_names,
group_coords=group_coords,
group_var_names=likelihood_var_names,
group_coords=likelihood_coords,
)

joined = xr.concat([pssdp, pssdl], dim="component").assign_coords(
Expand Down Expand Up @@ -227,7 +234,7 @@ def _diagnose(row):
return psense_df.round(round_to)


def power_scale_dataset(dt, group, alphas, sample_dims):
def power_scale_dataset(dt, group, alphas, sample_dims, group_var_names, group_coords):
"""Resample the dataset with the power scale weights.

Parameters
Expand All @@ -239,12 +246,25 @@ def power_scale_dataset(dt, group, alphas, sample_dims):
Lower and upper alpha values for power scaling.
sample_dims : str or sequence of hashable
Dimensions to reduce unless mapped to an aesthetic.
group_var_names : str
Name of the log-prior or log-likelihood variables to use.
group_coords : dict
Coordinates defining a subset over the group element for which to
compute the sensitivity diagnostic.

Returns
-------
DataSet with resampled data.
"""
lower_w, upper_w = _get_power_scale_weights(dt, alphas, group=group, sample_dims=sample_dims)
lower_w, upper_w = _get_power_scale_weights(
dt,
alphas,
group=group,
sample_dims=sample_dims,
group_var_names=group_var_names,
group_coords=group_coords,
)

lower_w = lower_w.values.flatten()
upper_w = upper_w.values.flatten()
s_size = len(lower_w)
Expand Down
Loading