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

fixes a bug where binomtest fails because of floating point math #315

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.10.1
hooks:
- id: black-jupyter
- repo: https://github.com/asottile/pyupgrade
Expand Down
10 changes: 7 additions & 3 deletions ema_workbench/analysis/prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def __init__(self, prim, box_lims, indices):
"res_dim": pd.Series(dtype=int),
"mass": pd.Series(dtype=float),
"id": pd.Series(dtype=int),
"n": pd.Series(dtype=int), # items in box
"k": pd.Series(dtype=int), # items of interest in box
}

self.peeling_trajectory = pd.DataFrame(columns)
Expand Down Expand Up @@ -794,6 +796,8 @@ def update(self, box_lims, indices):
"res_dim": restricted_dims.shape[0],
"mass": y.shape[0] / self.prim.n,
"id": i,
"n": y.shape[0],
"k": coi,
}
new_row = pd.DataFrame([data])
# self.peeling_trajectory = self.peeling_trajectory.append(
Expand Down Expand Up @@ -870,7 +874,7 @@ def show_pairs_scatter(
if dims is None:
dims = sdutil._determine_restricted_dims(self.box_lims[i], self.prim.box_init)

if diag_kind not in diag_kind.__members__:
if diag_kind not in DiagKind:
raise ValueError(
f"diag_kind should be one of DiagKind.KDE or DiagKind.CDF, not {diag_kind}"
)
Expand Down Expand Up @@ -914,10 +918,10 @@ def _calculate_quasi_p(self, i, restricted_dims):
box_lim = box_lim[restricted_dims]

# total nr. of cases in box
Tbox = self.peeling_trajectory["mass"][i] * self.prim.n
Tbox = self.peeling_trajectory.loc[i, "n"]

# total nr. of cases of interest in box
Hbox = self.peeling_trajectory["coverage"][i] * self.prim.t_coi
Hbox = self.peeling_trajectory.loc[i, "k"]

x = self.prim.x.loc[self.prim.yi_remaining, restricted_dims]
y = self.prim.y[self.prim.yi_remaining]
Expand Down
3 changes: 3 additions & 0 deletions ema_workbench/analysis/prim_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DiagKind(Enum):
CDF = "cdf"
"""constant for plotting diagonal in pairs_scatter as cdf"""

def __contains__(cls, item):
return item in cls.__members__.values()


def get_quantile(data, quantile):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_analysis/test_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_init(self):
prim_obj = prim.setup_prim(results, "y", threshold=0.8)
box = PrimBox(prim_obj, prim_obj.box_init, prim_obj.yi)

self.assertEqual(box.peeling_trajectory.shape, (1, 6))
self.assertEqual(box.peeling_trajectory.shape, (1, 8))

def test_select(self):
x = pd.DataFrame([(0, 1, 2), (2, 5, 6), (3, 2, 1)], columns=["a", "b", "c"])
Expand Down