Skip to content

Commit

Permalink
Updated GenerateMinimize and DataAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioTheOne committed Oct 28, 2024
1 parent 4cbe132 commit 601c0a1
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 194 deletions.
354 changes: 176 additions & 178 deletions lab/1-evaluation_pipeline.ipynb

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions lab/config/base/bbbp_gcn_irand.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"experiment" : {
"scope": "debug",
"parameters" : {
"lock_release_tout":120,
"propagate":[
{"in_sections" : ["doe-triplets/explainer"],"params" : {"fold_id": 1}},
{"in_sections" : ["doe-triplets/oracle"],"params" : {"fold_id": -1,"retrain":false}},
{"in_sections": ["doe-triplets/dataset"],"params": { "compose_man" : "lab/config/snippets/datasets/centr_and_weights.json" }}
],
"expand" : { "folds" : ["doe-triplets/explainer"], "triplets" : true }
}
},
"doe-triplets":[
{
"compose_do": "./lab/config/snippets/do-pairs/BBBP_GCN.json",
"explainer": {
"class": "src.explainer.future.search.i_rand.IRandExplainer",
"parameters": {
"p": 0.01,
"t": 3
}
}
}
],
"evaluator": {
"class": "src.evaluation.future.evaluator.Evaluator",
"parameters": {
"compose_pip": "./lab/config/snippets/default_pipeline.json"
}
},
"compose_strs" : "./lab/config/snippets/default_store_paths.json"
}
6 changes: 3 additions & 3 deletions lab/config/meta/generate_minimize.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"experiment" : {
"scope": "meta-overshoot-reduce",
"scope": "meta",
"parameters" : {
"lock_release_tout":120,
"propagate":[
Expand All @@ -15,7 +15,7 @@
{
"compose_do": "./lab/config/snippets/do-pairs/TCR-128-28-0.25_TCO.json",
"explainer": {
"class": "src.explainer.future.meta.generate_minimize.GenerateMinimizeExplainer",
"class": "src.explainer.future.meta.generate_minimize.GenerateMinimize",
"parameters":{
"fold_id": 1,
"generator": {
Expand All @@ -25,7 +25,7 @@
}
},
"minimizer": {
"class": "src.explainer.future.meta.minimizer.random.RandomMinimizer",
"class": "src.explainer.future.meta.minimizer.random.Random",
"parameters": {
"max_oc": 1000,
"changes_batch_size": 3
Expand Down
2 changes: 1 addition & 1 deletion src/data_analysis/future/data_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_aggregated_dataframe(cls, results_folder_path):
hashed_scope = results_dict['config']['scope']
hashed_dataset_name = results_dict['hash_ids']['dataset']
hashed_oracle_name = results_dict['hash_ids']['oracle']
exp_name = results_dict['hash_ids']['explainer'].split(sep='-')[0]
exp_name = results_dict['hash_ids']['explainer'].rsplit(sep='-', maxsplit=1)[0]
hashed_explainer_name = exp_name
# hashed_explainer_name = results_dict['hash_ids']['explainer']

Expand Down
19 changes: 8 additions & 11 deletions src/explainer/future/meta/generate_minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from src.future.explanation.local.graph_counterfactual import LocalGraphCounterfactualExplanation


class GenerateMinimizeExplainer(Explainer, Trainable):
class GenerateMinimize(Explainer):
"""This meta-explainer uses an explanation method to generate a first counterfactual and
then a minimizer function to reduce the distance between the counterfactual and the original
instance"""
Expand Down Expand Up @@ -42,11 +42,6 @@ def init(self):

self.explanation_minimizer = get_instance_kvargs(self.local_config['parameters']['minimizer']['class'],
{'context':self.context,'local_config': self.local_config['parameters']['minimizer']})


def real_fit(self):
# Chose if the components will be trained at creation time or in this fit
pass


def explain(self, instance):
Expand Down Expand Up @@ -79,8 +74,10 @@ def explain(self, instance):
return minimal_explanation


def write(self):
pass

def read(self):
pass
@property
def name(self):
# Make the name of the generator_minimizer explainer show the names of the used generator and minimizer
gen = get_class( self.local_config['parameters']['generator']['class'] ).__name__
min = get_class( self.local_config['parameters']['minimizer']['class'] ).__name__
alias = f'GenerateMinimize({gen}-{min})'
return self.context.get_name(self,alias=alias)
2 changes: 1 addition & 1 deletion src/explainer/future/meta/minimizer/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from src.dataset.instances.graph import GraphInstance
from src.utils.comparison import get_all_edge_differences, get_edge_differences

class RandomMinimizer(ExplanationMinimizer):
class Random(ExplanationMinimizer):

def check_configuration(self):
super().check_configuration()
Expand Down

0 comments on commit 601c0a1

Please sign in to comment.