-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExplanationsAggregator and get_self_influence_ranking
- Loading branch information
1 parent
7e34a3d
commit 85f3b4b
Showing
7 changed files
with
56 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from abc import ABC | ||
|
||
import torch | ||
|
||
|
||
class ExplanationsAggregator(ABC): | ||
def __init__(self, training_size: int, *args, **kwargs): | ||
self.scores = torch.zeros(training_size) | ||
|
||
def update(self, explanations: torch.Tensor): | ||
raise NotImplementedError | ||
|
||
def get_global_ranking(self) -> torch.Tensor: | ||
return self.scores.argsort() | ||
|
||
|
||
class SumAggregator(ExplanationsAggregator): | ||
def update(self, explanations: torch.Tensor) -> torch.Tensor: | ||
self.scores += explanations.sum(dim=0) | ||
|
||
|
||
class AbsSumAggregator(ExplanationsAggregator): | ||
def update(self, explanations: torch.Tensor) -> torch.Tensor: | ||
self.scores += explanations.abs().sum(dim=0) |
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
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.