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 performance metric to summary file #13

Merged
merged 3 commits into from
Feb 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ license = { file = "LICENSE" }
authors = [
{ name = "IHME Math Sciences", email = "[email protected]" },
]
dependencies = ["numpy", "scipy", "pandas", "matplotlib", "mrtool==0.1.4", "pplkit"]
dependencies = [
"numpy",
"scipy",
"pandas",
"matplotlib",
"limetr @ git+https://github.com/zhengp0/[email protected]",
"mrtool==0.1.4",
"pplkit",
]

[project.optional-dependencies]
test = ["pytest"]
Expand Down
2 changes: 1 addition & 1 deletion src/bopforge/continuous_pipeline/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fit_signal_model(dataif: DataInterface) -> None:

df = functions.convert_bc_to_em(df, signal_model)

summary = functions.get_signal_model_summary(name, all_settings, df)
summary = functions.get_signal_model_summary(name, all_settings, df, signal_model)

fig = functions.plot_signal_model(
name,
Expand Down
42 changes: 37 additions & 5 deletions src/bopforge/continuous_pipeline/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from mrtool.core.utils import sample_knots
from pandas import DataFrame
from scipy.stats import norm
from limetr import get_aic, get_bic, get_rmse


def get_signal_model(settings: dict, df: DataFrame) -> MRBeRT:
Expand Down Expand Up @@ -138,7 +139,12 @@ def convert_bc_to_em(df: DataFrame, signal_model: MRBeRT) -> DataFrame:
return df


def get_signal_model_summary(name: str, all_settings: dict, df: DataFrame) -> dict:
def get_signal_model_summary(
name: str,
all_settings: dict,
df: DataFrame,
signal_model: MRBeRT,
) -> dict:
"""Create signal model summary.

Parameters
Expand All @@ -149,6 +155,8 @@ def get_signal_model_summary(name: str, all_settings: dict, df: DataFrame) -> di
All the settings for the pipeline.
df
Data frame that contains the training dataset.
signal_model
Fitted signal model for risk curve.

Returns
-------
Expand Down Expand Up @@ -183,6 +191,26 @@ def get_signal_model_summary(name: str, all_settings: dict, df: DataFrame) -> di
"normalize_to_tmrel"
]

summary["model_performance"] = {
"signal_model": {
"aic": float(
np.array(
[get_aic(sub_model.lt) for sub_model in signal_model.sub_models]
).dot(signal_model.weights)
),
"bic": float(
np.array(
[get_bic(sub_model.lt) for sub_model in signal_model.sub_models]
).dot(signal_model.weights)
),
"rmse": float(
np.array(
[get_rmse(sub_model.lt) for sub_model in signal_model.sub_models]
).dot(signal_model.weights)
),
},
}

return summary


Expand Down Expand Up @@ -414,11 +442,9 @@ def get_linear_model_summary(
summary["score"] = float("nan")
summary["star_rating"] = 0
else:
score = float(
((sign * burden_of_proof)[:, index].mean(axis=1)).min()
)
score = float(((sign * burden_of_proof)[:, index].mean(axis=1)).min())
summary["score"] = score
#Assign star rating based on ROS
# Assign star rating based on ROS
if np.isnan(score):
summary["star_rating"] = 0
elif score > np.log(1 + 0.85):
Expand All @@ -445,6 +471,12 @@ def get_linear_model_summary(
summary["pub_bias"] = int(pval < 0.05)
summary["pub_bias_pval"] = float(pval)

summary["model_performance"]["linear_model"] = {
"aic": float(get_aic(linear_model.lt)),
"bic": float(get_bic(linear_model.lt)),
"rmse": float(get_rmse(linear_model.lt)),
}

return summary


Expand Down
9 changes: 9 additions & 0 deletions src/bopforge/dichotomous_pipeline/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mrtool import MRBRT, CovFinder, LinearCovModel, MRData
from pandas import DataFrame
from scipy.stats import norm
from limetr import get_aic, get_bic, get_rmse


def get_signal_model(settings: dict, df: DataFrame) -> MRBRT:
Expand Down Expand Up @@ -272,6 +273,14 @@ def get_linear_model_summary(
summary["pub_bias"] = int(pval < 0.05)
summary["pub_bias_pval"] = float(pval)

summary["model_performance"] = {
"linear_model": {
"aic": float(get_aic(linear_model.lt)),
"bic": float(get_bic(linear_model.lt)),
"rmse": float(get_rmse(linear_model.lt)),
}
}

return summary


Expand Down
Loading