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

Improve testing infrastructure #18

Merged
merged 4 commits into from
Sep 11, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ presentation/*
.cache
.devcontainer/*
.coverage
build.txt
build.txt
gist.githubusercontent*
4 changes: 0 additions & 4 deletions tests/test_coordinate_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,3 @@ def test_coordinate_descent_bounds():

assert np.all(rolch_lasso_path_negative <= 0), "Path should contain only betas <= 0"
assert np.all(rolch_lasso_path_positive >= 0), "Path should contain only betas >= 0"


test_coordinate_descent()
test_coordinate_descent_bounds()
46 changes: 46 additions & 0 deletions tests/test_python_against_r.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np

import rolch

file = "https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv"
mtcars = np.genfromtxt(file, delimiter=",", skip_header=1)[:, 1:]

y = mtcars[:, 0]
X = mtcars[:, [1, 3]]
X = np.hstack((np.ones((y.shape[0], 1)), X))


def test_normal_distribution():
# Run the following R code
# library("gamlss")
# data(mtcars)

# model = gamlss(
# mpg ~ cyl + hp,
# sigma.formula = ~cyl + hp,
# family=NO(),
# data=as.data.frame(mtcars)
# )

# coef(model, "mu")
# coef(model, "sigma")

# To get these coefficients
coef_R_mu = np.array([36.51776626, -2.32470221, -0.01421071])
coef_R_sg = np.array([1.8782995906, -0.1262290913, -0.0003943062])

estimator = rolch.OnlineGamlss(
distribution=rolch.DistributionNormal(),
method="ols",
do_scale=False,
expect_intercept=True,
rss_tol_inner=10,
)
estimator.fit(y=y, x0=X, x1=X)

assert np.allclose(
estimator.betas[0], coef_R_mu, atol=0.01
), "Location coefficients don't match"
assert np.allclose(
estimator.betas[1], coef_R_sg, atol=0.01
), "Scale coefficients don't match"
Loading