Skip to content

Commit

Permalink
Merge pull request #61 from artefactory/poetry
Browse files Browse the repository at this point in the history
ADD: Poetry dependancies management
  • Loading branch information
VincentAuriau authored Apr 26, 2024
2 parents 1831b89 + 8f50e4b commit d384fb4
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 38 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<img src="docs/choice_learn_official_logo.png" width="256">

Choice-Learn is a Python package designed to help you estimate discrete choice models and use them (e.g., assortment optimization plug-in).
The package provides ready-to-use datasets and models from the litterature. It also provides a lower level use if you wish to customize any model or create your own from scratch. In particular you will find efficient data handling to limit RAM usage and structure common to any choice model.
The package provides ready-to-use datasets and models from the litterature. It also provides a lower level use if you wish to customize any choice model or create your own from scratch. Choice-Learn efficiently handles data with the objective to limit RAM usage. It is made particularly easy to estimate choice models with your own, large datasets.

Choice-Learn uses NumPy and pandas as data backend engines and TensorFlow for models.

This repository contains a private version of the package.

## Table of Contents

- [choice-learn-private](#choice-learn-private)
[Choice-Learn](#choice-learn-private)
- [Introduction - Discrete Choice Modelling](#introduction---discrete-choice-modelling)
- [What's in there ?](#whats-in-there)
- [Getting Started](#getting-started)
Expand Down Expand Up @@ -100,7 +100,10 @@ Choice-Learn requires the following:
For modelling you need:
- TensorFlow (>=2.13)

Finally, an optional requirement used for report and LBFG-S optimization is:
> :warning: **Warning:** If you are a MAC user with a M1 or M2 chip, importing TensorFlow might lead to Python crashing.
> In such case, use anaconda to install TensorFlow with `conda install -c apple tensorflow`.
Finally, an optional requirement used for coefficients analysis and L-BFGS optimization is:
- TensorFlow Probability (>=0.20.1)

Once you have created your conda/pip python==3.9 environment, you can install requirements by:
Expand Down Expand Up @@ -152,7 +155,7 @@ print(model.report)

## Documentation

A detailed documentation of this project is available [here](https://artefactory.github.io/choice-learn-private/)
A detailed documentation of this project is available [here](https://artefactory.github.io/choice-learn-private/).

## Citation

Expand Down
2 changes: 1 addition & 1 deletion choice_learn/tf_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
axis=-1,
epsilon=1e-10,
name="eps_categorical_crossentropy",
reduction=tf.keras.losses.Reduction.AUTO,
reduction="sum_over_batch_size",
):
"""Initialize function.
Expand Down
98 changes: 77 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "choice-learn-private"
authors = [
{ name = "VincentAuriau", email = "[email protected]" }
]
description = "choice-learn is a Python package designed to help you build with ease a discrete choice model."
version = "0.0.1"
readme = "README.md"
requires-python = ">=3.8"

[project.urls]
"Homepage" = "https://github.com/artefactory/choice-learn-private"
"Documentation" = "https://artefactory.github.io/choice-learn-private"

[tool.setuptools]
packages = ["choice_learn", "config", "tests"]

[tool.ruff]
select = [
"E",
Expand Down Expand Up @@ -68,3 +47,80 @@ known-first-party = ["choice_learn", "config", "tests"]

[tool.bandit.assert_used]
exclude_dirs = ["tests/"]

[tool.poetry]
name = "choice-learn"
version = "0.1.0"
description = "Choice-Learn is a Python package to help you specify, estimate and use discrete choice models with ease."
authors = [
"artefactory <[email protected]>",
"VincentAuriau <[email protected]>"
]
homepage = "https://github.com/artefactory/choice-learn-private"
documentation = "https://artefactory.github.io/choice-learn-private"
license = "MIT"
readme = "README.md"
keywords = ["discrete", "choice", "model", "machine", "learning", "assortment", "pricing", "retail", "supermarket"]
packages = [{include = "choice_learn"}]

[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.24.3"
pandas = "^1.5.3"
tensorflow = "^2.11.0"
tensorflow-probability = "^0.20.1"
tqdm = "^4.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.2"
pre-commit = "^3.3"
ipykernel = "^6.9"
nbstripout = "^0.7"
ruff = "^0.1.2"
pytest-cov = "^4.1"
codespell = "^2.2"
python-markdown-math = "^0.8"

[tool.poetry.group.docs.dependencies]
mkdocs = "^1.5"
mkdocs-material = {extras = ["pygments"], version = "^9.5.3"}
mkdocs-nbconvert = "^0.2.1"
mkdocstrings-python = "^1.7.5"
python-markdown-math = "^0.8"
bandit = "^1.7.5"
nbstripout = "^0.6.1"

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

[tool.semantic_release]
version_variables = ["choice_learn/__init__.py:__version__"]
version_toml = ["pyproject.toml:tool.poetry.version"]
branch = "main"
upload_to_pypi = false
upload_to_release = true
build_command = "pip install poetry && poetry build"
commit_message = "chore(release): {version}\n\n[skip ci]\nAutomatically generated by semantic-release"
tag_format = "{version}"

[tool.semantic_release.changelog]
exclude_commit_patterns = ['''^chore\(release\).*''']

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"ADD",
"BUILD",
"CHORE",
"CI",
"DOC",
"ENH",
"FEAT",
"FIX",
"PERF",
"STYLE",
"REFAC",
"TEST",
]
minor_tags = ["FEAT"]
patch_tags = ["ADD", "BUILD", "ENH", "FIX", "PERF"]
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ def test_batch():
assert (batch[0][1] == np.array([1, 0, 0, 0])).all()

assert (batch[1][0] == np.array([[2, 2, 2, 2], [2, 2, 2, 3]])).all()
assert (batch[1][0] == np.array([[1, 0, 0, 0], [0, 1, 0, 0]])).all()
assert (batch[1][1] == np.array([[1, 0, 0, 0], [0, 1, 0, 0]])).all()

assert (batch[3] == np.array([1.0, 1.0])).all()
assert batch[4] == 0
assert (batch[2] == np.array([1.0, 1.0])).all()
assert batch[3] == 0

batch = dataset.batch[0]
assert (batch[0][0] == np.array([2, 1])).all()
assert (batch[0][1] == np.array([1, 0, 0, 0])).all()

assert (batch[1][0] == np.array([[2, 2, 2, 2], [2, 2, 2, 3]])).all()
assert (batch[1][0] == np.array([[1, 0, 0, 0], [0, 1, 0, 0]])).all()
assert (batch[1][1] == np.array([[1, 0, 0, 0], [0, 1, 0, 0]])).all()

assert (batch[3] == np.array([1.0, 1.0])).all()
assert batch[4] == 0
assert (batch[2] == np.array([1.0, 1.0])).all()
assert batch[3] == 0

batch = dataset.get_choices_batch([1, 2])
assert (batch[0][0] == np.array([[3, 4], [9, 4]])).all()
Expand All @@ -74,11 +74,11 @@ def test_batch():
batch[1][0] == np.array([[[2, 2, 3, 2], [3, 2, 2, 2]], [[3, 2, 2, 2], [2, 3, 2, 2]]])
).all()
assert (
batch[1][0] == np.array([[[0, 0, 0, 1], [0, 0, 1, 0]], [[1, 0, 0, 0], [0, 1, 0, 0]]])
batch[1][1] == np.array([[[0, 0, 0, 1], [0, 0, 1, 0]], [[1, 0, 0, 0], [0, 1, 0, 0]]])
).all()

assert (batch[3] == np.array([[1.0, 1.0], [1.0, 1.0]])).all()
assert (batch[4] == np.array([1, 1])).all()
assert (batch[2] == np.array([[1.0, 1.0], [1.0, 1.0]])).all()
assert (batch[3] == np.array([1, 1])).all()

batch = dataset.batch[[1, 2]]
assert (batch[0][0] == np.array([[3, 4], [9, 4]])).all()
Expand All @@ -88,8 +88,8 @@ def test_batch():
batch[1][0] == np.array([[[2, 2, 3, 2], [3, 2, 2, 2]], [[3, 2, 2, 2], [2, 3, 2, 2]]])
).all()
assert (
batch[1][0] == np.array([[[0, 0, 0, 1], [0, 0, 1, 0]], [[1, 0, 0, 0], [0, 1, 0, 0]]])
batch[1][1] == np.array([[[0, 0, 0, 1], [0, 0, 1, 0]], [[1, 0, 0, 0], [0, 1, 0, 0]]])
).all()

assert (batch[3] == np.array([[1.0, 1.0], [1.0, 1.0]])).all()
assert (batch[4] == np.array([1, 1])).all()
assert (batch[2] == np.array([[1.0, 1.0], [1.0, 1.0]])).all()
assert (batch[3] == np.array([1, 1])).all()
File renamed without changes.

0 comments on commit d384fb4

Please sign in to comment.