From 1b79941ebba45f1db0a5be3cfb11f51b63862d5e Mon Sep 17 00:00:00 2001 From: Pierre Bonami Date: Wed, 8 Jan 2025 09:50:18 +0100 Subject: [PATCH] Set bounds on output variables of decision trees --- src/gurobi_ml/modeling/decision_tree/decision_tree_model.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gurobi_ml/modeling/decision_tree/decision_tree_model.py b/src/gurobi_ml/modeling/decision_tree/decision_tree_model.py index c8f1e7cb..70c41615 100644 --- a/src/gurobi_ml/modeling/decision_tree/decision_tree_model.py +++ b/src/gurobi_ml/modeling/decision_tree/decision_tree_model.py @@ -128,6 +128,8 @@ def _leaf_formulation( if verbose: timer.timing(f"Added {nex} linear constraints") + output.LB = np.maximum(output.LB, np.min(tree["value"])) + output.UB = np.minimum(output.UB, np.max(tree["value"])) def _paths_formulation(gp_model, _input, output, tree, epsilon, _name_var): @@ -207,8 +209,8 @@ def _paths_formulation(gp_model, _input, output, tree, epsilon, _name_var): for i in range(outdim) ) - output.LB = np.min(tree.value) - output.UB = np.max(tree.value) + output.LB = np.maximum(output.LB, np.min(tree["value"])) + output.UB = np.minimum(output.UB, np.max(tree["value"])) class AbstractTreeEstimator(AbstractPredictorConstr):