Skip to content

Commit

Permalink
Default values are now 'default'. (#87)
Browse files Browse the repository at this point in the history
* Default values are now 'default'.

* Pin extendr.

* Correct pins for extendr and libR-sys.
  • Loading branch information
mlondschien authored Jan 21, 2022
1 parent b478856 commit e1504e4
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 46 deletions.
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# Changelog

## 0.4.2 - (2021-01-21)

**Other changes:**

- The R-package now makes use of the latest version of `libR-sys`, enabling compilation for Apple silicon on `conda-forge` (#86).

**Bug fixes:**

- Fixed a bug where passing `Control()` to `changeforest` in the Python package overwrote the default value for `random_forest_max_depth` to `None`. Default values for `Control` in the python package are now `"default"` (#87).

## 0.4.1 - (2021-01-13)

**Bug fixes:**

- Upgrade `biosphere` to `0.2.1` fixing a bug in `RandomForest`.
- Upgrade `biosphere` to `0.2.1` fixing a bug in `RandomForest` (#84).

**Other changes:**

- New parameter `model_selection_n_permutations`.
- New parameter `model_selection_n_permutations` (#85).

## 0.4.0 - (2021-01-11)

**New features:**

- `changeforest` now uses random forests from [`biosphere`](https://github.com/mlondschien/biosphere).
This should be faster than `smartcore` used previously and supports parallelization.
This should be faster than `smartcore` used previously and supports parallelization (#82).

## 0.3.0 - (2021-12-15)

**New features:**

- Implemented trait `Display` for `BinarySegmentationResult`. In Python `str(result)`
now prints a pretty display (#77).
- Implemented trait `Display` for `BinarySegmentationResult`. In Python `str(result)` now prints a pretty display (#77).

**Other changes:**

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "changeforest"
description = "Classifier based non-parametric change point detection."
authors = ["Malte Londschien <malte@londschien.ch>"]
repository = "https://github.com/mlondschien/changeforest/"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
readme = "README.md"
license = "BSD-3-Clause"
Expand Down
2 changes: 1 addition & 1 deletion changeforest-py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "changeforest_py"
version = "0.4.1"
version = "0.4.2"
edition = "2021"

[lib]
Expand Down
26 changes: 15 additions & 11 deletions changeforest-py/changeforest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ class Control:

def __init__(
self,
minimal_relative_segment_length=None,
minimal_gain_to_split=None,
model_selection_alpha=None,
model_selection_n_permutations=None,
number_of_wild_segments=None,
seeded_segments_alpha=None,
seed=None,
random_forest_n_trees=None,
random_forest_max_depth=None,
random_forest_mtry=None,
random_forest_n_jobs=None,
minimal_relative_segment_length="default",
minimal_gain_to_split="default",
model_selection_alpha="default",
model_selection_n_permutations="default",
number_of_wild_segments="default",
seeded_segments_alpha="default",
seed="default",
random_forest_n_trees="default",
random_forest_max_depth="default",
random_forest_mtry="default",
random_forest_n_jobs="default",
):
self.minimal_relative_segment_length = _to_float(
minimal_relative_segment_length
Expand All @@ -37,12 +37,16 @@ def __init__(
def _to_float(value):
if value is None:
return None
if value == "default":
return "default"
else:
return float(value)


def _to_int(value):
if value is None:
return None
if value == "default":
return "default"
else:
return int(value)
2 changes: 1 addition & 1 deletion changeforest-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "changeforest"
description = "Classifier based non-parametric change point detection"
readme = "README.md"
version = "0.4.1"
version = "0.4.2"
requires-python = ">=3.7"
author = "Malte Londschien <malte@londschien.ch>"
urls = {homepage = "https://github.com/mlondschien/changeforest/"}
Expand Down
8 changes: 4 additions & 4 deletions changeforest-py/tests/test_changeforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_changeforest_repr(iris_dataset):
== """\
best_split max_gain p_value
(0, 150] 50 96.322 0.01
¦--(0, 50] 19 -6.524 1
°--(50, 150] 100 53.855 0.01
¦--(50, 100] 80 -6.793 1
°--(100, 150] 123 -7.479 1\
¦--(0, 50] 23 -10.204 1
°--(50, 150] 100 53.822 0.01
¦--(50, 100] 79 -18.63 1
°--(100, 150] 134 -10.839 1\
"""
)
35 changes: 19 additions & 16 deletions changeforest-py/tests/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ def test_control_segmentation_parameters(
assert len(result.segments) == expected_number_of_segments


def test_control_seed(iris_dataset):
result = changeforest(
iris_dataset,
"random_forest",
"wbs",
Control(seed=42, number_of_wild_segments=10),
@pytest.mark.parametrize(
"key, default_value, another_value",
[
("random_forest_n_trees", 100, 11),
("minimal_relative_segment_length", 0.1, 0.05),
("seed", 0, 1),
("random_forest_mtry", None, 1),
("random_forest_max_depth", 8, None),
],
)
def test_control_defaults(iris_dataset, key, default_value, another_value):
result = changeforest(iris_dataset, "random_forest", "bs", Control())
default_result = changeforest(
iris_dataset, "random_forest", "bs", Control(**{key: default_value})
)
assert result.segments[0].start == 5
assert abs(result.segments[0].max_gain - 11.38617) < 1e-5

result = changeforest(
iris_dataset,
"random_forest",
"wbs",
Control(seed=12, number_of_wild_segments=10),
another_result = changeforest(
iris_dataset, "random_forest", "bs", Control(**{key: another_value})
)
assert result.segments[0].start == 21
assert abs(result.segments[0].max_gain - 44.98708) < 1e-5

assert str(result) == str(default_result)
assert str(result) != str(another_result)
2 changes: 1 addition & 1 deletion changeforest-r/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: changeforest
Type: Package
Title: Classifier Based Non-Parametric Change Point Detection
Version: 0.4.1
Version: 0.4.2
Author: Malte Londschien
Maintainer: Malte Londschien <malte@londschien.ch>
Description: Perform classifier based multivariate, non-parametric change point detection.
Expand Down
6 changes: 3 additions & 3 deletions changeforest-r/src/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'changeforestr'
version = '0.4.1'
version = '0.4.2'
edition = '2021'

[lib]
Expand All @@ -13,5 +13,5 @@ changeforest = { path = "../../../" }
ndarray = "0.15.3"

[patch.crates-io]
libR-sys = { git = "https://github.com/extendr/libR-sys" }
extendr-api = { git = 'https://github.com/extendr/extendr'}
libR-sys = { git = "https://github.com/extendr/libR-sys", rev = "355cf0de0dd7f28cfa3933a70b29deb247eb2017" }
extendr-api = { git = "https://github.com/extendr/extendr", rev = "a59d65c50e001810dadba2d8624517a36b4725d2" }
3 changes: 1 addition & 2 deletions changeforest-r/tests/testthat/test-control.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ test_that("control", {
# seed
result = changeforest(X_iris, "random_forest", "wbs", Control$new(number_of_wild_segments=10, seed=42))
expect_equal(result$segments[[1]]$start, 5)
expect_equal(result$segments[[1]]$max_gain, 12.28034, tolerance=1e-5)
result = changeforest(X_iris, "random_forest", "wbs", Control$new(number_of_wild_segments=10, seed=12))
expect_equal(result$segments[[1]]$start, 21)
expect_equal(result$segments[[1]]$max_gain, 44.987, tolerance=1e-5)

# random_forest_ntree
expect_lists_equal(changeforest(X_iris, "random_forest", "bs", Control$new(random_forest_n_trees=1))$split_points(), c(47, 99))
expect_lists_equal(changeforest(X_iris, "random_forest", "bs", Control$new(random_forest_n_trees=1))$split_points(), c(37, 52, 99))
expect_lists_equal(changeforest(X_iris, "random_forest", "bs", Control$new(random_forest_n_trees=100))$split_points(), c(50, 100))
expect_lists_equal(changeforest(X, "random_forest", "bs", Control$new(random_forest_n_trees=1))$split_points(), c())
expect_lists_equal(changeforest(X, "random_forest", "bs", Control$new(random_forest_n_trees=1))$split_points(), c())
Expand Down
2 changes: 1 addition & 1 deletion src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Control {
random_forest_n_trees: 100,
random_forest_mtry: None,
random_forest_n_jobs: None,
random_forest_max_depth: Some(4),
random_forest_max_depth: Some(8),
}
}

Expand Down

0 comments on commit e1504e4

Please sign in to comment.