From 6d7922b2743ffa21202e9d89bb75cd36bafda8cc Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Thu, 3 Apr 2025 16:56:46 -0500 Subject: [PATCH 1/7] Updated README.md --- README.md | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ae9e9db..7229d34 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +from pywhyllm import ValidationSuggesterfrom pywhyllm import IdentificationSuggester + # PyWhy-LLM: Leveraging Large Language Models for Causal Analysis [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) @@ -25,7 +27,10 @@ pip install pywhyllm PyWhy-LLM seamlessly integrates into your existing causal inference process. Import the necessary classes and start exploring the power of LLM-augmented causal analysis. ```python -from pywhyllm import ModelSuggester, IdentificationSuggester, ValidationSuggester +from pywhyllm.suggesters.model_suggester import ModelSuggester +from pywhyllm.suggesters.identification_suggester import IdentificationSuggester +from pywhyllm.suggesters.validation_suggester import ValidationSuggester +from pywhyllm import RelationshipStrategy ``` @@ -34,17 +39,20 @@ from pywhyllm import ModelSuggester, IdentificationSuggester, ValidationSuggeste ```python # Create instance of Modeler -modeler = Modeler() +modeler = ModelSuggester('gpt-4') + +factors_list = ["a", "b", "c"] +treatment = "treatment" +outcome = "outcome" + +#Suggest a list of domain expertises +domain_expertises = modeler.suggest_domain_expertises(factors_list) # Suggest a set of potential confounders -suggested_confounders = modeler.suggest_confounders(variables=_variables, treatment=treatment, outcome=outcome, llm=gpt4) +suggested_confounders = modeler.suggest_confounders(treatment, outcome, factors_list, domain_expertises) # Suggest pair-wise relationship between variables -suggested_dag = modeler.suggest_relationships(variables=selected_variables, llm=gpt4) - -plt.figure(figsize=(10, 5)) -nx.draw(suggested_dag, with_labels=True, node_color='lightblue') -plt.show() +suggested_dag = modeler.suggest_relationships(treatment, outcome, factors_list, domain_expertises, RelationshipStrategy.Pairwise) ``` @@ -54,15 +62,13 @@ plt.show() ```python # Create instance of Identifier -identifier = Identifier() +identifier = IdentificationSuggester('gpt-4') -# Suggest a backdoor set, front door set, and iv set -suggested_backdoor = identifier.suggest_backdoor(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) -suggested_frontdoor = identifier.suggest_frontdoor(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) -suggested_iv = identifier.suggest_iv(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) +# Suggest a backdoor set, mediator set, and iv set +suggested_backdoor = identifier.suggest_backdoor(treatment, outcome, factors_list, domain_expertises) +suggested_mediators = identifier.suggest_mediators(treatment, outcome, factors_list, domain_expertises) +suggested_iv = identifier.suggest_ivs(treatment, outcome, factors_list, domain_expertises) -# Suggest an estimand based on the suggester backdoor set, front door set, and iv set -estimand = identifier.suggest_estimand(confounders=suggested_confounders, treatment=treatment, outcome=outcome, backdoor=suggested_backdoor, frontdoor=suggested_frontdoor, iv=suggested_iv, llm=gpt4) ``` @@ -72,20 +78,16 @@ estimand = identifier.suggest_estimand(confounders=suggested_confounders, treatm ```python # Create instance of Validator -validator = Validator() +validator = ValidationSuggester('gpt-4') -# Suggest a critique of the provided DAG -suggested_critiques_dag = validator.critique_graph(graph=suggested_dag, llm=gpt4) +# Suggest a critique of the edges in provided DAG +suggested_critiques_dag = validator.critique_graph(factors_list, suggested_dag, domain_expertises, RelationshipStrategy.Pairwise) # Suggest latent confounders -suggested_latent_confounders = validator.suggest_latent_confounders(treatment=treatment, outcome=outcome, llm=gpt4) +suggested_latent_confounders = validator.suggest_latent_confounders(treatment, outcome, factors_list, domain_expertises) # Suggest negative controls -suggested_negative_controls = validator.suggest_negative_controls(variables=selected_variables, treatment=treatment, outcome=outcome, llm=gpt4) - -plt.figure(figsize=(10, 5)) -nx.draw(suggested_critiques_dag, with_labels=True, node_color='lightblue') -plt.show() +suggested_negative_controls = validator.suggest_negative_controls(treatment, outcome, factors_list, domain_expertises) ``` From fff57a3ff9aff606a8f527c779556e495a7e4379 Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Thu, 3 Apr 2025 16:57:07 -0500 Subject: [PATCH 2/7] Updated README.md Signed-off-by: Grace Sng --- pywhyllm/suggesters/model_suggester.py | 2 +- pywhyllm/suggesters/validation_suggester.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pywhyllm/suggesters/model_suggester.py b/pywhyllm/suggesters/model_suggester.py index 3e7a4c5..c8cb89c 100644 --- a/pywhyllm/suggesters/model_suggester.py +++ b/pywhyllm/suggesters/model_suggester.py @@ -461,7 +461,7 @@ def suggest_relationships( outcome: str, factors_list: list, expertise_list: list, - relationship_strategy: RelationshipStrategy = RelationshipStrategy.Parent, + relationship_strategy: RelationshipStrategy = RelationshipStrategy.Pairwise, analysis_context: str = CONTEXT, stakeholders: list = None, ): diff --git a/pywhyllm/suggesters/validation_suggester.py b/pywhyllm/suggesters/validation_suggester.py index 57518ed..a50c5a7 100644 --- a/pywhyllm/suggesters/validation_suggester.py +++ b/pywhyllm/suggesters/validation_suggester.py @@ -381,7 +381,7 @@ def critique_graph( factors_list: List[str], edges: Dict[Tuple[str, str], int], experts: list(), - relationship_strategy: RelationshipStrategy = RelationshipStrategy.Parent, + relationship_strategy: RelationshipStrategy = RelationshipStrategy.Pairwise, analysis_context: str = CONTEXT, stakeholders: list() = None, ): From 75880c690144b7caa0ff810ff0cd0a43436cbc69 Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Thu, 3 Apr 2025 16:58:52 -0500 Subject: [PATCH 3/7] Updated README.md Signed-off-by: Grace Sng --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 7229d34..138c11d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -from pywhyllm import ValidationSuggesterfrom pywhyllm import IdentificationSuggester - # PyWhy-LLM: Leveraging Large Language Models for Causal Analysis [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) From 935b8593ccb327158a2d8608e164736eb097b46a Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Sat, 5 Apr 2025 21:08:23 -0400 Subject: [PATCH 4/7] Updated directory and imports and revised parameter lists. Signed-off-by: Grace Sng --- README.md | 2 +- pywhyllm/suggesters/identification_suggester.py | 10 +++++----- pywhyllm/suggesters/model_suggester.py | 12 ++++++------ pywhyllm/suggesters/validation_suggester.py | 12 ++++++------ {pywhyllm/tests => tests}/__init__.py | 0 .../tests => tests}/model_suggester/__init__.py | 0 .../model_suggester/data_providers/__init__.py | 0 .../identification_suggester_data_provider.py | 0 .../data_providers/model_suggester_data_provider.py | 0 .../simple_identification_suggester_data_provider.py | 0 .../simple_model_suggester_data_provider.py | 0 .../tuebingen_model_suggester_data_provider.py | 0 .../validation_suggester_data_provider.py | 0 .../model_suggester/test_identification_suggester.py | 5 +++-- .../model_suggester/test_model_suggester.py | 2 +- .../test_simple_identification_suggester.py | 2 +- .../model_suggester/test_simple_model_suggester.py | 2 +- .../test_tuebingen_model_suggester.py | 3 +-- .../model_suggester/test_validation_suggester.py | 5 ++--- {pywhyllm/tests => tests}/test_notebooks.py | 0 20 files changed, 27 insertions(+), 28 deletions(-) rename {pywhyllm/tests => tests}/__init__.py (100%) rename {pywhyllm/tests => tests}/model_suggester/__init__.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/__init__.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/identification_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/model_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/simple_identification_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/simple_model_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/tuebingen_model_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/data_providers/validation_suggester_data_provider.py (100%) rename {pywhyllm/tests => tests}/model_suggester/test_identification_suggester.py (91%) rename {pywhyllm/tests => tests}/model_suggester/test_model_suggester.py (98%) rename {pywhyllm/tests => tests}/model_suggester/test_simple_identification_suggester.py (93%) rename {pywhyllm/tests => tests}/model_suggester/test_simple_model_suggester.py (97%) rename {pywhyllm/tests => tests}/model_suggester/test_tuebingen_model_suggester.py (97%) rename {pywhyllm/tests => tests}/model_suggester/test_validation_suggester.py (96%) rename {pywhyllm/tests => tests}/test_notebooks.py (100%) diff --git a/README.md b/README.md index 138c11d..4e5e2c7 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ factors_list = ["a", "b", "c"] treatment = "treatment" outcome = "outcome" -#Suggest a list of domain expertises +# Suggest a list of domain expertises domain_expertises = modeler.suggest_domain_expertises(factors_list) # Suggest a set of potential confounders diff --git a/pywhyllm/suggesters/identification_suggester.py b/pywhyllm/suggesters/identification_suggester.py index 194b272..a6ab124 100644 --- a/pywhyllm/suggesters/identification_suggester.py +++ b/pywhyllm/suggesters/identification_suggester.py @@ -118,7 +118,7 @@ def suggest_backdoor( outcome: str, factors_list: list(), expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): backdoor_set = self.model_suggester.suggest_confounders( @@ -138,7 +138,7 @@ def suggest_frontdoor( outcome: str, factors_list: list(), expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): pass @@ -149,7 +149,7 @@ def suggest_mediators( outcome: str, factors_list: list(), expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): expert_list: List[str] = list() @@ -189,7 +189,7 @@ def request_mediators( domain_expertise, factors_list, mediators_edges, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): mediators: List[str] = list() @@ -262,7 +262,7 @@ def suggest_ivs( outcome: str, factors_list: list(), expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): expert_list: List[str] = list() diff --git a/pywhyllm/suggesters/model_suggester.py b/pywhyllm/suggesters/model_suggester.py index c8cb89c..a7cb7de 100644 --- a/pywhyllm/suggesters/model_suggester.py +++ b/pywhyllm/suggesters/model_suggester.py @@ -19,7 +19,7 @@ def suggest_domain_expertises( self, factors_list, n_experts: int = 1, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): expertise_list: List[str] = list() @@ -62,7 +62,7 @@ def suggest_domain_experts( self, factors_list, n_experts: int = 5, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): experts_list: Set[str] = set() @@ -104,7 +104,7 @@ def suggest_stakeholders( self, factors_list, n_stakeholders: int = 5, # must be > 1 - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): stakeholder_list: List[str] = list() @@ -194,7 +194,7 @@ def request_confounders( domain_expertise, factors_list, confounders_edges, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): confounders: List[str] = list() @@ -265,7 +265,7 @@ def suggest_parents( domain_expertise, factor, factors_list, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): parent_candidates: List[str] = [] @@ -330,7 +330,7 @@ def suggest_children( domain_expertise, factor, factors_list, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): children_candidates: List[str] = [] diff --git a/pywhyllm/suggesters/validation_suggester.py b/pywhyllm/suggesters/validation_suggester.py index a50c5a7..3b2e259 100644 --- a/pywhyllm/suggesters/validation_suggester.py +++ b/pywhyllm/suggesters/validation_suggester.py @@ -24,7 +24,7 @@ def suggest_negative_controls( outcome: str, factors_list: list(), expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): expert_list: List[str] = list() @@ -65,7 +65,7 @@ def request_negative_controls( factors_list: list(), negative_controls_counter: list(), domain_expertise: str, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): negative_controls_list: List[str] = list() @@ -132,7 +132,7 @@ def suggest_latent_confounders( treatment: str, outcome: str, expertise_list: list(), - analysis_context=CONTEXT, + analysis_context: str = CONTEXT, stakeholders: list() = None ): expert_list: List[str] = list() @@ -166,7 +166,7 @@ def request_latent_confounders( outcome: str, latent_confounders_counter: list(), domain_expertise: str, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): latent_confounders_list: List[str] = list() @@ -224,7 +224,7 @@ def request_parent_critique( factor, factors_list, domain_expertise, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): edited_factors_list: List[str] = [] @@ -275,7 +275,7 @@ def request_children_critique( factor, factors_list, domain_expertise, - analysis_context=CONTEXT + analysis_context: str = CONTEXT ): edited_factors_list: List[str] = [] diff --git a/pywhyllm/tests/__init__.py b/tests/__init__.py similarity index 100% rename from pywhyllm/tests/__init__.py rename to tests/__init__.py diff --git a/pywhyllm/tests/model_suggester/__init__.py b/tests/model_suggester/__init__.py similarity index 100% rename from pywhyllm/tests/model_suggester/__init__.py rename to tests/model_suggester/__init__.py diff --git a/pywhyllm/tests/model_suggester/data_providers/__init__.py b/tests/model_suggester/data_providers/__init__.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/__init__.py rename to tests/model_suggester/data_providers/__init__.py diff --git a/pywhyllm/tests/model_suggester/data_providers/identification_suggester_data_provider.py b/tests/model_suggester/data_providers/identification_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/identification_suggester_data_provider.py rename to tests/model_suggester/data_providers/identification_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/data_providers/model_suggester_data_provider.py b/tests/model_suggester/data_providers/model_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/model_suggester_data_provider.py rename to tests/model_suggester/data_providers/model_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/data_providers/simple_identification_suggester_data_provider.py b/tests/model_suggester/data_providers/simple_identification_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/simple_identification_suggester_data_provider.py rename to tests/model_suggester/data_providers/simple_identification_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/data_providers/simple_model_suggester_data_provider.py b/tests/model_suggester/data_providers/simple_model_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/simple_model_suggester_data_provider.py rename to tests/model_suggester/data_providers/simple_model_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/data_providers/tuebingen_model_suggester_data_provider.py b/tests/model_suggester/data_providers/tuebingen_model_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/tuebingen_model_suggester_data_provider.py rename to tests/model_suggester/data_providers/tuebingen_model_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/data_providers/validation_suggester_data_provider.py b/tests/model_suggester/data_providers/validation_suggester_data_provider.py similarity index 100% rename from pywhyllm/tests/model_suggester/data_providers/validation_suggester_data_provider.py rename to tests/model_suggester/data_providers/validation_suggester_data_provider.py diff --git a/pywhyllm/tests/model_suggester/test_identification_suggester.py b/tests/model_suggester/test_identification_suggester.py similarity index 91% rename from pywhyllm/tests/model_suggester/test_identification_suggester.py rename to tests/model_suggester/test_identification_suggester.py index 5515db4..d60203d 100644 --- a/pywhyllm/tests/model_suggester/test_identification_suggester.py +++ b/tests/model_suggester/test_identification_suggester.py @@ -4,8 +4,9 @@ from pywhyllm.suggesters.identification_suggester import IdentificationSuggester from pywhyllm.suggesters.model_suggester import ModelSuggester -from pywhyllm.tests.model_suggester.data_providers.model_suggester_data_provider import * -from pywhyllm.tests.model_suggester.data_providers.identification_suggester_data_provider import * +from tests.model_suggester.data_providers.identification_suggester_data_provider import * +from tests.model_suggester.data_providers.model_suggester_data_provider import * + class TestIdentificationSuggester(unittest.TestCase): def test_suggest_backdoor(self): diff --git a/pywhyllm/tests/model_suggester/test_model_suggester.py b/tests/model_suggester/test_model_suggester.py similarity index 98% rename from pywhyllm/tests/model_suggester/test_model_suggester.py rename to tests/model_suggester/test_model_suggester.py index 98292fe..38c0ef6 100644 --- a/pywhyllm/tests/model_suggester/test_model_suggester.py +++ b/tests/model_suggester/test_model_suggester.py @@ -3,8 +3,8 @@ from guidance.models._openai import OpenAI from pywhyllm.suggesters.model_suggester import ModelSuggester -from pywhyllm.tests.model_suggester.data_providers.model_suggester_data_provider import * from pywhyllm.helpers import RelationshipStrategy +from tests.model_suggester.data_providers.model_suggester_data_provider import * class TestModelSuggester(unittest.TestCase): diff --git a/pywhyllm/tests/model_suggester/test_simple_identification_suggester.py b/tests/model_suggester/test_simple_identification_suggester.py similarity index 93% rename from pywhyllm/tests/model_suggester/test_simple_identification_suggester.py rename to tests/model_suggester/test_simple_identification_suggester.py index 2e87809..a7d91e3 100644 --- a/pywhyllm/tests/model_suggester/test_simple_identification_suggester.py +++ b/tests/model_suggester/test_simple_identification_suggester.py @@ -3,7 +3,7 @@ from guidance.models._openai import OpenAI from pywhyllm.suggesters.simple_identification_suggester import SimpleIdentificationSuggester -from pywhyllm.tests.model_suggester.data_providers.simple_identification_suggester_data_provider import * +from tests.model_suggester.data_providers.simple_identification_suggester_data_provider import * class TestSimpleIdentificationSuggester(unittest.TestCase): diff --git a/pywhyllm/tests/model_suggester/test_simple_model_suggester.py b/tests/model_suggester/test_simple_model_suggester.py similarity index 97% rename from pywhyllm/tests/model_suggester/test_simple_model_suggester.py rename to tests/model_suggester/test_simple_model_suggester.py index 70bd3ef..bfe5973 100644 --- a/pywhyllm/tests/model_suggester/test_simple_model_suggester.py +++ b/tests/model_suggester/test_simple_model_suggester.py @@ -3,7 +3,7 @@ from guidance.models._openai import OpenAI from pywhyllm.suggesters.simple_model_suggester import SimpleModelSuggester -from pywhyllm.tests.model_suggester.data_providers.simple_model_suggester_data_provider import * +from tests.model_suggester.data_providers.simple_model_suggester_data_provider import * class TestSimpleModelSuggester(unittest.TestCase): diff --git a/pywhyllm/tests/model_suggester/test_tuebingen_model_suggester.py b/tests/model_suggester/test_tuebingen_model_suggester.py similarity index 97% rename from pywhyllm/tests/model_suggester/test_tuebingen_model_suggester.py rename to tests/model_suggester/test_tuebingen_model_suggester.py index c90e308..9d2bb25 100644 --- a/pywhyllm/tests/model_suggester/test_tuebingen_model_suggester.py +++ b/tests/model_suggester/test_tuebingen_model_suggester.py @@ -3,8 +3,7 @@ from guidance.models._openai import OpenAI from pywhyllm.suggesters.tuebingen_model_suggester import TuebingenModelSuggester, Strategy -from pywhyllm.tests.model_suggester.data_providers.tuebingen_model_suggester_data_provider import * - +from tests.model_suggester.data_providers.tuebingen_model_suggester_data_provider import * class TestTuebingenModelSuggester(unittest.TestCase): def test_suggest_description(self): diff --git a/pywhyllm/tests/model_suggester/test_validation_suggester.py b/tests/model_suggester/test_validation_suggester.py similarity index 96% rename from pywhyllm/tests/model_suggester/test_validation_suggester.py rename to tests/model_suggester/test_validation_suggester.py index dd3a014..106ec5b 100644 --- a/pywhyllm/tests/model_suggester/test_validation_suggester.py +++ b/tests/model_suggester/test_validation_suggester.py @@ -4,10 +4,9 @@ from guidance.models._openai import OpenAI from pywhyllm.suggesters.validation_suggester import ValidationSuggester -from pywhyllm.tests.model_suggester.data_providers.validation_suggester_data_provider import * -from pywhyllm.tests.model_suggester.data_providers.model_suggester_data_provider import * from pywhyllm.helpers import RelationshipStrategy - +from tests.model_suggester.data_providers.model_suggester_data_provider import * +from tests.model_suggester.data_providers.validation_suggester_data_provider import * class TestValidationSuggester(unittest.TestCase): def test_suggest_latent_confounders(self): diff --git a/pywhyllm/tests/test_notebooks.py b/tests/test_notebooks.py similarity index 100% rename from pywhyllm/tests/test_notebooks.py rename to tests/test_notebooks.py From 63fd72a08a9a62b0bb49cf3b11b5ddf268c736bb Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Sun, 6 Apr 2025 22:51:26 -0400 Subject: [PATCH 5/7] Edited README.md Signed-off-by: Grace Sng --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e5e2c7..908d176 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ from pywhyllm import RelationshipStrategy # Create instance of Modeler modeler = ModelSuggester('gpt-4') -factors_list = ["a", "b", "c"] -treatment = "treatment" -outcome = "outcome" +factors_list = ["smoking", "lung cancer", "exercise habits", "air pollution exposure"] +treatment = "smoking" +outcome = "lung cancer" # Suggest a list of domain expertises domain_expertises = modeler.suggest_domain_expertises(factors_list) From 09d85db258d49eb0742edddebc9f671e82fa159a Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Mon, 7 Apr 2025 21:46:05 -0400 Subject: [PATCH 6/7] Changed factors_list to all_factors in README.md Signed-off-by: Grace Sng --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ae9e9db..be7cd2b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,10 @@ pip install pywhyllm PyWhy-LLM seamlessly integrates into your existing causal inference process. Import the necessary classes and start exploring the power of LLM-augmented causal analysis. ```python -from pywhyllm import ModelSuggester, IdentificationSuggester, ValidationSuggester +from pywhyllm.suggesters.model_suggester import ModelSuggester +from pywhyllm.suggesters.identification_suggester import IdentificationSuggester +from pywhyllm.suggesters.validation_suggester import ValidationSuggester +from pywhyllm import RelationshipStrategy ``` @@ -34,17 +37,20 @@ from pywhyllm import ModelSuggester, IdentificationSuggester, ValidationSuggeste ```python # Create instance of Modeler -modeler = Modeler() +modeler = ModelSuggester('gpt-4') + +all_factors = ["smoking", "lung cancer", "exercise habits", "air pollution exposure"] +treatment = "smoking" +outcome = "lung cancer" + +# Suggest a list of domain expertises +domain_expertises = modeler.suggest_domain_expertises(all_factors) # Suggest a set of potential confounders -suggested_confounders = modeler.suggest_confounders(variables=_variables, treatment=treatment, outcome=outcome, llm=gpt4) +suggested_confounders = modeler.suggest_confounders(treatment, outcome, all_factors, domain_expertises) # Suggest pair-wise relationship between variables -suggested_dag = modeler.suggest_relationships(variables=selected_variables, llm=gpt4) - -plt.figure(figsize=(10, 5)) -nx.draw(suggested_dag, with_labels=True, node_color='lightblue') -plt.show() +suggested_dag = modeler.suggest_relationships(treatment, outcome, all_factors, domain_expertises, RelationshipStrategy.Pairwise) ``` @@ -54,15 +60,13 @@ plt.show() ```python # Create instance of Identifier -identifier = Identifier() +identifier = IdentificationSuggester('gpt-4') -# Suggest a backdoor set, front door set, and iv set -suggested_backdoor = identifier.suggest_backdoor(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) -suggested_frontdoor = identifier.suggest_frontdoor(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) -suggested_iv = identifier.suggest_iv(llm=gpt4, treatment=treatment, outcome=outcome, confounders=suggested_confounders) +# Suggest a backdoor set, mediator set, and iv set +suggested_backdoor = identifier.suggest_backdoor(treatment, outcome, all_factors, domain_expertises) +suggested_mediators = identifier.suggest_mediators(treatment, outcome, all_factors, domain_expertises) +suggested_iv = identifier.suggest_ivs(treatment, outcome, all_factors, domain_expertises) -# Suggest an estimand based on the suggester backdoor set, front door set, and iv set -estimand = identifier.suggest_estimand(confounders=suggested_confounders, treatment=treatment, outcome=outcome, backdoor=suggested_backdoor, frontdoor=suggested_frontdoor, iv=suggested_iv, llm=gpt4) ``` @@ -72,20 +76,16 @@ estimand = identifier.suggest_estimand(confounders=suggested_confounders, treatm ```python # Create instance of Validator -validator = Validator() +validator = ValidationSuggester('gpt-4') -# Suggest a critique of the provided DAG -suggested_critiques_dag = validator.critique_graph(graph=suggested_dag, llm=gpt4) +# Suggest a critique of the edges in provided DAG +suggested_critiques_dag = validator.critique_graph(all_factors, suggested_dag, domain_expertises, RelationshipStrategy.Pairwise) # Suggest latent confounders -suggested_latent_confounders = validator.suggest_latent_confounders(treatment=treatment, outcome=outcome, llm=gpt4) +suggested_latent_confounders = validator.suggest_latent_confounders(treatment, outcome, all_factors, domain_expertises) # Suggest negative controls -suggested_negative_controls = validator.suggest_negative_controls(variables=selected_variables, treatment=treatment, outcome=outcome, llm=gpt4) - -plt.figure(figsize=(10, 5)) -nx.draw(suggested_critiques_dag, with_labels=True, node_color='lightblue') -plt.show() +suggested_negative_controls = validator.suggest_negative_controls(treatment, outcome, all_factors, domain_expertises) ``` From eede694231b1bcbde5816c067a73031461103bd5 Mon Sep 17 00:00:00 2001 From: Grace Sng Date: Mon, 7 Apr 2025 21:58:01 -0400 Subject: [PATCH 7/7] Changed factors_list parameter to all_factors in functions Signed-off-by: Grace Sng --- .../suggesters/identification_suggester.py | 46 ++++++------- pywhyllm/suggesters/model_suggester.py | 66 +++++++++---------- pywhyllm/suggesters/validation_suggester.py | 56 ++++++++-------- 3 files changed, 84 insertions(+), 84 deletions(-) diff --git a/pywhyllm/suggesters/identification_suggester.py b/pywhyllm/suggesters/identification_suggester.py index 12386c2..5cd0d15 100644 --- a/pywhyllm/suggesters/identification_suggester.py +++ b/pywhyllm/suggesters/identification_suggester.py @@ -19,7 +19,7 @@ def __init__(self, llm=None): # self, # treatment: str, # outcome: str, - # factors_list: list(), + # all_factors: list(), # llm: guidance.models, # backdoor: Set[str] = None, # frontdoor: Set[str] = None, @@ -41,7 +41,7 @@ def __init__(self, llm=None): # backdoor_edges, backdoor_set = self.suggest_backdoor( # treatment=treatment, # outcome=outcome, - # factors_list=factors_list, + # all_factors=all_factors, # llm=llm, # experts=experts, # analysis_context=analysis_context, @@ -66,7 +66,7 @@ def __init__(self, llm=None): # frontdoor_edges, frontdoor_set = self.suggest_frontdoor( # treatment=treatment, # outcome=outcome, - # factors_list=factors_list, + # all_factors=all_factors, # llm=llm, # experts=experts, # analysis_context=analysis_context, @@ -87,7 +87,7 @@ def __init__(self, llm=None): # ivs_edges, ivs_set = self.suggest_ivs( # treatment=treatment, # outcome=outcome, - # factors_list=factors_list, + # all_factors=all_factors, # llm=llm, # experts=experts, # analysis_context=analysis_context, @@ -116,7 +116,7 @@ def suggest_backdoor( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), expertise_list: list(), analysis_context: str = CONTEXT, stakeholders: list() = None @@ -124,7 +124,7 @@ def suggest_backdoor( backdoor_set = self.model_suggester.suggest_confounders( treatment=treatment, outcome=outcome, - factors_list=factors_list, + all_factors=all_factors, expertise_list=expertise_list, analysis_context=analysis_context, stakeholders=stakeholders @@ -136,7 +136,7 @@ def suggest_frontdoor( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), expertise_list: list(), analysis_context: str = CONTEXT, stakeholders: list() = None @@ -147,7 +147,7 @@ def suggest_mediators( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), expertise_list: list(), analysis_context: str = CONTEXT, stakeholders: list() = None @@ -164,16 +164,16 @@ def suggest_mediators( mediators_edges[(treatment, outcome)] = 1 edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != treatment and factors_list[i] != outcome: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != treatment and all_factors[i] != outcome: + edited_factors_list.append(all_factors[i]) for expert in expert_list: mediators_edges, mediators_list = self.request_mediators( treatment=treatment, outcome=outcome, domain_expertise=expert, - factors_list=edited_factors_list, + all_factors=edited_factors_list, mediators_edges=mediators_edges, analysis_context=analysis_context ) @@ -187,7 +187,7 @@ def request_mediators( treatment, outcome, domain_expertise, - factors_list, + all_factors, mediators_edges, analysis_context: str = CONTEXT ): @@ -218,7 +218,7 @@ def request_mediators( on the causal chain that links the {treatment} to the {outcome}? From your perspective as an expert in {domain_expertise}, which factor(s) of the following factors, if any at all, mediates, is/are on the causal chain, that links the {treatment} to the {outcome}? Then provide your step by step chain of thoughts within - the tags . factor_names : {factors_list} Wrap the name of the factor(s), if any at all, + the tags . factor_names : {all_factors} Wrap the name of the factor(s), if any at all, that has/have a high likelihood of directly influencing and causing the assignment of the {outcome} and also has/have a high likelihood of being directly influenced and caused by the assignment of the {treatment} within the tags factor_name. Where factor_name is one of the items within the @@ -237,7 +237,7 @@ def request_mediators( if mediating_factor: for factor in mediating_factor: # to not add it twice into the list - if factor in factors_list and factor not in mediators: + if factor in all_factors and factor not in mediators: mediators.append(factor) success = True @@ -262,7 +262,7 @@ def suggest_ivs( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), expertise_list: list(), analysis_context: str = CONTEXT, stakeholders: list() = None @@ -279,9 +279,9 @@ def suggest_ivs( iv_edges[(treatment, outcome)] = 1 edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != treatment and factors_list[i] != outcome: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != treatment and all_factors[i] != outcome: + edited_factors_list.append(all_factors[i]) for expert in expert_list: iv_edges, iv_list = self.request_ivs( @@ -289,7 +289,7 @@ def suggest_ivs( outcome=outcome, analysis_context=analysis_context, domain_expertise=expert, - factors_list=edited_factors_list, + all_factors=edited_factors_list, iv_edges=iv_edges, ) @@ -305,7 +305,7 @@ def request_ivs( outcome, analysis_context, domain_expertise, - factors_list, + all_factors, iv_edges ): ivs: List[str] = list() @@ -338,7 +338,7 @@ def request_ivs( the {outcome}? Which factor(s) of the following factors, if any at all, are (an) instrumental variable(s) to the causal relationship of the {treatment} causing the {outcome}? Be concise and keep your thinking within two paragraphs. Then provide your step by step chain of thoughts within the tags - . factor_names : {factors_list} Wrap the name of the factor(s), if there are any at + . factor_names : {all_factors} Wrap the name of the factor(s), if there are any at all, that both has/have a high likelihood of influecing and causing the {treatment} and has/have a very low likelihood of influencing and causing the {outcome}, within the tags factor_name. Where factor_name is one of the items within the factor_names list. If a factor does not have a high @@ -353,7 +353,7 @@ def request_ivs( if iv_factors: for factor in iv_factors: - if factor in factors_list and factor not in ivs: + if factor in all_factors and factor not in ivs: ivs.append(factor) success = True diff --git a/pywhyllm/suggesters/model_suggester.py b/pywhyllm/suggesters/model_suggester.py index e99e1bd..b7b9df2 100644 --- a/pywhyllm/suggesters/model_suggester.py +++ b/pywhyllm/suggesters/model_suggester.py @@ -17,7 +17,7 @@ def __init__(self, llm=None): def suggest_domain_expertises( self, - factors_list, + all_factors, n_experts: int = 1, analysis_context: str = CONTEXT ): @@ -34,7 +34,7 @@ def suggest_domain_expertises( with user(): prompt_str = f"""What domain expertises have the knowledge and experience needed to identify causal relationships and causal influences between the {analysis_context}? What domain expertises are needed - to work with and reason about the causal influence between {factors_list}? What domain expertises + to work with and reason about the causal influence between {all_factors}? What domain expertises have the knowledge and experience to reason and answer questions about influence and cause between such factors? Think about this in a step by step manner and recommend {n_experts} expertises and provide each one wrapped within the tags, , along with the @@ -61,7 +61,7 @@ def suggest_domain_expertises( def suggest_domain_experts( self, - factors_list, + all_factors, n_experts: int = 5, analysis_context: str = CONTEXT ): @@ -77,7 +77,7 @@ def suggest_domain_experts( with user(): prompt_str = f"""What domain experts have the knowledge and experience needed to identify causal relationships and causal influences between the {analysis_context}? What experts are needed to work with and - reason about the causal influence between {factors_list}? What domain experts have the knowledge + reason about the causal influence between {all_factors}? What domain experts have the knowledge and experience to reason and answer questions about influence and cause between such factors? Think about this in a step by step manner and recommend {n_experts} domain experts and provide each one wrapped within the tags, , along with the reasoning and explanation @@ -104,7 +104,7 @@ def suggest_domain_experts( def suggest_stakeholders( self, - factors_list, + all_factors, n_stakeholders: int = 5, # must be > 1 analysis_context: str = CONTEXT ): @@ -122,7 +122,7 @@ def suggest_stakeholders( with user(): prompt_str = f"""What stakeholders have knowledge and experience in and about {analysis_context}? What stakeholders can work best with and reason well about the causal influence between - {factors_list}? What stakeholders have the knowledge and experience useful to reason within this context? Think about + {all_factors}? What stakeholders have the knowledge and experience useful to reason within this context? Think about this in a step by step manner and recommend {n_stakeholders} stakeholders. Then provide each useful stakeholder wrapped within the tags, , along with the reasoning and explanation wrapped between the tags .""" @@ -152,7 +152,7 @@ def suggest_confounders( self, treatment: str, outcome: str, - factors_list: list, + all_factors: list, expertise_list: list, analysis_context: str = CONTEXT, stakeholders: list = None @@ -170,9 +170,9 @@ def suggest_confounders( confounders: List[str] = list() edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != treatment and factors_list[i] != outcome: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != treatment and all_factors[i] != outcome: + edited_factors_list.append(all_factors[i]) for expert in expertise_list: confounders_edges, confounders_list = self.request_confounders( @@ -180,7 +180,7 @@ def suggest_confounders( outcome=outcome, analysis_context=analysis_context, domain_expertise=expert, - factors_list=edited_factors_list, + all_factors=edited_factors_list, confounders_edges=confounders_edges ) @@ -195,7 +195,7 @@ def request_confounders( treatment, outcome, domain_expertise, - factors_list, + all_factors, confounders_edges, analysis_context: str = CONTEXT ): @@ -229,7 +229,7 @@ def request_confounders( keep your thinking within two paragraphs. Then provide your step by step chain of thoughts within the tags . \n factor_names : - {factors_list} Wrap the name of the factor(s), if any at all, that has/have a high likelihood of directly influencing + {all_factors} Wrap the name of the factor(s), if any at all, that has/have a high likelihood of directly influencing and causing both the {treatment} and the {outcome}, within the tags factor_name where factor_name is one of the items within the factor_names list. If a factor does not have a high likelihood of directly @@ -244,7 +244,7 @@ def request_confounders( if confounding_factors: for factor in confounding_factors: # to not add it twice into the list - if factor in factors_list and factor not in confounders: + if factor in all_factors and factor not in confounders: confounders.append(factor) success = True @@ -269,14 +269,14 @@ def suggest_parents( self, domain_expertise, factor, - factors_list, + all_factors, analysis_context: str = CONTEXT ): parent_candidates: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != factor: - parent_candidates.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != factor: + parent_candidates.append(all_factors[i]) parents: List[str] = list() @@ -303,7 +303,7 @@ def suggest_parents( (2) From your perspective as an expert in {domain_expertise} which of the following factors has a high likelihood of directly influencing and causing the {factor}? factors list: [ -{factors_list}] +{all_factors}] For any factors within the list with a high likelihood of directly influencing and causing the {factor} wrap the name of the factor with the tags factor_name. @@ -335,15 +335,15 @@ def suggest_children( self, domain_expertise, factor, - factors_list, + all_factors, analysis_context: str = CONTEXT ): children_candidates: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != factor: - children_candidates.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != factor: + children_candidates.append(all_factors[i]) children: List[str] = list() @@ -373,7 +373,7 @@ def suggest_children( list, if any at all, has/have a high likelihood of being directly influenced and caused by the {factor}? What factor( - s) from the factors list, if any at all, is/are affected by the {factor}? factors list: [{factors_list}] + s) from the factors list, if any at all, is/are affected by the {factor}? factors list: [{all_factors}] For any factors within the list with a high likelihood of being directly influenced and caused by the {factor}, wrap the name of the factor with the tags factor_name. If a factor @@ -467,7 +467,7 @@ def suggest_relationships( self, treatment: str, outcome: str, - factors_list: list, + all_factors: list, expertise_list: list, relationship_strategy: RelationshipStrategy = RelationshipStrategy.Pairwise, analysis_context: str = CONTEXT, @@ -483,19 +483,19 @@ def suggest_relationships( if relationship_strategy == RelationshipStrategy.Parent: "loop asking parents program" parent_edges: Dict[Tuple[str, str], int] = dict() - for factor in factors_list: + for factor in all_factors: for expert in expert_list: suggested_parent = self.suggest_parents( domain_expertise=expert, factor=factor, - factors_list=factors_list, + all_factors=all_factors, analysis_context=analysis_context ) for element in suggested_parent: if ( element, factor, - ) in parent_edges and element in factors_list: + ) in parent_edges and element in all_factors: parent_edges[(element, factor)] += 1 else: parent_edges[(element, factor)] = 1 @@ -507,19 +507,19 @@ def suggest_relationships( children_edges: Dict[Tuple[str, str], int] = dict() - for factor in factors_list: + for factor in all_factors: for expert in expert_list: suggested_children = self.suggest_children( domain_expertise=expert, factor=factor, - factors_list=factors_list, + all_factors=all_factors, analysis_context=analysis_context ) for element in suggested_children: if ( element, factor, - ) in children_edges and element in factors_list: + ) in children_edges and element in all_factors: children_edges[(element, factor)] += 1 else: children_edges[(element, factor)] = 1 @@ -531,7 +531,7 @@ def suggest_relationships( pairwise_edges: Dict[Tuple[str, str], int] = dict() - for (factor_a, factor_b) in itertools.combinations(factors_list, 2): + for (factor_a, factor_b) in itertools.combinations(all_factors, 2): for expert in expert_list: suggested_edge = self.suggest_pairwise_relationship( domain_expertise=expert, @@ -554,7 +554,7 @@ def suggest_relationships( confounders_counter, confounders = self.suggest_confounders( treatment=treatment, outcome=outcome, - factors_list=factors_list, + all_factors=all_factors, expertise_list=expertise_list, analysis_context=analysis_context ) diff --git a/pywhyllm/suggesters/validation_suggester.py b/pywhyllm/suggesters/validation_suggester.py index 8d307ce..dcd0cc5 100644 --- a/pywhyllm/suggesters/validation_suggester.py +++ b/pywhyllm/suggesters/validation_suggester.py @@ -23,7 +23,7 @@ def suggest_negative_controls( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), expertise_list: list(), analysis_context: str = CONTEXT, stakeholders: list() = None @@ -39,16 +39,16 @@ def suggest_negative_controls( negative_controls: List[str] = list() edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] != treatment and factors_list[i] != outcome: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] != treatment and all_factors[i] != outcome: + edited_factors_list.append(all_factors[i]) for expert in expert_list: negative_controls_counter, negative_controls_list = self.request_negative_controls( treatment=treatment, outcome=outcome, - factors_list=edited_factors_list, + all_factors=edited_factors_list, negative_controls_counter=negative_controls_counter, domain_expertise=expert, analysis_context=analysis_context @@ -63,7 +63,7 @@ def request_negative_controls( self, treatment: str, outcome: str, - factors_list: list(), + all_factors: list(), negative_controls_counter: list(), domain_expertise: str, analysis_context: str = CONTEXT @@ -84,7 +84,7 @@ def request_negative_controls( lm += cleandoc(prompt_str) with user(): - prompt_str = f"""factor_names: {factors_list} From your perspective as an expert in the {domain_expertise}, what factor(s) from the list of factors, relevant to + prompt_str = f"""factor_names: {all_factors} From your perspective as an expert in the {domain_expertise}, what factor(s) from the list of factors, relevant to the {analysis_context}, should see zero treatment effect when changing the {treatment}? Which factor(s) from the list of factors, if any at all, relevant to the {analysis_context}, are negative controls on the causal mechanisms that affect the {outcome} when changing {treatment}? Using your domain knowledge, @@ -113,7 +113,7 @@ def request_negative_controls( for factor in negative_controls: # to not add it twice into the list if ( - factor in factors_list + factor in all_factors and factor not in negative_controls_list ): negative_controls_list.append(factor) @@ -227,15 +227,15 @@ def request_latent_confounders( def request_parent_critique( self, factor, - factors_list, + all_factors, domain_expertise, analysis_context: str = CONTEXT ): edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] not in factor: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] not in factor: + edited_factors_list.append(all_factors[i]) parents: List[str] = list() @@ -250,10 +250,10 @@ def request_parent_critique( lm += cleandoc(prompt_str) with user(): prompt_str = f"""Steps: (1) - Analyze potential factors [{factors_list}] for factors directly influencing/causing/affecting { + Analyze potential factors [{all_factors}] for factors directly influencing/causing/affecting { factor}. Is relationship direct? Ignore feedback mechanisms/factors not in list. Keep thoughts within tags. (2) Use prior thoughts to answer: how {factor} influenced/caused/affected by [ - {factors_list}]? Is relationship direct? Ignore feedback mechanisms/factors not in list. Wrap + {all_factors}]? Is relationship direct? Ignore feedback mechanisms/factors not in list. Wrap factors highly likely directly influencing/causing/affecting {factor} in tags. No tags for low likelihood factors. Ignore feedback mechanisms/factors not in list. Answer as {domain_expertise} expert.""" @@ -280,15 +280,15 @@ def request_parent_critique( def request_children_critique( self, factor, - factors_list, + all_factors, domain_expertise, analysis_context: str = CONTEXT ): edited_factors_list: List[str] = [] - for i in range(len(factors_list)): - if factors_list[i] not in factor: - edited_factors_list.append(factors_list[i]) + for i in range(len(all_factors)): + if all_factors[i] not in factor: + edited_factors_list.append(all_factors[i]) children: List[str] = list() @@ -305,10 +305,10 @@ def request_children_critique( with user(): prompt_str = f"""Steps: ( - 1) Analyze potential factors [{factors_list}] for factors directly influenced/caused/affected by + 1) Analyze potential factors [{all_factors}] for factors directly influenced/caused/affected by {factor}. Is relationship direct? Ignore feedback mechanisms/factors not in list. Keep thoughts within tags. (2) Use prior thoughts to answer: how {factor} influences/causes/affects [{ - factors_list}]? Is relationship direct? Ignore feedback mechanisms/factors not in list. Wrap + all_factors}]? Is relationship direct? Ignore feedback mechanisms/factors not in list. Wrap factors highly likely directly influenced/caused/affected by {factor} in tags. No tags for low likelihood factors. Ignore feedback mechanisms/factors not in list. Answer as {domain_expertise} expert.""" @@ -389,7 +389,7 @@ def request_pairwise_critique( def critique_graph( self, - factors_list: List[str], + all_factors: List[str], edges: Dict[Tuple[str, str], int], experts: list(), relationship_strategy: RelationshipStrategy = RelationshipStrategy.Pairwise, @@ -408,19 +408,19 @@ def critique_graph( parent_edges: Dict[Tuple[str, str], int] = dict() - for factor in factors_list: + for factor in all_factors: for expert in expert_list: suggested_parent = self.request_parent_critique( analysis_context=analysis_context, factor=factor, - factors_list=factors_list, + all_factors=all_factors, domain_expertise=expert ) for element in suggested_parent: if ( element, factor, - ) in parent_edges and element in factors_list: + ) in parent_edges and element in all_factors: parent_edges[(element, factor)] += 1 else: parent_edges[(element, factor)] = 1 @@ -432,16 +432,16 @@ def critique_graph( critiqued_children_edges: Dict[Tuple[str, str], int] = dict() - for factor in factors_list: + for factor in all_factors: for expert in expert_list: suggested_children = self.request_children_critique( factor=factor, - factors_list=factors_list, + all_factors=all_factors, domain_expertise=expert, analysis_context=analysis_context ) for element in suggested_children: - if (element, factor) in critiqued_children_edges and element in factors_list: + if (element, factor) in critiqued_children_edges and element in all_factors: critiqued_children_edges[(element, factor)] += 1 else: critiqued_children_edges[(element, factor)] = 1 @@ -453,7 +453,7 @@ def critique_graph( critiqued_pairwise_edges: Dict[Tuple[str, str], int] = dict() - for (factor_a, factor_b) in itertools.combinations(factors_list, 2): + for (factor_a, factor_b) in itertools.combinations(all_factors, 2): for expert in expert_list: suggested_edge = self.request_pairwise_critique( factor_a=factor_a,