Constraint

ReHLine allows you to impose various linear constraints on the model coefficients.

Usage Pattern

Define constraints as a list of dictionaries:

# list of constraint dictionaries
constraint = [{'name': <constraint_name>, **kwargs}, ...]

Supported Constraints

Non-negative

Constrains all coefficients to be non-negative (\(\beta_j \ge 0\)) [1].

  • Names: 'nonnegative', '>=0'

  • Parameters: None

constraint = [{'name': '>=0'}]

Related Example

Fairness

Constrains the correlation between predictions and sensitive attributes to be within a tolerance [2].

  • Names: 'fair', 'fairness'

  • Parameters:
    • sen_idx (list of int): Column indices of sensitive attributes in X.

    • tol_sen (list of float): Tolerance thresholds for each sensitive attribute.

# Example: Constrain fairness w.r.t. feature at index 0 with tolerance 0.01
constraint = [{'name': 'fair', 'sen_idx': [0], 'tol_sen': [0.01]}]

Related Example

Monotonicity

Constrains coefficients to be monotonically increasing or decreasing [3]. Increasing: \(\beta_i \le \beta_{i+1}\). Decreasing: \(\beta_i \ge \beta_{i+1}\).

  • Names: 'monotonic', 'monotonicity'

  • Parameters:
    • decreasing (bool, default=False): If True, enforces decreasing monotonicity.

# Monotonically increasing
constraint = [{'name': 'monotonic'}]

# Monotonically decreasing
constraint = [{'name': 'monotonic', 'decreasing': True}]

Custom Constraints

Define arbitrary linear constraints of the form \(A\beta + b \ge 0\).

  • Names: 'custom'

  • Parameters:
    • A (ndarray): Coefficient matrix of shape (K, d).

    • b (ndarray): Intercept vector of shape (K,).

import numpy as np

# Example: beta_0 + beta_1 >= 1
A = np.zeros((1, d))
A[0, 0] = 1
A[0, 1] = 1
b = np.array([-1.0])

constraint = [{'name': 'custom', 'A': A, 'b': b}]

References