Skip to content

Commit

Permalink
Set bounds on output variables of decision trees
Browse files Browse the repository at this point in the history
  • Loading branch information
pobonomo committed Jan 8, 2025
1 parent da47d0d commit 3b73ca1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gurobi_ml/modeling/decision_tree/decision_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _leaf_formulation(
# We should attain 1 leaf
gp_model.addConstr(leafs_vars.sum(axis=1) == 1)

gp_model.addConstr(output <= np.max(tree["value"], axis=0))
gp_model.addConstr(output >= np.min(tree["value"], axis=0))
if verbose:
timer.timing(f"Added {nex} linear constraints")

Expand Down Expand Up @@ -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"], axis=0))
output.UB = np.minimum(output.UB, np.max(tree["value"], axis=0))


class AbstractTreeEstimator(AbstractPredictorConstr):
Expand Down

0 comments on commit 3b73ca1

Please sign in to comment.