Skip to content

Commit

Permalink
Merge pull request #78 from blei-lab/achille/prepare_release
Browse files Browse the repository at this point in the history
Achille/prepare release
  • Loading branch information
velezbeltran authored Jun 11, 2024
2 parents f3afbe5 + 488b472 commit 1df04ce
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 62 deletions.
31 changes: 0 additions & 31 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ six>=1.14.0
tox
twine
scipy
poetry
43 changes: 40 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
[build-system]
requires = [
"setuptools>=30.3.0",
[tool.poetry]
name = "treeffuser"
version = "0.1.0"
description = ""
authors = [
"Nicolas Beltran-Velez <[email protected]>",
"Alessandro Antonio Grande <[email protected]>",
"Achille Nazaret <[email protected]>",
]
license = "MIT"
readme = "README.rst"
packages = [{include = "treeffuser", from= "src"}]
repository = "https://github.com/blei-lab/treeffuser"
include = [
"pyproject.toml",
"AUTHORS.rst",
"README.rst",
"LICENSE"
]

[tool.poetry.dependencies]
python = "^3.9"
numpy = "^1.24"
jaxtyping = "^0.2.19"
einops = "^0.8.0"
scipy = "^1.13.1"
tqdm = "^4.66.4"
lightgbm = "^4.3.0"
ml-collections = "^0.1.1"
scikit-learn = "^1.5.0"

[tool.poetry.dev-dependencies]
pytest = "^8.2.2"
tox = "^3.20.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff.per-file-ignores]
"ci/*" = ["S"]

Expand Down Expand Up @@ -56,3 +90,6 @@ target-version = ["py38"]

[tool.ruff.format]
indent-style="space"

[tool.pytest.ini_options]
pythonpath = "src"
14 changes: 0 additions & 14 deletions requirements.txt

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_score_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import numpy as np
from einops import repeat
from sklearn.metrics import r2_score

from treeffuser._score_models import LightGBMScore
from treeffuser.sde.sdes import VESDE

from .utils import generate_bimodal_linear_regression_data
from .utils import r2_score


def test_linear_regression():
Expand Down
5 changes: 3 additions & 2 deletions tests/test_treeffuser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
from scipy.stats import ks_2samp
from sklearn.model_selection import train_test_split

from treeffuser import LightGBMTreeffuser
from utils import gaussian_mixture_pdf

from .utils import gaussian_mixture_pdf
from .utils import train_test_split


def test_treeffuser_bimodal_linear_regression():
Expand Down
31 changes: 31 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,34 @@ def gaussian_mixture_pdf(
density = weight1 * gaussian_pdf(x, loc1, scale1, log=False)
density += (1 - weight1) * gaussian_pdf(x, loc2, scale2, log=False)
return np.log(density) if log else density


def train_test_split(X, y, test_size=0.2, random_state=None):
"""
Split the data into training and test sets.
"""
n = X.shape[0]
if random_state is not None:
rng = np.random.default_rng(random_state)
else:
rng = np.random.default_rng()
idx = rng.permutation(n)
n_test = int(n * test_size)
idx_train = idx[n_test:]
idx_test = idx[:n_test]
return X[idx_train], X[idx_test], y[idx_train], y[idx_test]


def r2_score(y_true, y_pred):
"""
Compute the R^2 score.
"""
y_true = y_true.flatten()
y_pred = y_pred.flatten()

y_mean = np.mean(y_true)
ss_tot = np.sum((y_true - y_mean) ** 2)
ss_res = np.sum((y_true - y_pred) ** 2)

r2 = 1 - ss_res / ss_tot
return r2
17 changes: 6 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ commands =
passenv =
*

; a generative tox configuration, see: https://tox.wiki/en/latest/user_guide.html#generative-environments
# TODO: This should be fixed for the final release
[tox]
skipsdist = true
envlist =
clean,
check,
{py310,pypy310, py39,pypy39},
report
#clean,
#check,
#docs,
#{py38,py39,py310,py311,py312,pypy38,pypy39,pypy310},
#report
ignore_basepython_conflict = true

[testenv]
Expand All @@ -40,24 +34,25 @@ setenv =
passenv =
*
usedevelop = false
allowlist_externals = poetry
deps =
pytest
pytest-cov
commands =
{posargs:pytest --cov --cov-report=term-missing --cov-report=xml -vv tests}
poetry install
poetry run pytest --cov --cov-report=term-missing --cov-report=xml -vv tests

[testenv:check]
deps =
docutils
check-manifest
pre-commit
readme-renderer
pygments
isort
skip_install = true
allowlist_externals = poetry
commands =
python setup.py check --strict --metadata --restructuredtext
check-manifest .
poetry check
pre-commit run --all-files --show-diff-on-failure

[testenv:docs]
Expand Down

0 comments on commit 1df04ce

Please sign in to comment.