Skip to content

Commit

Permalink
timeout added
Browse files Browse the repository at this point in the history
  • Loading branch information
deadsoul44 committed Oct 18, 2024
1 parent be869b1 commit e5f933a
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
windows-build-test:
strategy:
matrix:
pyversion: ["3.8", "3.9", "3.10", "3.11", "3.12"]
pyversion: ["3.9", "3.10", "3.11", "3.12"]
runs-on: "windows-latest"
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
pyversion: ["3.8", "3.9", "3.10", "3.11", "3.12"]
pyversion: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Install latests stable Rust
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "perpetual"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
authors = ["Mutlu Simsek <[email protected]>"]
homepage = "https://perpetual-ml.com"
Expand All @@ -22,7 +22,7 @@ codegen-units = 1
[dependencies]
rayon = "1.8"
thiserror = "1.0.64"
serde_json = { version = "1.0.127", features = ["float_roundtrip"] }
serde_json = { version = "1.0.129", features = ["float_roundtrip"] }
serde = { version = "1.0.209", features = ["derive"] }
approx = "0.5"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pip install perpetual
To use in a Rust project, add the following to your Cargo.toml file to get the package from [crates.io](https://crates.io/crates/perpetual).

```toml
perpetual = "0.5.1"
perpetual = "0.5.2"
```

## Paper
Expand Down
4 changes: 3 additions & 1 deletion benches/perpetual_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn tree_benchmarks(c: &mut Criterion) {
black_box(0.3),
black_box(None),
black_box(None),
black_box(None),
)
.unwrap();
})
Expand All @@ -173,12 +174,13 @@ pub fn tree_benchmarks(c: &mut Criterion) {
black_box(0.3),
black_box(None),
black_box(None),
black_box(None),
)
.unwrap();
})
});
let mut booster = PerpetualBooster::default();
booster.fit(&data, &y, None, None, 0.3, None, None).unwrap();
booster.fit(&data, &y, None, None, 0.1, None, None, None).unwrap();
booster_train.bench_function("Predict Booster", |b| {
b.iter(|| booster.predict(black_box(&data), false))
});
Expand Down
2 changes: 1 addition & 1 deletion examples/cal_housing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.set_num_threads(Some(*num_threads));

let now = SystemTime::now();
model.fit(&matrix_train, &y_train, None, None, *budget, None, None)?;
model.fit(&matrix_train, &y_train, None, None, *budget, None, None, None)?;
println!("now.elapsed: {:?}", now.elapsed().unwrap().as_secs_f32());

let trees = model.get_prediction_trees();
Expand Down
2 changes: 1 addition & 1 deletion examples/cover_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.map(|y| if (*y as i32) == i { 1.0 } else { 0.0 })
.collect();

model.fit(&matrix_train, &y_tr, None, None, *budget, None, None)?;
model.fit(&matrix_train, &y_tr, None, None, *budget, None, None, None)?;
println!("Completed fitting model number: {}", i);

let trees = model.get_prediction_trees();
Expand Down
2 changes: 1 addition & 1 deletion examples/titanic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// the relevant `set_` methods for any parameters you would like to
// adjust.
let mut model = PerpetualBooster::default().set_objective(Objective::LogLoss);
model.fit(&matrix, &y, None, None, *budget, None, None)?;
model.fit(&matrix, &y, None, None, *budget, None, None, None)?;

println!("Model prediction: {:?} ...", &model.predict(&matrix, true)[0..10]);

Expand Down
6 changes: 3 additions & 3 deletions python-package/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "py-perpetual"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
authors = ["Mutlu Simsek <[email protected]>"]
homepage = "https://perpetual-ml.com"
Expand All @@ -18,8 +18,8 @@ name = "perpetual"
crate-type = ["cdylib", "rlib"]

[dependencies]
pyo3 = { version = "0.22.4", features = ["extension-module"] }
perpetual_rs = {package="perpetual", version = "0.5.1", path = "../" }
pyo3 = { version = "0.22.5", features = ["extension-module"] }
perpetual_rs = {package="perpetual", version = "0.5.2", path = "../" }
numpy = "0.22.0"
ndarray = "0.16.1"
serde_plain = { version = "1.0" }
Expand Down
124 changes: 0 additions & 124 deletions python-package/examples/openml_cnae.ipynb

This file was deleted.

86 changes: 86 additions & 0 deletions python-package/examples/openml_mnist.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from perpetual import PerpetualBooster"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"\n",
"logging.basicConfig()\n",
"logging.getLogger().setLevel(logging.DEBUG)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"X_train = pd.read_csv(\"../../resources/fashion_train_flat.csv\", index_col=False, header=None).to_numpy().reshape(63000, -1)\n",
"X_train.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"y_train = pd.read_csv(\"../../resources/fashion_train_y.csv\", index_col=False, header=None).to_numpy().flatten()\n",
"y_train.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = PerpetualBooster(log_iterations=1)\n",
"model.fit(X_train, y_train, budget=1.0, timeout=360)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model.number_of_trees"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "py311",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
5 changes: 2 additions & 3 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "perpetual"
version = "0.5.1"
version = "0.5.2"
description = "A self-generalizing gradient boosting machine which doesn't need hyperparameter optimization"
license = { file = "LICENSE" }
keywords = [
Expand All @@ -19,11 +19,10 @@ keywords = [
authors = [{ name = "Mutlu Simsek" }]
readme = "README.md"
dependencies = ["numpy", "typing-extensions"]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
3 changes: 3 additions & 0 deletions python-package/python/perpetual/booster.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def fit(
alpha: Union[float, None] = None,
reset: Union[bool, None] = None,
categorical_features: Union[Iterable[int], Iterable[str], str, None] = "auto",
timeout: Union[float, None] = None,
) -> Self:
"""Fit the gradient booster on a provided dataset.
Expand All @@ -172,6 +173,7 @@ def fit(
reset: whether to reset the model or continue training.
categorical_features: The names or indices for categorical features.
`auto` for Polars or Pandas categorical data type.
timeout: optional fit timeout in seconds
"""

features_, flat_data, rows, cols, categorical_features_, cat_mapping = (
Expand Down Expand Up @@ -244,6 +246,7 @@ def fit(
alpha=alpha,
reset=reset,
categorical_features=categorical_features_, # type: ignore
timeout=timeout,
)

return self
Expand Down
15 changes: 11 additions & 4 deletions python-package/src/booster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl PerpetualBooster {
alpha: Option<f32>,
reset: Option<bool>,
categorical_features: Option<HashSet<usize>>,
timeout: Option<f32>,
) -> PyResult<()> {
let flat_data = flat_data.as_slice()?;
let data = Matrix::new(flat_data, rows, cols);
Expand All @@ -152,10 +153,16 @@ impl PerpetualBooster {
None => None,
};

match self
.booster
.fit(&data, y, sample_weight_, alpha, budget, reset, categorical_features)
{
match self.booster.fit(
&data,
y,
sample_weight_,
alpha,
budget,
reset,
categorical_features,
timeout,
) {
Ok(m) => Ok(m),
Err(e) => Err(PyValueError::new_err(e.to_string())),
}?;
Expand Down
Loading

0 comments on commit e5f933a

Please sign in to comment.