-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27f9798
commit 4728e87
Showing
20 changed files
with
43,673 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .systems import * | ||
from .surrogates import * | ||
from .surrogates import * | ||
from .hyperplanetree import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# hyperplanetree | ||
A Python library to build piecewise linear or piecewise quadratic models in multi-dimensional spaces. | ||
|
||
This code is a fork of [linear-tree](https://github.com/cerlymarco/linear-tree). Please see this repository for more information about Linear Model Decision Trees! | ||
|
||
## What does this fork include? | ||
|
||
The main features of this fork (compared to upstream) are as follows: | ||
|
||
1. Translate the mathematics of linear-tree into PyTorch tensor operations. This is roughly 1.5-2.5x faster on CPU and enables GPU calculations. (The exact speedup is highly dependent on your dataset, model hyperparameter choices, and probably even your CPU.) | ||
2. HyperplaneTree: Hyperplanes (linear combinations of features) are considered as splitting variables. This significantly increases the training cost of the tree, which motivated the PyTorch rewrite. | ||
3. "Mixed-integer linear program" (MIP) formulations for hyperplane trees via [OMLT](https://github.com/cog-imperial/OMLT) and [Pyomo](https://pyomo.org). | ||
|
||
## Installation | ||
This package can be installed as part of systems2atoms: | ||
|
||
```pip install git+https://github.com/LLNL/systems2atoms``` | ||
|
||
Then, it can be imported as follows: | ||
|
||
```python | ||
from systems2atoms.hyperplanetree import LinearTreeRegressor, HyperplaneTreeRegressor | ||
``` | ||
|
||
Alternatively, you can install hyperplanetree without installing the rest of systems2atoms: | ||
|
||
```pip install "hyperplanetree @ git+https://[email protected]/LLNL/systems2atoms#subdirectory=systems2atoms/hyperplanetree"``` | ||
|
||
The import will then be: | ||
|
||
```python | ||
from hyperplanetree import LinearTreeRegressor, HyperplaneTreeRegressor | ||
``` | ||
|
||
## Quickstart | ||
Please see the notebooks folder for basic tutorials on these models. | ||
|
||
## Why Hyperplanes? | ||
TLDR: Expanding the search space of possible splits can allow us to build trees with better accuracy for the same number of leaves. | ||
|
||
We use leaf-model decision trees as surrogates in optimization problems. See: [Ammari et al. Linear model decision trees as surrogates in optimization of engineering applications](https://www.sciencedirect.com/science/article/pii/S009813542300217X) | ||
|
||
Expanding the search space of possible splits can allow us to build trees with better accuracy for the same number of leaves. This is useful because when we translate the trees to optimization problems (via OMLT and Pyomo), each leaf becomes a binary variable. Optimization problems generally have poor scaling with the number of binary variables, so we cannot endlessly deepen our trees to achieve high accuracy. | ||
|
||
Hyperplanes are specifically useful because they are linear. When converted to optimization constraints, the problem will still be linear: a Mixed-Integer Linear Problem (MIP). | ||
|
||
To further increase the accuracy of our models, we can also use quadratic terms in the splits and leaf regressions. This turns the problem into a Mixed-Integer Quadratic Constrained Problem (MIQCP). Quadric Trees are implemented as an experimental feature in this repository. We have not yet seen enough error metric improvement from these models to justify their use. | ||
|
||
Further increases in model complexity are possible. However, they are not implemented here as they quickly become computationally impractical even for small regression tasks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .hyperplanetree.lineartree import ( | ||
LinearTreeRegressor, | ||
) | ||
|
||
from .hyperplanetree.hyperplane_tree import ( | ||
HyperplaneTreeRegressor, | ||
) | ||
|
||
from .hyperplanetree.quadric_tree import ( | ||
QuadricTreeRegressor, | ||
) | ||
|
||
from .hyperplanetree.omlt import ( | ||
HyperplaneTreeDefinition, | ||
HyperplaneTreeGDPFormulation, | ||
HyperplaneTreeHybridBigMFormulation, | ||
HyperplaneTreeOMLTFormulationMixin, | ||
) | ||
|
||
from .hyperplanetree.uq import ( | ||
calculate_uncertainty_metrics, | ||
) | ||
|
||
from .hyperplanetree._classes import ( | ||
plot_surrogate_2d, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .lineartree import ( | ||
LinearTreeRegressor, | ||
) | ||
|
||
from .hyperplane_tree import ( | ||
HyperplaneTreeRegressor, | ||
) | ||
|
||
from .quadric_tree import ( | ||
QuadricTreeRegressor, | ||
) | ||
|
||
from .omlt import ( | ||
HyperplaneTreeDefinition, | ||
HyperplaneTreeGDPFormulation, | ||
HyperplaneTreeHybridBigMFormulation, | ||
HyperplaneTreeOMLTFormulationMixin, | ||
) | ||
|
||
from .uq import ( | ||
calculate_uncertainty_metrics, | ||
) | ||
|
||
from ._classes import ( | ||
plot_surrogate_2d, | ||
) |
Oops, something went wrong.