wmayner / pyphi

A toolbox for integrated information theory.
https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006343
Other
368 stars 98 forks source link

Refactor tpm functions into ExplicitTPM class #69

Closed isacdaavid closed 1 year ago

isacdaavid commented 1 year ago

This change leaves the TPM functionality and API almost untouched, while also refactoring it into a parent TPM class and an ExplicitTPM subclass, which takes the codebase closer to having another ImplicitTPM subclass with xarray.

Test results before and after these commits (I only see one lingering test I have yet to look at, test_network_from_json):

Before

============================================================================================= short test summary info ============================================================================================= FAILED test/test_subsystem_cause_effect_info.py::test_cause_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_cause_effect_info.py::test_effect_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_cause_effect_info.py::test_cause_effect_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_expand.py::test_expand_effect_repertoire - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected0] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ┌─... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected2] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B]\n Purview: [B,C]\n Specified state(s): \n [1, 0]\n Direction: CAUSE\n MIP:\n A B ∅ \n ─── ✕ ─── ✕ ───\n ... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected3] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B,C]\n Purview: [A,B,C]\n Specified state(s): \n [1, 1, 0]\n Direction: CAUSE\n MIP:\n B A,C ∅ \n ─── ✕ ─── ✕ ─... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected4] - assert Maximally-irreducible effect\n φ = 1/2\n Mechanism: [B]\n Purview: [A]\n Specified state(s): \n [0]\n Direction: EFFECT\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ A \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected5] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [A,B]\n Specified state(s): \n [0, 0]\n [1, 0]\n Direction: EFFECT\n MIP:\n C ∅ \n ─── ✕ ───\n ∅ A,B\n ... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected6] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: EFFECT\n MIP:\n A,B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected7] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B,C]\n Purview: [A,C]\n Specified state(s): \n [0, 1]\n Direction: EFFECT\n MIP:\n A B,C ∅ \n ─── ✕ ─── ✕ ───\n ∅ A,C... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut8-CAUSE-expected8] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ┌─... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut13-EFFECT-expected13] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [B]\n Specified state(s): \n [0]\n Direction: EFFECT\n MIP:\n C ∅ \n ─── ✕ ───\n ∅ B \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut14-EFFECT-expected14] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: EFFECT\n MIP:\n A,B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected0] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ┌─... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected2] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B]\n Purview: [B,C]\n Specified state(s): \n [1, 0]\n Direction: CAUSE\n MIP:\n A B ∅ \n ─── ✕ ─── ✕ ───\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected3] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B,C]\n Purview: [A,B,C]\n Specified state(s): \n [1, 1, 0]\n Direction: CAUSE\n MIP:\n B A,C ∅ \n ─── ✕ ─── ✕ ─... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected4] - assert Maximally-irreducible effect\n φ = 1/2\n Mechanism: [B]\n Purview: [A]\n Specified state(s): \n [0]\n Direction: EFFECT\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ A \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected5] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [A,B]\n Specified state(s): \n [0, 0]\n [1, 0]\n Direction: EFFECT\n MIP:\n C ∅ \n ─── ✕ ───\n ∅ A,B\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected6] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: EFFECT\n MIP:\n A,B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected7] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B,C]\n Purview: [A,C]\n Specified state(s): \n [0, 1]\n Direction: EFFECT\n MIP:\n A B,C ∅ \n ─── ✕ ─── ✕ ───\n ∅ A,C... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut8-CAUSE-expected8] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE\n MIP:\n B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ┌─... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut13-EFFECT-expected13] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [B]\n Specified state(s): \n [0]\n Direction: EFFECT\n MIP:\n C ∅ \n ─── ✕ ───\n ∅ B \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut14-EFFECT-expected14] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: EFFECT\n MIP:\n A,B ∅ \n ─── ✕ ───\n ∅ C \n Repertoire:\n ... FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism0-0.25] - assert False FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism2-0.333333] - assert False FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism3-0.4999995] - assert False FAILED test/test_subsystem_small_phi.py::test_find_mip[CAUSE-subsystem0-None-mechanism0-purview0-expected0] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[CAUSE-subsystem1-cut1-mechanism1-purview1-expected1] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem2-None-mechanism2-purview2-expected2] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem3-cut3-mechanism3-purview3-expected3] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem4-cut4-mechanism4-purview4-expected4] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem5-cut5-mechanism5-purview5-expected5] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem6-cut6-mechanism6-purview6-expected6] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_cause_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_effect_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_cause_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_cause_mip_reducible - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_effect_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_effect_mip_reducible - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' ERROR test/test_macro_subsystem.py::test_cut_indices - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_cut_mechanisms - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_cut_node_labels_are_for_micro_elements - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_concept_str_uses_macro_node_labels - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_node_labels - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_macro_subsystem - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_macro_cut_subsystem - ValueError: Invalid TPM: probabilities must sum to 1. ================================================================= 41 failed, 161 passed, 1 skipped, 560 deselected, 2 xfailed, 7 errors in 31.17s =================================================================

After

============================================================================================= short test summary info ============================================================================================= FAILED test/test_json.py::test_network_from_json - TypeError: '<' not supported between instances of 'dict' and 'float' FAILED test/test_subsystem_cause_effect_info.py::test_cause_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_cause_effect_info.py::test_effect_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_cause_effect_info.py::test_cause_effect_info - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_expand.py::test_expand_effect_repertoire - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO [closed]> FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected0] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected2] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B]\n Purview: [B,C]\n Specified state(s): \n [1, 0... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-CAUSE-expected3] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B,C]\n Purview: [A,B,C]\n Specified state(s): \n [... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected4] - assert Maximally-irreducible effect\n φ = 1/2\n Mechanism: [B]\n Purview: [A]\n Specified state(s): \n [0]\n Direction: E... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected5] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [A,B]\n Specified state(s): \n [0, 0]\n [1, 0]... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected6] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: E... FAILED test/test_subsystem_phi_max.py::test_find_mice[None-EFFECT-expected7] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B,C]\n Purview: [A,C]\n Specified state(s): \n [0, 1]\n Direc... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut8-CAUSE-expected8] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUSE... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut13-EFFECT-expected13] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [B]\n Specified state(s): \n [0]\n Direction: E... FAILED test/test_subsystem_phi_max.py::test_find_mice[cut14-EFFECT-expected14] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction:... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected0] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUS... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected2] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B]\n Purview: [B,C]\n Specified state(s): \n [1, ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-CAUSE-expected3] - assert Maximally-irreducible cause\n φ = 0.5849625007212\n Mechanism: [A,B,C]\n Purview: [A,B,C]\n Specified state(s): \n ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected4] - assert Maximally-irreducible effect\n φ = 1/2\n Mechanism: [B]\n Purview: [A]\n Specified state(s): \n [0]\n Direction: ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected5] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [A,B]\n Specified state(s): \n [0, 0]\n [1, 0]... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected6] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction: ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[None-EFFECT-expected7] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B,C]\n Purview: [A,C]\n Specified state(s): \n [0, 1]\n Dire... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut8-CAUSE-expected8] - assert Maximally-irreducible cause\n φ = 1\n Mechanism: [B]\n Purview: [C]\n Specified state(s): \n [0]\n Direction: CAUS... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut13-EFFECT-expected13] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [C]\n Purview: [B]\n Specified state(s): \n [0]\n Direction: ... FAILED test/test_subsystem_phi_max.py::test_mic_or_mie[cut14-EFFECT-expected14] - assert Maximally-irreducible effect\n φ = 1\n Mechanism: [A,B]\n Purview: [C]\n Specified state(s): \n [1]\n Direction... FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism0-0.25] - assert False FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism2-0.333333] - assert False FAILED test/test_subsystem_phi_max.py::test_phi_max[None-mechanism3-0.4999995] - assert False FAILED test/test_subsystem_small_phi.py::test_find_mip[CAUSE-subsystem0-None-mechanism0-purview0-expected0] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[CAUSE-subsystem1-cut1-mechanism1-purview1-expected1] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem2-None-mechanism2-purview2-expected2] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem3-cut3-mechanism3-purview3-expected3] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem4-cut4-mechanism4-purview4-expected4] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem5-cut5-mechanism5-purview5-expected5] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_find_mip[EFFECT-subsystem6-cut6-mechanism6-purview6-expected6] - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_cause_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_effect_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_cause_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_cause_mip_reducible - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_effect_mip - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi_effect_mip_reducible - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' FAILED test/test_subsystem_small_phi.py::test_phi - TypeError: iit_4_small_phi_no_absolute_value() missing 1 required positional argument: 'state' ERROR test/test_macro_subsystem.py::test_cut_indices - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_cut_mechanisms - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_cut_node_labels_are_for_micro_elements - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_concept_str_uses_macro_node_labels - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_node_labels - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_macro_subsystem - ValueError: Invalid TPM: probabilities must sum to 1. ERROR test/test_macro_subsystem.py::test_macro_cut_subsystem - ValueError: Invalid TPM: probabilities must sum to 1. ================================================================= 42 failed, 160 passed, 1 skipped, 560 deselected, 2 xfailed, 7 errors in 10.13s =================================================================