arborenum 0.2.4__tar.gz → 0.2.6__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.
- {arborenum-0.2.4/src/arborenum.egg-info → arborenum-0.2.6}/PKG-INFO +1 -1
- {arborenum-0.2.4 → arborenum-0.2.6}/pyproject.toml +1 -1
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum/__init__.py +115 -5
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum/_core.cpp +52 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum/cpp/arborenum.cpp +1503 -188
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum/cpp/rid.cpp +44 -13
- {arborenum-0.2.4 → arborenum-0.2.6/src/arborenum.egg-info}/PKG-INFO +1 -1
- {arborenum-0.2.4 → arborenum-0.2.6}/MANIFEST.in +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/README.md +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/setup.cfg +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/setup.py +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum/_threshold_guessing.py +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum.egg-info/SOURCES.txt +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum.egg-info/dependency_links.txt +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum.egg-info/requires.txt +0 -0
- {arborenum-0.2.4 → arborenum-0.2.6}/src/arborenum.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "arborenum"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.6"
|
|
8
8
|
description = "Exact, approximate, and anytime decision tree Rashomon sets over binary and continuous features"
|
|
9
9
|
requires-python = ">=3.9"
|
|
10
10
|
dependencies = [
|
|
@@ -776,6 +776,7 @@ class ArborEnum:
|
|
|
776
776
|
self.multiplicative_slack_ = float(multiplicative_slack)
|
|
777
777
|
self.lookahead_k_ = int(lookahead_k)
|
|
778
778
|
self.eta_defer_ = float(eta_defer)
|
|
779
|
+
self._model.set_additive(bool(additive))
|
|
779
780
|
|
|
780
781
|
if X_initial is None:
|
|
781
782
|
if early_stopping and X_num.shape[1] > 0:
|
|
@@ -856,8 +857,7 @@ class ArborEnum:
|
|
|
856
857
|
memory_limit_mb=memory_limit_mb,
|
|
857
858
|
use_deferral=use_deferral,
|
|
858
859
|
eta_defer=eta_defer,
|
|
859
|
-
additive=additive,
|
|
860
|
-
|
|
860
|
+
additive=additive,
|
|
861
861
|
)
|
|
862
862
|
|
|
863
863
|
return self.fit_prepared(
|
|
@@ -890,7 +890,6 @@ class ArborEnum:
|
|
|
890
890
|
stronger_rollout=stronger_rollout,
|
|
891
891
|
use_deferral=use_deferral,
|
|
892
892
|
eta_defer=eta_defer,
|
|
893
|
-
additive=additive,
|
|
894
893
|
)
|
|
895
894
|
|
|
896
895
|
|
|
@@ -1363,6 +1362,8 @@ class ArborEnum:
|
|
|
1363
1362
|
|
|
1364
1363
|
key_mode_parsed = parse_key_mode(key_mode)
|
|
1365
1364
|
|
|
1365
|
+
self._model.set_additive(bool(additive))
|
|
1366
|
+
|
|
1366
1367
|
self._model.fit_then_extend(
|
|
1367
1368
|
X,
|
|
1368
1369
|
y,
|
|
@@ -1394,7 +1395,6 @@ class ArborEnum:
|
|
|
1394
1395
|
bool(use_deferral),
|
|
1395
1396
|
float(eta_defer),
|
|
1396
1397
|
bb_pred_vec,
|
|
1397
|
-
bool(additive)
|
|
1398
1398
|
)
|
|
1399
1399
|
|
|
1400
1400
|
return self
|
|
@@ -1434,6 +1434,7 @@ class ArborEnum:
|
|
|
1434
1434
|
use_deferral=False,
|
|
1435
1435
|
eta_defer=0.0,
|
|
1436
1436
|
bb_pred=None,
|
|
1437
|
+
additive=False,
|
|
1437
1438
|
):
|
|
1438
1439
|
X = np.asarray(X, dtype=np.uint8)
|
|
1439
1440
|
y = np.asarray(y, dtype=int)
|
|
@@ -1554,6 +1555,8 @@ class ArborEnum:
|
|
|
1554
1555
|
)
|
|
1555
1556
|
key_mode_parsed = parse_key_mode(key_mode)
|
|
1556
1557
|
|
|
1558
|
+
self._model.set_additive(bool(additive))
|
|
1559
|
+
|
|
1557
1560
|
self._model.fit_anytime(
|
|
1558
1561
|
X,
|
|
1559
1562
|
y,
|
|
@@ -1946,6 +1949,8 @@ class ArborEnum:
|
|
|
1946
1949
|
|
|
1947
1950
|
key_mode_parsed = parse_key_mode(key_mode)
|
|
1948
1951
|
|
|
1952
|
+
self._model.set_additive(bool(additive))
|
|
1953
|
+
|
|
1949
1954
|
self._model.fit_prepared_then_extend(
|
|
1950
1955
|
float(lambda_reg),
|
|
1951
1956
|
int(depth_budget),
|
|
@@ -1972,7 +1977,6 @@ class ArborEnum:
|
|
|
1972
1977
|
float(memory_limit_mb),
|
|
1973
1978
|
bool(use_deferral),
|
|
1974
1979
|
float(eta_defer),
|
|
1975
|
-
bool(additive)
|
|
1976
1980
|
)
|
|
1977
1981
|
|
|
1978
1982
|
return self
|
|
@@ -2008,6 +2012,7 @@ class ArborEnum:
|
|
|
2008
2012
|
memory_limit_mb=-1.0,
|
|
2009
2013
|
use_deferral=False,
|
|
2010
2014
|
eta_defer=0.0,
|
|
2015
|
+
additive=False,
|
|
2011
2016
|
):
|
|
2012
2017
|
rashomon_mult = float(rashomon_mult)
|
|
2013
2018
|
|
|
@@ -2065,6 +2070,8 @@ class ArborEnum:
|
|
|
2065
2070
|
|
|
2066
2071
|
key_mode_parsed = parse_key_mode(key_mode)
|
|
2067
2072
|
|
|
2073
|
+
self._model.set_additive(bool(additive))
|
|
2074
|
+
|
|
2068
2075
|
self._model.fit_prepared_anytime(
|
|
2069
2076
|
float(lambda_reg),
|
|
2070
2077
|
int(depth_budget),
|
|
@@ -2276,6 +2283,109 @@ class ArborEnum:
|
|
|
2276
2283
|
copy=False,
|
|
2277
2284
|
)
|
|
2278
2285
|
|
|
2286
|
+
def get_exact_replacement_importance_intervals(
|
|
2287
|
+
self,
|
|
2288
|
+
X_eval,
|
|
2289
|
+
y_eval,
|
|
2290
|
+
budget_override=None,
|
|
2291
|
+
):
|
|
2292
|
+
"""
|
|
2293
|
+
Exact global [min, max] subtractive model-reliance interval
|
|
2294
|
+
over the fitted Rashomon set, evaluated on X_eval, y_eval.
|
|
2295
|
+
X_eval may be completely different from the training data.
|
|
2296
|
+
"""
|
|
2297
|
+
|
|
2298
|
+
if self.n_features_in_ is None:
|
|
2299
|
+
raise RuntimeError("Fit the model first.")
|
|
2300
|
+
|
|
2301
|
+
X_internal = np.ascontiguousarray(
|
|
2302
|
+
self.transform(X_eval),
|
|
2303
|
+
dtype=np.uint8,
|
|
2304
|
+
)
|
|
2305
|
+
|
|
2306
|
+
y_eval = np.ascontiguousarray(
|
|
2307
|
+
np.asarray(y_eval, dtype=np.int32)
|
|
2308
|
+
)
|
|
2309
|
+
|
|
2310
|
+
if y_eval.ndim != 1:
|
|
2311
|
+
raise ValueError("y_eval must be 1D.")
|
|
2312
|
+
|
|
2313
|
+
if y_eval.shape[0] != X_internal.shape[0]:
|
|
2314
|
+
raise ValueError(
|
|
2315
|
+
"y_eval must have the same number of rows as X_eval."
|
|
2316
|
+
)
|
|
2317
|
+
|
|
2318
|
+
# map each original feature to its internal threshold columns.
|
|
2319
|
+
variable_columns = [
|
|
2320
|
+
[] for _ in range(self.n_features_in_)
|
|
2321
|
+
]
|
|
2322
|
+
|
|
2323
|
+
# low-cardinality features created directly in python.
|
|
2324
|
+
for internal_feature, spec in enumerate(
|
|
2325
|
+
self.binary_feature_specs_
|
|
2326
|
+
):
|
|
2327
|
+
original_feature = int(spec["original_feature"])
|
|
2328
|
+
variable_columns[original_feature].append(
|
|
2329
|
+
int(internal_feature)
|
|
2330
|
+
)
|
|
2331
|
+
|
|
2332
|
+
# continuous threshold groups created in cpp
|
|
2333
|
+
starts = self.get_continuous_starts()
|
|
2334
|
+
|
|
2335
|
+
for group, original_feature in enumerate(
|
|
2336
|
+
self.continuous_feature_indices_
|
|
2337
|
+
):
|
|
2338
|
+
original_feature = int(original_feature)
|
|
2339
|
+
|
|
2340
|
+
start = int(starts[group])
|
|
2341
|
+
end = int(self.get_continuous_group_end(group))
|
|
2342
|
+
|
|
2343
|
+
variable_columns[original_feature].extend(
|
|
2344
|
+
range(start, end)
|
|
2345
|
+
)
|
|
2346
|
+
|
|
2347
|
+
# constant training features have no internal columns and
|
|
2348
|
+
# therefore importance exactly zero for every fitted tree.
|
|
2349
|
+
active_features = [
|
|
2350
|
+
j
|
|
2351
|
+
for j, cols in enumerate(variable_columns)
|
|
2352
|
+
if cols
|
|
2353
|
+
]
|
|
2354
|
+
|
|
2355
|
+
active_variable_columns = [
|
|
2356
|
+
variable_columns[j]
|
|
2357
|
+
for j in active_features
|
|
2358
|
+
]
|
|
2359
|
+
|
|
2360
|
+
budget = (
|
|
2361
|
+
-1
|
|
2362
|
+
if budget_override is None
|
|
2363
|
+
else int(budget_override)
|
|
2364
|
+
)
|
|
2365
|
+
|
|
2366
|
+
active_intervals = np.asarray(
|
|
2367
|
+
self._model
|
|
2368
|
+
.get_exact_replacement_importance_intervals_packed_trie(
|
|
2369
|
+
X_internal,
|
|
2370
|
+
y_eval,
|
|
2371
|
+
budget,
|
|
2372
|
+
active_variable_columns,
|
|
2373
|
+
np.empty(0, dtype=np.int32),
|
|
2374
|
+
False, # global min/max, not per-sample
|
|
2375
|
+
),
|
|
2376
|
+
dtype=float,
|
|
2377
|
+
)
|
|
2378
|
+
|
|
2379
|
+
intervals = np.zeros(
|
|
2380
|
+
(self.n_features_in_, 2),
|
|
2381
|
+
dtype=float,
|
|
2382
|
+
)
|
|
2383
|
+
|
|
2384
|
+
if active_features:
|
|
2385
|
+
intervals[active_features] = active_intervals
|
|
2386
|
+
|
|
2387
|
+
return intervals
|
|
2388
|
+
|
|
2279
2389
|
|
|
2280
2390
|
# WARNING: 1-indexed unlike features
|
|
2281
2391
|
def get_tree_paths(self, tree_index: int):
|
|
@@ -2060,6 +2060,58 @@ PYBIND11_MODULE(_core, m) {
|
|
|
2060
2060
|
"continuous feature group."
|
|
2061
2061
|
)
|
|
2062
2062
|
|
|
2063
|
+
.def(
|
|
2064
|
+
"get_exact_replacement_importance_intervals_packed_trie",
|
|
2065
|
+
[](const ArborEnum& self,
|
|
2066
|
+
py::array_t<
|
|
2067
|
+
uint8_t,
|
|
2068
|
+
py::array::c_style | py::array::forcecast
|
|
2069
|
+
> X_eval,
|
|
2070
|
+
py::array_t<
|
|
2071
|
+
int,
|
|
2072
|
+
py::array::c_style | py::array::forcecast
|
|
2073
|
+
> y_eval,
|
|
2074
|
+
int budget_override,
|
|
2075
|
+
const std::vector<std::vector<int>>& variable_columns,
|
|
2076
|
+
py::array_t<
|
|
2077
|
+
int,
|
|
2078
|
+
py::array::c_style | py::array::forcecast
|
|
2079
|
+
> bb_pred_eval,
|
|
2080
|
+
bool sum_samplewise_extrema) {
|
|
2081
|
+
|
|
2082
|
+
auto X_vec =
|
|
2083
|
+
numpy_uint8_2d_to_row_major(X_eval, "X_eval");
|
|
2084
|
+
|
|
2085
|
+
auto y_vec =
|
|
2086
|
+
numpy_int_1d_to_vector(y_eval, "y_eval");
|
|
2087
|
+
|
|
2088
|
+
auto bb_vec =
|
|
2089
|
+
numpy_int_1d_to_vector(
|
|
2090
|
+
bb_pred_eval,
|
|
2091
|
+
"bb_pred_eval"
|
|
2092
|
+
);
|
|
2093
|
+
|
|
2094
|
+
return self
|
|
2095
|
+
.get_exact_replacement_importance_intervals_packed_trie(
|
|
2096
|
+
X_vec,
|
|
2097
|
+
y_vec,
|
|
2098
|
+
budget_override,
|
|
2099
|
+
variable_columns,
|
|
2100
|
+
bb_vec,
|
|
2101
|
+
{}, // matched_group_of_row_by_variable_eval
|
|
2102
|
+
{}, // matched_group_size_by_variable_eval
|
|
2103
|
+
sum_samplewise_extrema
|
|
2104
|
+
);
|
|
2105
|
+
},
|
|
2106
|
+
py::arg("X_eval"),
|
|
2107
|
+
py::arg("y_eval"),
|
|
2108
|
+
py::arg("budget_override") = -1,
|
|
2109
|
+
py::arg("variable_columns") =
|
|
2110
|
+
std::vector<std::vector<int>>{},
|
|
2111
|
+
py::arg("bb_pred_eval") = py::array_t<int>(0),
|
|
2112
|
+
py::arg("sum_samplewise_extrema") = false
|
|
2113
|
+
)
|
|
2114
|
+
|
|
2063
2115
|
|
|
2064
2116
|
.def(
|
|
2065
2117
|
"training_samples_with_multiple_reachable_predictions",
|