Skip to content

Commit fad551c

Browse files
Use epsilon as a parameter when solving least core optimization problems
1 parent 884fe73 commit fad551c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/pydvl/value/least_core/_common.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def _solve_least_core_linear_program(
1919
b_eq: NDArray[np.float_],
2020
A_lb: NDArray[np.float_],
2121
b_lb: NDArray[np.float_],
22+
*,
23+
epsilon: float = 0.0,
2224
**options,
2325
) -> Tuple[Optional[NDArray[np.float_]], Optional[float]]:
2426
"""Solves the Least Core's linear program using cvxopt.
@@ -44,6 +46,7 @@ def _solve_least_core_linear_program(
4446
coefficients of a linear inequality constraint on ``x``.
4547
:param b_lb: The inequality constraint vector. Each element represents a
4648
lower bound on the corresponding value of ``A_lb @ x``.
49+
:param epsilon: Relaxation value by which the subset utility is decreased.
4750
:param options: Keyword arguments that will be used to select a solver
4851
and to configure it. For all possible options, refer to `cvxpy's documentation
4952
<https://www.cvxpy.org/tutorial/advanced/index.html#setting-solver-options>`_
@@ -54,11 +57,13 @@ def _solve_least_core_linear_program(
5457

5558
x = cp.Variable(n_variables)
5659
e = cp.Variable()
60+
epsilon_parameter = cp.Parameter(name="epsilon", nonneg=True, value=epsilon)
61+
5762
objective = cp.Minimize(e)
5863
constraints = [
5964
e >= 0,
6065
A_eq @ x == b_eq,
61-
A_lb @ x + e * np.ones(len(A_lb)) >= b_lb,
66+
(A_lb @ x + e * np.ones(len(A_lb))) >= (b_lb - epsilon_parameter),
6267
]
6368
problem = cp.Problem(objective, constraints)
6469

@@ -105,6 +110,7 @@ def _solve_egalitarian_least_core_quadratic_program(
105110
b_eq: NDArray[np.float_],
106111
A_lb: NDArray[np.float_],
107112
b_lb: NDArray[np.float_],
113+
epsilon: float = 0.0,
108114
**options,
109115
) -> Optional[NDArray[np.float_]]:
110116
"""Solves the egalitarian Least Core's quadratic program using cvxopt.
@@ -131,6 +137,7 @@ def _solve_egalitarian_least_core_quadratic_program(
131137
coefficients of a linear inequality constraint on ``x``.
132138
:param b_lb: The inequality constraint vector. Each element represents a
133139
lower bound on the corresponding value of ``A_lb @ x``.
140+
:param epsilon: Relaxation value by which the subset utility is decreased.
134141
:param options: Keyword arguments that will be used to select a solver
135142
and to configure it. Refer to the following page for all possible options:
136143
https://www.cvxpy.org/tutorial/advanced/index.html#setting-solver-options
@@ -143,10 +150,12 @@ def _solve_egalitarian_least_core_quadratic_program(
143150
n_variables = A_eq.shape[1]
144151

145152
x = cp.Variable(n_variables)
153+
epsilon_parameter = cp.Parameter(name="epsilon", nonneg=True, value=epsilon)
154+
146155
objective = cp.Minimize(cp.norm2(x))
147156
constraints = [
148157
A_eq @ x == b_eq,
149-
A_lb @ x + subsidy * np.ones(len(A_lb)) >= b_lb,
158+
(A_lb @ x + subsidy * np.ones(len(A_lb))) >= (b_lb - epsilon_parameter),
150159
]
151160
problem = cp.Problem(objective, constraints)
152161

src/pydvl/value/least_core/montecarlo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def montecarlo_least_core(
156156
)
157157

158158
logger.debug("Building vectors and matrices for linear programming problem")
159-
b_lb = utility_values - epsilon
159+
b_lb = utility_values
160160
A_eq = np.ones((1, n))
161161
# We explicitly add the utility value for the entire dataset
162162
b_eq = np.array([u(u.data.indices)])
@@ -166,7 +166,7 @@ def montecarlo_least_core(
166166
b_lb = b_lb[unique_indices]
167167

168168
_, subsidy = _solve_least_core_linear_program(
169-
A_eq=A_eq, b_eq=b_eq, A_lb=A_lb, b_lb=b_lb, **options
169+
A_eq=A_eq, b_eq=b_eq, A_lb=A_lb, b_lb=b_lb, epsilon=epsilon, **options
170170
)
171171

172172
values: Optional[NDArray[np.float_]]

0 commit comments

Comments
 (0)