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

Advance to version 0.2.1 #70

Merged
merged 2 commits into from
Mar 7, 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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "onemod"
version = "0.2.0"
version = "0.2.1"
description = "A pipeline package for estimating scalar quantity by leveraging covariates and correlations across multiple dimensions."
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -25,12 +25,12 @@ dependencies = [
"loguru",
"modrover @ git+https://github.com/ihmeuw-msca/modrover.git@v0.1.3",
"regmodsm @ git+https://github.com/ihmeuw-msca/regmodsm.git@v0.1.1",
"pandas < 2.0",
"pandas",
"pyarrow",
"pydantic",
"scipy",
"regmod == 0.1.1",
"weighted-average == 1.1.1",
"weighted-average == 1.1.2",
]

[project.optional-dependencies]
Expand Down
26 changes: 18 additions & 8 deletions src/onemod/actions/models/regmod_smooth_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Run regmod smooth model, currently the main goal of this step is to smooth
the covariate coefficients across age groups.
"""

from functools import partial
from typing import Callable

Expand Down Expand Up @@ -58,17 +59,17 @@ def get_residual_computation_function(

def get_residual_se_function(
model_type: str,
col_obs: str,
col_pred: str,
col_weights: str,
) -> Callable:
"""
Calculate the residual standard error for a given row based on the specified model type.

Parameters:
row (pd.Series): The row containing the observation and prediction data.
model_type (str): Type of the statistical model (e.g., 'binomial', 'poisson', 'tobit').
col_obs (str): Column name for the observed values.
col_pred (str): Column name for the predicted values.
col_weights (str): Column name for the weights.

Returns:
float: The calculated residual standard error value.
Expand All @@ -79,12 +80,19 @@ def get_residual_se_function(

callable_map = {
"binomial": partial(
lambda row, obs, pred: 1 / np.sqrt(row[col_pred] * (1 - row[col_pred])),
obs=col_obs,
lambda row, pred, weights: 1
/ np.sqrt(row[weights] * row[pred] * (1 - row[pred])),
pred=col_pred,
weights=col_weights,
),
"poisson": partial(
lambda row, pred, weights: 1 / np.sqrt(row[weights] * row[pred]),
pred=col_pred,
weights=col_weights,
),
"gaussian": partial(
lambda row, weights: 1 / np.sqrt(row[weights]), weights=col_weights
),
"poisson": partial(lambda row, pred: 1 / np.sqrt(row[col_pred]), pred=col_pred),
"gaussian": lambda *args, **kwargs: 1.0,
}

try:
Expand Down Expand Up @@ -177,7 +185,9 @@ def regmod_smooth_model(experiment_dir: str) -> None:
for var_group in var_groups:
cov = var_group["col"]
if "uprior" not in var_group:
var_group["uprior"] = tuple(map(float, coef_bounds.get(cov, [-np.inf, np.inf])))
var_group["uprior"] = tuple(
map(float, coef_bounds.get(cov, [-np.inf, np.inf]))
)
if "lam" not in var_group:
var_group["lam"] = lam

Expand Down Expand Up @@ -210,8 +220,8 @@ def regmod_smooth_model(experiment_dir: str) -> None:

residual_se_func = get_residual_se_function(
model_type=regmod_smooth_config.mtype,
col_obs=global_config.col_obs,
col_pred=global_config.col_pred,
col_weights=regmod_smooth_config.model.weights,
)
df["residual"] = df.apply(
residual_func,
Expand Down
1 change: 1 addition & 0 deletions src/onemod/actions/models/weave_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"exponential": "radius",
"tricubic": "exponent",
"depth": "radius",
"variance": "radius",
}


Expand Down
127 changes: 0 additions & 127 deletions src/onemod/schema/config.py

This file was deleted.

3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def sample_input_data(temporary_directory):
# Generate an observations column, random from 0 to 1
data["obs_rate"] = np.random.rand(len(data))

# Add population for residual uncertainty computation
data["population"] = 1.0

# Save to the temp directory
os.mkdir(temporary_directory / "data")
data_path = temporary_directory / "data" / "data.parquet"
Expand Down