-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create repeat_indices helper and use it in _owen_sampling_shapley and…
… _combinatorial_montecarlo_shapley
- Loading branch information
1 parent
efca423
commit 4ad3eeb
Showing
4 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from collections.abc import Iterator | ||
from itertools import cycle, takewhile | ||
from typing import Collection | ||
|
||
from tqdm.auto import tqdm | ||
|
||
from pydvl.value.result import ValuationResult | ||
from pydvl.value.stopping import StoppingCriterion | ||
|
||
__all__ = ["repeat_indices"] | ||
|
||
|
||
def repeat_indices( | ||
indices: Collection[int], result: ValuationResult, done: StoppingCriterion, **kwargs | ||
) -> Iterator[int]: | ||
"""Helper function to cycle indefinitely over a collection of indices | ||
until the stopping criterion is satisfied while displaying progress. | ||
Args: | ||
indices: Collection of indices that will be cycled until done. | ||
result: Object containing the current results. | ||
done: Stopping criterion. | ||
kwargs: Keyword arguments passed to tqdm. | ||
""" | ||
with tqdm(total=100, unit="%", **kwargs) as pbar: | ||
it = takewhile(lambda _: not done(result), cycle(indices)) | ||
for i in it: | ||
yield i | ||
pbar.update(100 * done.completion() - pbar.n) | ||
pbar.refresh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters