Skip to content

Commit

Permalink
fix(RandomForest): Always cast seed to int (#1084)
Browse files Browse the repository at this point in the history
* fix(RandomForest): Always cast `seed` to `int`

In cases where seeds were generated from some numpy objects, sometimes
you'd get back an `np.integer`, which causes the program to crash when
communicating with `pyrfr` through `swig`. It seems that swig doesn't
know that it's an _int-like_ and so we explicitly cast it to `int`.

* Update CHANGELOG.md

---------

Co-authored-by: C. Benjamins <[email protected]>
  • Loading branch information
eddiebergman and benjamc authored Nov 21, 2023
1 parent 06d584f commit 3852013
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix path for dask scheduler file (#1055).
- Add OrdinalHyperparameter for random forest imputer (#1065).
- Configurations that fail to become incumbents will be added to the rejected lists (#1069).
- SMAC RandomForest doesn't crash when `np.integer` used, i.e. as generated from a `np.random.RandomState` (#1084).

# 2.0.2

Expand Down
4 changes: 3 additions & 1 deletion smac/model/random_forest/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def __init__(
self._rf_opts.compute_law_of_total_variance = False
self._rf: BinaryForest | None = None
self._log_y = log_y
self._rng = regression.default_random_engine(seed)

# Case to `int` incase we get an `np.integer` type
self._rng = regression.default_random_engine(int(seed))

self._n_trees = n_trees
self._n_points_per_tree = n_points_per_tree
Expand Down

0 comments on commit 3852013

Please sign in to comment.