sgtlearn 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sgtlearn-0.1.0/.github/workflows/workflow.yml +172 -0
- sgtlearn-0.1.0/.gitignore +238 -0
- sgtlearn-0.1.0/LICENSE +21 -0
- sgtlearn-0.1.0/PKG-INFO +162 -0
- sgtlearn-0.1.0/README.md +138 -0
- sgtlearn-0.1.0/ROADMAP.md +20 -0
- sgtlearn-0.1.0/assets/SGT_Viz.png +0 -0
- sgtlearn-0.1.0/cpp/CMakeLists.txt +209 -0
- sgtlearn-0.1.0/cpp/README.md +76 -0
- sgtlearn-0.1.0/cpp/bindings/Discretizers.cpp +360 -0
- sgtlearn-0.1.0/cpp/bindings/ShapeGeneralizedTrees.cpp +513 -0
- sgtlearn-0.1.0/cpp/bindings/_arma_bridge.h +260 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/AbsoluteErrorBranchAssignment.cpp +127 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/AbsoluteErrorBranchAssignment.h +51 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/BranchAssignment.h +26 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/BranchAssignmentFactory.cpp +74 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/BranchAssignmentFactory.h +34 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/BranchAssignmentVariants.h +66 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/LeafAggregateProcessor.h +69 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/LeafAggregationBranchAssignment.cpp +110 -0
- sgtlearn-0.1.0/cpp/src/BranchAssignmentObjectives/LeafAggregationBranchAssignment.h +60 -0
- sgtlearn-0.1.0/cpp/src/Criterion.cpp +123 -0
- sgtlearn-0.1.0/cpp/src/Criterion.h +36 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/ClassificationDiscretizer.h +72 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/GainHessianUnivariateDiscretizer.cpp +57 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/GainHessianUnivariateDiscretizer.h +23 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/RegressionDiscretizer.h +73 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateClassificationDiscretizer.cpp +56 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateClassificationDiscretizer.h +33 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateDiscretizer.h +67 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateDiscretizer.tpp +115 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateRegressionDiscretizer.cpp +51 -0
- sgtlearn-0.1.0/cpp/src/Discretizers/UnivariateRegressionDiscretizer.h +29 -0
- sgtlearn-0.1.0/cpp/src/Domain/LearningCriterion.h +13 -0
- sgtlearn-0.1.0/cpp/src/Domain/LearningFactories.h +9 -0
- sgtlearn-0.1.0/cpp/src/Domain/SplitCandidate.h +37 -0
- sgtlearn-0.1.0/cpp/src/Estimators/ClassificationShapeGeneralizedTree.cpp +566 -0
- sgtlearn-0.1.0/cpp/src/Estimators/ClassificationShapeGeneralizedTree.h +177 -0
- sgtlearn-0.1.0/cpp/src/Estimators/RegressionShapeGeneralizedTree.cpp +640 -0
- sgtlearn-0.1.0/cpp/src/Estimators/RegressionShapeGeneralizedTree.h +174 -0
- sgtlearn-0.1.0/cpp/src/Estimators/ShapeFunctionNode.h +90 -0
- sgtlearn-0.1.0/cpp/src/Splitters/AbsoluteErrorSplitter.cpp +58 -0
- sgtlearn-0.1.0/cpp/src/Splitters/AbsoluteErrorSplitter.h +30 -0
- sgtlearn-0.1.0/cpp/src/Splitters/ClassificationSplitter.h +56 -0
- sgtlearn-0.1.0/cpp/src/Splitters/EntropySplitter.h +33 -0
- sgtlearn-0.1.0/cpp/src/Splitters/GainHessianSplitter.cpp +49 -0
- sgtlearn-0.1.0/cpp/src/Splitters/GainHessianSplitter.h +36 -0
- sgtlearn-0.1.0/cpp/src/Splitters/GiniSplitter.h +31 -0
- sgtlearn-0.1.0/cpp/src/Splitters/Splitter.h +71 -0
- sgtlearn-0.1.0/cpp/src/Splitters/Splitter.tpp +160 -0
- sgtlearn-0.1.0/cpp/src/Splitters/SplitterFactory.cpp +57 -0
- sgtlearn-0.1.0/cpp/src/Splitters/SplitterFactory.h +29 -0
- sgtlearn-0.1.0/cpp/src/Splitters/SquaredErrorSplitter.cpp +52 -0
- sgtlearn-0.1.0/cpp/src/Splitters/SquaredErrorSplitter.h +29 -0
- sgtlearn-0.1.0/cpp/src/algorithms/BinPartitionAssignments.h +55 -0
- sgtlearn-0.1.0/cpp/src/algorithms/CoordinateDescent.h +78 -0
- sgtlearn-0.1.0/cpp/src/algorithms/FeatureBagging.h +171 -0
- sgtlearn-0.1.0/cpp/src/algorithms/KMeansUtils.h +85 -0
- sgtlearn-0.1.0/cpp/src/algorithms/ShapeBranchingTypes.h +42 -0
- sgtlearn-0.1.0/cpp/src/algorithms/ShapeGeneralizedTreeParams.h +50 -0
- sgtlearn-0.1.0/cpp/src/algorithms/TreeBuilder.h +40 -0
- sgtlearn-0.1.0/cpp/src/algorithms/TreeBuilder.tpp +49 -0
- sgtlearn-0.1.0/cpp/src/algorithms/WaveletTreeMAE.cpp +474 -0
- sgtlearn-0.1.0/cpp/src/algorithms/WaveletTreeMAE.h +90 -0
- sgtlearn-0.1.0/cpp/src/algorithms/frontiers.h +46 -0
- sgtlearn-0.1.0/cpp/tests/test_branch_assignment.cpp +160 -0
- sgtlearn-0.1.0/cpp/tests/test_splitters.cpp +248 -0
- sgtlearn-0.1.0/cpp/tests/test_wavelet_tree_mae.cpp +204 -0
- sgtlearn-0.1.0/example.py +46 -0
- sgtlearn-0.1.0/examples/plot_tree_demo.py +200 -0
- sgtlearn-0.1.0/pyproject.toml +65 -0
- sgtlearn-0.1.0/setup.py +0 -0
- sgtlearn-0.1.0/sgtlearn/__init__.py +26 -0
- sgtlearn-0.1.0/sgtlearn/_export.py +662 -0
- sgtlearn-0.1.0/sgtlearn/_weights.py +64 -0
- sgtlearn-0.1.0/sgtlearn/base.py +586 -0
- sgtlearn-0.1.0/sgtlearn/datasets.py +64 -0
- sgtlearn-0.1.0/sgtlearn/ensemble/RandomSGForestClassifier.py +201 -0
- sgtlearn-0.1.0/sgtlearn/ensemble/RandomSGForestRegressor.py +159 -0
- sgtlearn-0.1.0/sgtlearn/ensemble/__init__.py +4 -0
- sgtlearn-0.1.0/sgtlearn/ensemble/_random_sgforest.py +217 -0
- sgtlearn-0.1.0/tests/discretizer_grid.py +12 -0
- sgtlearn-0.1.0/tests/test_mae_regression_stress.py +141 -0
- sgtlearn-0.1.0/tests/test_plot_helpers.py +523 -0
- sgtlearn-0.1.0/tests/test_plot_tree.py +211 -0
- sgtlearn-0.1.0/tests/test_random_sgforest_classifier_fidelity.py +237 -0
- sgtlearn-0.1.0/tests/test_random_sgforest_regressor_fidelity.py +209 -0
- sgtlearn-0.1.0/tests/test_sgt_classifier_fidelity.py +87 -0
- sgtlearn-0.1.0/tests/test_sgt_regressor_fidelity.py +103 -0
- sgtlearn-0.1.0/tests/test_tree_export.py +124 -0
- sgtlearn-0.1.0/tests/test_univariate_classification_discretizer.py +97 -0
- sgtlearn-0.1.0/tests/test_univariate_regression_discretizer.py +166 -0
- sgtlearn-0.1.0/tests/test_weighted_sample.py +364 -0
- sgtlearn-0.1.0/tree.png +0 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
tags: ["*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: ["**"]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
cpp_build_and_test:
|
|
12
|
+
name: Build & Test C++
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout repository code
|
|
17
|
+
uses: actions/checkout@v6
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.14"
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
sudo apt-get update
|
|
27
|
+
sudo apt-get install -y cmake ninja-build build-essential libopenblas-dev
|
|
28
|
+
pip install numpy
|
|
29
|
+
|
|
30
|
+
- name: Configure CMake
|
|
31
|
+
working-directory: cpp
|
|
32
|
+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DPython3_EXECUTABLE="$(which python3)"
|
|
33
|
+
|
|
34
|
+
- name: Build project
|
|
35
|
+
working-directory: cpp
|
|
36
|
+
run: cmake --build build
|
|
37
|
+
|
|
38
|
+
- name: Run unit tests
|
|
39
|
+
working-directory: cpp/build
|
|
40
|
+
run: ctest --output-on-failure
|
|
41
|
+
|
|
42
|
+
lint:
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v6
|
|
46
|
+
- uses: actions/setup-python@v5
|
|
47
|
+
with:
|
|
48
|
+
python-version: "3.14"
|
|
49
|
+
- run: pip install ruff black
|
|
50
|
+
- run: ruff check sgtlearn/
|
|
51
|
+
- run: black --check sgtlearn/
|
|
52
|
+
|
|
53
|
+
python_layer_tests:
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
strategy:
|
|
56
|
+
fail-fast: false
|
|
57
|
+
matrix:
|
|
58
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v6
|
|
61
|
+
- uses: actions/setup-python@v5
|
|
62
|
+
with:
|
|
63
|
+
python-version: ${{ matrix.python-version }}
|
|
64
|
+
- run: pip install -e ".[dev]"
|
|
65
|
+
- name: Install scikit-learn 1.8+ for exact tree fidelity (3.11+)
|
|
66
|
+
if: matrix.python-version != '3.10'
|
|
67
|
+
run: pip install "scikit-learn>=1.8"
|
|
68
|
+
- run: pytest -v
|
|
69
|
+
|
|
70
|
+
build-check:
|
|
71
|
+
runs-on: ubuntu-latest
|
|
72
|
+
steps:
|
|
73
|
+
- uses: actions/checkout@v6
|
|
74
|
+
- uses: actions/setup-python@v5
|
|
75
|
+
with:
|
|
76
|
+
python-version: "3.14"
|
|
77
|
+
- run: pip install build
|
|
78
|
+
- run: python -m build
|
|
79
|
+
|
|
80
|
+
build_wheels:
|
|
81
|
+
name: Build wheels for ${{ matrix.os }}
|
|
82
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
83
|
+
needs: [cpp_build_and_test, lint, python_layer_tests, build-check]
|
|
84
|
+
runs-on: ${{ matrix.os }}
|
|
85
|
+
strategy:
|
|
86
|
+
matrix:
|
|
87
|
+
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, windows-11-arm, macos-15-intel, macos-latest]
|
|
88
|
+
steps:
|
|
89
|
+
- uses: actions/checkout@v6
|
|
90
|
+
with:
|
|
91
|
+
submodules: true
|
|
92
|
+
persist-credentials: false
|
|
93
|
+
|
|
94
|
+
- name: Build wheels
|
|
95
|
+
uses: pypa/cibuildwheel@v3.4.1
|
|
96
|
+
with:
|
|
97
|
+
extras: uv
|
|
98
|
+
env:
|
|
99
|
+
CIBW_BUILD_FRONTEND: "build[uv]"
|
|
100
|
+
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-*"
|
|
101
|
+
CIBW_SKIP: "cp36-* cp37-* cp38-* cp39-* cp310-* pp*"
|
|
102
|
+
|
|
103
|
+
- uses: actions/upload-artifact@v4
|
|
104
|
+
with:
|
|
105
|
+
name: wheels-${{ matrix.os }}
|
|
106
|
+
path: ./wheelhouse/*.whl
|
|
107
|
+
|
|
108
|
+
build_sdist:
|
|
109
|
+
name: Build source distribution
|
|
110
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
111
|
+
needs: [cpp_build_and_test, lint, python_layer_tests, build-check]
|
|
112
|
+
runs-on: ubuntu-latest
|
|
113
|
+
steps:
|
|
114
|
+
- uses: actions/checkout@v6
|
|
115
|
+
with:
|
|
116
|
+
submodules: true
|
|
117
|
+
persist-credentials: false
|
|
118
|
+
|
|
119
|
+
- name: Build sdist
|
|
120
|
+
run: pipx run build --sdist
|
|
121
|
+
|
|
122
|
+
- uses: actions/upload-artifact@v4
|
|
123
|
+
with:
|
|
124
|
+
name: sdist
|
|
125
|
+
path: dist/*.tar.gz
|
|
126
|
+
|
|
127
|
+
publish-to-testpypi:
|
|
128
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
129
|
+
needs: [build_wheels, build_sdist]
|
|
130
|
+
name: Publish Python 🐍 distribution 📦 to TestPyPI
|
|
131
|
+
runs-on: ubuntu-latest
|
|
132
|
+
environment:
|
|
133
|
+
name: testpypi
|
|
134
|
+
url: https://test.pypi.org/p/sgtlearn
|
|
135
|
+
permissions:
|
|
136
|
+
id-token: write
|
|
137
|
+
steps:
|
|
138
|
+
- uses: actions/download-artifact@v4
|
|
139
|
+
with:
|
|
140
|
+
pattern: wheels-*
|
|
141
|
+
merge-multiple: true
|
|
142
|
+
path: dist
|
|
143
|
+
- uses: actions/download-artifact@v4
|
|
144
|
+
with:
|
|
145
|
+
name: sdist
|
|
146
|
+
path: dist
|
|
147
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
148
|
+
with:
|
|
149
|
+
repository-url: https://test.pypi.org/legacy/
|
|
150
|
+
skip-existing: true
|
|
151
|
+
|
|
152
|
+
publish-to-pypi:
|
|
153
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
154
|
+
needs: [publish-to-testpypi]
|
|
155
|
+
name: Publish Python 🐍 distribution 📦 to PyPI
|
|
156
|
+
runs-on: ubuntu-latest
|
|
157
|
+
environment:
|
|
158
|
+
name: pypi
|
|
159
|
+
url: https://pypi.org/p/sgtlearn
|
|
160
|
+
permissions:
|
|
161
|
+
id-token: write
|
|
162
|
+
steps:
|
|
163
|
+
- uses: actions/download-artifact@v4
|
|
164
|
+
with:
|
|
165
|
+
pattern: wheels-*
|
|
166
|
+
merge-multiple: true
|
|
167
|
+
path: dist
|
|
168
|
+
- uses: actions/download-artifact@v4
|
|
169
|
+
with:
|
|
170
|
+
name: sdist
|
|
171
|
+
path: dist
|
|
172
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
.DS_Store
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
.claude/
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py.cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
.python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# UV
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
uv.lock
|
|
105
|
+
|
|
106
|
+
# poetry
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
108
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
109
|
+
# commonly ignored for libraries.
|
|
110
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
111
|
+
poetry.lock
|
|
112
|
+
poetry.toml
|
|
113
|
+
|
|
114
|
+
# pdm
|
|
115
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
116
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
117
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
118
|
+
#pdm.lock
|
|
119
|
+
#pdm.toml
|
|
120
|
+
.pdm-python
|
|
121
|
+
.pdm-build/
|
|
122
|
+
|
|
123
|
+
# pixi
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
125
|
+
#pixi.lock
|
|
126
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
127
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
128
|
+
.pixi
|
|
129
|
+
|
|
130
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
131
|
+
__pypackages__/
|
|
132
|
+
|
|
133
|
+
# Celery stuff
|
|
134
|
+
celerybeat-schedule
|
|
135
|
+
celerybeat.pid
|
|
136
|
+
|
|
137
|
+
# SageMath parsed files
|
|
138
|
+
*.sage.py
|
|
139
|
+
|
|
140
|
+
# Environments
|
|
141
|
+
.env
|
|
142
|
+
.envrc
|
|
143
|
+
.venv
|
|
144
|
+
env/
|
|
145
|
+
venv/
|
|
146
|
+
ENV/
|
|
147
|
+
env.bak/
|
|
148
|
+
venv.bak/
|
|
149
|
+
|
|
150
|
+
# Spyder project settings
|
|
151
|
+
.spyderproject
|
|
152
|
+
.spyproject
|
|
153
|
+
|
|
154
|
+
# Rope project settings
|
|
155
|
+
.ropeproject
|
|
156
|
+
|
|
157
|
+
# mkdocs documentation
|
|
158
|
+
/site
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
.idea/
|
|
180
|
+
|
|
181
|
+
# Abstra
|
|
182
|
+
# Abstra is an AI-powered process automation framework.
|
|
183
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
184
|
+
# Learn more at https://abstra.io/docs
|
|
185
|
+
.abstra/
|
|
186
|
+
|
|
187
|
+
# Visual Studio Code
|
|
188
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
189
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
190
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
191
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
192
|
+
# .vscode/
|
|
193
|
+
|
|
194
|
+
# Ruff stuff:
|
|
195
|
+
.ruff_cache/
|
|
196
|
+
|
|
197
|
+
# PyPI configuration file
|
|
198
|
+
.pypirc
|
|
199
|
+
|
|
200
|
+
# Cursor
|
|
201
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
202
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
203
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
204
|
+
.cursorignore
|
|
205
|
+
.cursorindexingignore
|
|
206
|
+
|
|
207
|
+
# Marimo
|
|
208
|
+
marimo/_static/
|
|
209
|
+
marimo/_lsp/
|
|
210
|
+
__marimo__/
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
.vscode/
|
|
214
|
+
tempCodeRunnerFile.py
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# results/
|
|
218
|
+
data/
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# cpp
|
|
222
|
+
**/cmake-build-debug
|
|
223
|
+
**/cmake-build-release
|
|
224
|
+
# Accidental in-source CMake in cpp/ (always use -B cpp/cmake-build-release or similar)
|
|
225
|
+
cpp/CMakeCache.txt
|
|
226
|
+
cpp/CMakeFiles/
|
|
227
|
+
cpp/_deps/
|
|
228
|
+
cpp/Testing/
|
|
229
|
+
cpp/.cmake/
|
|
230
|
+
cpp/cmake_install.cmake
|
|
231
|
+
cpp/CTestTestfile.cmake
|
|
232
|
+
cpp/Makefile
|
|
233
|
+
cpp/build.ninja
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
sgt-learnold/
|
|
237
|
+
CLAUDE.md
|
|
238
|
+
docs/
|
sgtlearn-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nakul Upadhya, Eldan Cohen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
sgtlearn-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: sgtlearn
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shape Generalized Trees learning library
|
|
5
|
+
Author-Email: Nakul Upadhya <nakulupadhya1@gmail.com>, Joshua Lee <joshua.lee.9880@gmail.com>, Eldan Cohen <eldan.cohen@utoronto.ca>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: numpy>=1.20
|
|
12
|
+
Requires-Dist: scikit-learn>=1.3
|
|
13
|
+
Requires-Dist: joblib>=1.2
|
|
14
|
+
Requires-Dist: matplotlib>=3.10.9
|
|
15
|
+
Requires-Dist: seaborn>=0.13.2
|
|
16
|
+
Requires-Dist: graphviz>=0.21
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
19
|
+
Requires-Dist: pybind11-stubgen; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff; extra == "dev"
|
|
21
|
+
Requires-Dist: black; extra == "dev"
|
|
22
|
+
Requires-Dist: mypy; extra == "dev"
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# SGTLearn
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
`sgtlearn` is a Python package for learning [Shape Generalized Trees (SGTs)](https://neurips.cc/virtual/2025/loc/san-diego/poster/115950).
|
|
29
|
+
|
|
30
|
+
- 🌳 **Shape Generalized Trees (SGTs):** A class of decision trees where each node applies a learnable, axis-aligned shape function to a feature for non-linear and interpretable splits.
|
|
31
|
+
- 👁 **Interpretability:** Each node's shape function can be visualized directly.
|
|
32
|
+
- ⚡ **ShapeCART Algorithm:** An efficient induction method for learning SGTs from data.
|
|
33
|
+
- 🔀 **Extensions:**
|
|
34
|
+
- **Shape²GT (S²GT):** Bivariate shape functions for richer splits.
|
|
35
|
+
- **SGT<sub>K</sub>:** Multi-way branching generalization.
|
|
36
|
+
- **Shape²CART & ShapeCART<sub>K</sub>:** Algorithms for learning S²GTs and SGT<sub>K</sub>s.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install sgtlearn
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Wheels are published for CPython 3.11–3.14 on Linux, macOS, and Windows
|
|
45
|
+
(x86_64 + arm64); no compiler is needed for a binary install. To build from
|
|
46
|
+
source instead, see [Developer Setup](#developer-setup).
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from sklearn.model_selection import train_test_split
|
|
52
|
+
from sgtlearn import SGTClassifier, plot_tree, make_plus
|
|
53
|
+
|
|
54
|
+
X, y = make_plus(n_samples=1500, grid=3, margin=0.07, random_state=42)
|
|
55
|
+
|
|
56
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
57
|
+
|
|
58
|
+
model = SGTClassifier(max_depth=4, random_state=42)
|
|
59
|
+
model.fit(X_train, y_train)
|
|
60
|
+
|
|
61
|
+
plot_tree(model, X=X_train)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Developer Setup
|
|
65
|
+
|
|
66
|
+
Use a **project-local virtual environment** (`.venv`) so Python, pytest, and
|
|
67
|
+
scikit-learn stay isolated and reproducible. Pick one of the paths below
|
|
68
|
+
(`uv` is recommended). All require **Python ≥ 3.11**.
|
|
69
|
+
|
|
70
|
+
### Path 1 — `uv` (recommended)
|
|
71
|
+
|
|
72
|
+
`uv` provisions a hermetic CPython and resolves the dev extras in one step:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uv sync --all-extras
|
|
76
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Path 2 — `pip` + `venv` (editable)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python3 -m venv .venv
|
|
83
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
84
|
+
pip install -U pip
|
|
85
|
+
pip install -e ".[dev]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The editable install builds the C++ extensions via scikit-build-core and
|
|
89
|
+
installs the `sgtlearn` package plus native modules into `.venv`.
|
|
90
|
+
|
|
91
|
+
### Path 3 — `pip` non-editable (into the active environment)
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install .
|
|
95
|
+
pip install ".[dev]" # dev extras (pytest, scikit-learn) only if needed
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
> **Anaconda users:** Do not bootstrap the venv from an Anaconda Python.
|
|
99
|
+
> Anaconda ships a `libstdc++.so.6` that lags the symbol versions produced by
|
|
100
|
+
> recent system compilers (gcc ≥ 13), so the install succeeds but
|
|
101
|
+
> `import sgtlearn` fails with `ImportError: GLIBCXX_3.4.NN not found`. Use a
|
|
102
|
+
> non-Anaconda Python — e.g. `uv venv --python 3.12 .venv` (downloads a
|
|
103
|
+
> hermetic CPython), `pyenv`, or your distro's `python3`.
|
|
104
|
+
|
|
105
|
+
## Build Workflow (scikit-build + CMake)
|
|
106
|
+
|
|
107
|
+
`pip install .` drives this build path:
|
|
108
|
+
|
|
109
|
+
1. `pyproject.toml` selects `scikit_build_core.build` as the backend.
|
|
110
|
+
2. CMake is configured from `cpp/CMakeLists.txt`.
|
|
111
|
+
3. Each file in `cpp/bindings/*.cpp` becomes one pybind11 module target.
|
|
112
|
+
4. After each module is built, `pybind11-stubgen` generates a matching `.pyi`.
|
|
113
|
+
5. The `.pyi` is generated and installed in the same location as the module `.so`.
|
|
114
|
+
|
|
115
|
+
## C++ Folder Conventions
|
|
116
|
+
|
|
117
|
+
- `cpp/include/sgtlearn/`: public headers for the core C++ API.
|
|
118
|
+
- `cpp/src/`: internal C++ implementation for the core library.
|
|
119
|
+
- `cpp/bindings/`: pybind11 binding entrypoints; one `.cpp` file maps to one Python extension module.
|
|
120
|
+
- `cpp/tests/`: C++ unit tests consumed by the `cpp_tests` executable target.
|
|
121
|
+
|
|
122
|
+
## CMake Targets
|
|
123
|
+
|
|
124
|
+
- `sgtlearn_core` (static library): shared C++ logic used by Python modules and tests.
|
|
125
|
+
- `<module_name>` (pybind11 module, one per file in `cpp/bindings/`): compiled extension modules installed into the package.
|
|
126
|
+
- `cpp_tests` (Catch2 executable): optional C++ test target, controlled by:
|
|
127
|
+
- `-DSGTLEARN_BUILD_TESTS=ON` (build C++ tests)
|
|
128
|
+
- `-DSGTLEARN_BUILD_TESTS=OFF` (default for `pip install`; the CMake option itself defaults to `ON`, but `pyproject.toml` overrides this so wheels don't ship test binaries)
|
|
129
|
+
|
|
130
|
+
### Overriding CMake options from `pip`
|
|
131
|
+
|
|
132
|
+
Example (build C++ tests for one install):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install . --config-settings=cmake.args="-DSGTLEARN_BUILD_TESTS=ON"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
141
|
+
|
|
142
|
+
## Contributing
|
|
143
|
+
|
|
144
|
+
Contributions are welcome. Please feel free to submit a pull request.
|
|
145
|
+
|
|
146
|
+
## Citation
|
|
147
|
+
For the canonical code base for the paper "Empowering Decision Trees via Shape Function Branching", please refer to https://github.com/optimal-uoft/Empowering-DTs-via-Shape-Functions.
|
|
148
|
+
|
|
149
|
+
If you use this package in your research, please cite:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
@article{upadhya2026empowering,
|
|
153
|
+
title={Empowering Decision Trees via Shape Function Branching},
|
|
154
|
+
author={Upadhya, Nakul and Cohen, Eldan},
|
|
155
|
+
journal={Advances in Neural Information Processing Systems},
|
|
156
|
+
volume={38},
|
|
157
|
+
pages={122263--122308},
|
|
158
|
+
year={2026}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Additionally, check out our other works on our [lab website](https://optimal.mie.utoronto.ca/).
|