pydvl.valuation.methods.least_core
¶
This module implements the least-core valuation method.
Least-Core values were introduced by Yan and Procaccia (2021).1 Please refer to the paper or our documentation for more details and a comparison with other methods (Benmerzoug and de Benito Delgado, 2023).2
References¶
-
Yan, Tom, and Ariel D. Procaccia. If You Like Shapley Then You’ll Love the Core. In Proceedings of the 35th AAAI Conference on Artificial Intelligence, 2021, 6:5751–59. Virtual conference: Association for the Advancement of Artificial Intelligence, 2021. ↩
-
Benmerzoug, Anes, and Miguel de Benito Delgado. [Re] If You like Shapley, Then You’ll Love the Core. ReScience C 9, no. 2 (31 July 2023): #32. ↩
ExactLeastCoreValuation
¶
ExactLeastCoreValuation(
utility: UtilityBase,
non_negative_subsidy: bool = False,
solver_options: dict | None = None,
progress: bool = True,
batch_size: int = 1,
)
Bases: LeastCoreValuation
Class to calculate exact least-core values.
Equivalent to constructing a
LeastCoreValuation with a
DeterministicUniformSampler
and n_samples=None.
| PARAMETER | DESCRIPTION |
|---|---|
utility
|
Utility object with model, data and scoring function.
TYPE:
|
non_negative_subsidy
|
If True, the least core subsidy \(e\) is constrained to be non-negative.
TYPE:
|
solver_options
|
Optional dictionary containing a CVXPY solver and options to configure it. For valid values to the "solver" key see here. For additional options see here.
TYPE:
|
progress
|
Whether to show a progress bar during the construction of the least-core problem.
TYPE:
|
Source code in src/pydvl/valuation/methods/least_core.py
fit
¶
fit(data: Dataset, continue_from: ValuationResult | None = None) -> Self
Calculate the exact least core valuation on a dataset.
This method computes all possible coalitions which makes it only feasible for small datasets (typically less than 20 samples).
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Data for which to compute values
TYPE:
|
continue_from
|
A previously computed valuation result to continue from.
TYPE:
|
Source code in src/pydvl/valuation/methods/least_core.py
values
¶
values(sort: bool = False) -> ValuationResult
Returns a copy of the valuation result.
The valuation must have been run with fit() before calling this method.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
Whether to sort the valuation result by value before returning it.
TYPE:
|
Returns: The result of the valuation.
Source code in src/pydvl/valuation/base.py
LeastCoreValuation
¶
LeastCoreValuation(
utility: UtilityBase,
sampler: PowersetSampler,
n_samples: int | None = None,
non_negative_subsidy: bool = False,
solver_options: dict | None = None,
progress: bool = True,
)
Bases: Valuation
Umbrella class to calculate least-core values with multiple sampling methods.
See the documentation for an overview.
Different samplers correspond to different least-core methods from the literature.
For those, we provide convenience subclasses of LeastCoreValuation. See
Other samplers allow you to create your own importance sampling method and might yield computational gains over the standard Monte Carlo method.
| PARAMETER | DESCRIPTION |
|---|---|
utility
|
Utility object with model, data and scoring function.
TYPE:
|
sampler
|
The sampler to use for the valuation.
TYPE:
|
n_samples
|
The number of samples to use for the valuation. If None, it will be
set to the sample limit of the chosen sampler (for finite samplers) or
TYPE:
|
non_negative_subsidy
|
If True, the least core subsidy \(e\) is constrained to be non-negative.
TYPE:
|
solver_options
|
Optional dictionary containing a CVXPY solver and options to configure it. For valid values to the "solver" key see here. For additional options see here.
TYPE:
|
progress
|
Whether to show a progress bar during the construction of the least-core problem.
TYPE:
|
Source code in src/pydvl/valuation/methods/least_core.py
fit
¶
fit(data: Dataset, continue_from: ValuationResult | None = None) -> Self
Calculate the least core valuation on a dataset.
This method has to be called before calling values().
Calculating the least core valuation is a computationally expensive task that
can be parallelized. To do so, call the fit() method inside a
joblib.parallel_config context manager as follows:
Source code in src/pydvl/valuation/methods/least_core.py
values
¶
values(sort: bool = False) -> ValuationResult
Returns a copy of the valuation result.
The valuation must have been run with fit() before calling this method.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
Whether to sort the valuation result by value before returning it.
TYPE:
|
Returns: The result of the valuation.
Source code in src/pydvl/valuation/base.py
MonteCarloLeastCoreValuation
¶
MonteCarloLeastCoreValuation(
utility: UtilityBase,
n_samples: int,
non_negative_subsidy: bool = False,
solver_options: dict | None = None,
progress: bool = True,
seed: Seed | None = None,
batch_size: int = 1,
)
Bases: LeastCoreValuation
Class to calculate exact least-core values.
Equivalent to creating a LeastCoreValuation with a UniformSampler.
| PARAMETER | DESCRIPTION |
|---|---|
utility
|
Utility object with model, data and scoring function.
TYPE:
|
n_samples
|
The number of samples to use for the valuation. If None, it will be
set to
TYPE:
|
non_negative_subsidy
|
If True, the least core subsidy \(e\) is constrained to be non-negative.
TYPE:
|
solver_options
|
Optional dictionary containing a CVXPY solver and options to configure it. For valid values to the "solver" key see here. For additional options see here.
TYPE:
|
progress
|
Whether to show a progress bar during the construction of the least-core problem.
TYPE:
|
Source code in src/pydvl/valuation/methods/least_core.py
fit
¶
fit(data: Dataset, continue_from: ValuationResult | None = None) -> Self
Calculate the Monte Carlo approximation of Least-Core valuation on a dataset.
This method uses random sampling of coalitions and can handle larger datasets than the exact method, with accuracy depending on the number of samples. Args: data: Data for which to compute values continue_from: A previously computed valuation result to continue from.
Source code in src/pydvl/valuation/methods/least_core.py
values
¶
values(sort: bool = False) -> ValuationResult
Returns a copy of the valuation result.
The valuation must have been run with fit() before calling this method.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
Whether to sort the valuation result by value before returning it.
TYPE:
|
Returns: The result of the valuation.
Source code in src/pydvl/valuation/base.py
create_least_core_problem
¶
create_least_core_problem(
u: UtilityBase, sampler: PowersetSampler, n_samples: int, progress: bool
) -> LeastCoreProblem
Create a Least Core problem from a utility and a sampler.
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Utility object with model, data and scoring function.
TYPE:
|
sampler
|
The sampler to use for the valuation.
TYPE:
|
n_samples
|
The maximum number of samples to use for the valuation.
TYPE:
|
progress
|
Whether to show a progress bar during the construction of the least-core problem.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LeastCoreProblem
|
The least core problem to solve.
TYPE:
|