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

ValueError: math domain error #51

Closed 7beggars closed 2 years ago

7beggars commented 2 years ago
from graphiit import Graph
import pyphi
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)

pyphi.config.PARALLEL_CONCEPT_EVALUATION = True
pyphi.config.NUMBER_OF_CORES = -1
pyphi.config.MAXIMUM_CACHE_MEMORY_PERCENTAGE = 100

graph_config = [
('A','AND','B','C','D','E','F','G','H','I','J','K','L'),
('B','NAND','A','C','D','E','F','G','H','I','J','K','L'),
('C','OR','A','B','D','E','F','G','H','I','J','K','L'),
('D','COPY','A'),
('E','NOR','A','B','C','D','F','G','H','I','J','K','L'),
('F','NOT','A'),
('G','XOR','A','B','C','D','E','F','H','I','J','K','L'),
('H','XNOR','A','B','C','D','E','F','G','I','J','K','L'),
('I','MAJORITY','A','B','C','D','E','F','G','H','J','K','L'),
('J','MAJ','A','B','C','D','E','F','G','H','I','K','L'),
('K','MINORITY','A','B','C','D','E','F','G','H','I','J','L'),
('L','MIN','A','B','C','D','E','F','G','H','I','J','K')
]

graph = Graph(graph_config)

network = graph.pyphi_network()

state = (0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1)

subsystem = pyphi.Subsystem(network, state)

A, B, C, D, E, F, G, H, I, J, K, L = subsystem.node_indices

following the guidelines in https://pyphi.readthedocs.io/en/latest/examples/actual_causation.html:

X = Y = (A, B, C, D, E, F, G, H, I, J, K, L)

X_state = Y_state = (0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1)

transition = actual.Transition(network, X_state, Y_state, X, Y)

everything happens normally but when I do:

>>> transition.find_actual_cause((B, C))

or

account = actual.account(transition)
print(account) 

get error:


~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_actual_cause(self, mechanism, purviews)
    435     def find_actual_cause(self, mechanism, purviews=False):
    436         """Return the actual cause of a mechanism."""
--> 437         return self.find_causal_link(Direction.CAUSE, mechanism, purviews)
    438 
    439     def find_actual_effect(self, mechanism, purviews=False):

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_causal_link(self, direction, mechanism, purviews, allow_neg)
    426         else:
    427             # This max should be most positive
--> 428             max_ria = max(self.find_mip(direction, mechanism, purview,
    429                                         allow_neg)
    430                           for purview in purviews)

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in <genexpr>(.0)
    426         else:
    427             # This max should be most positive
--> 428             max_ria = max(self.find_mip(direction, mechanism, purview,
    429                                         allow_neg)
    430                           for purview in purviews)

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_mip(self, direction, mechanism, purview, allow_neg)
    342             partitioned_probability = self.partitioned_probability(
    343                 direction, partition)
--> 344             alpha = log2(probability / partitioned_probability)
    345 
    346             # First check for 0

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in log2(x)
     40 def log2(x):
     41     """Rounded version of ``log2``."""
---> 42     return round(_log2(x), config.PRECISION)
     43 
     44 

ValueError: math domain error

I know it's more likely that I'm doing something inappropriate, but I did not understand what ...

Also if:

transition.find_actual_cause((K, K))

then ...

CausalLink
  α = 0.413  [A, C, D] ◀━━ [K, K]

why? whether alpha smaller than 10 ** (- constant.epsilon), should returnalpha = 0.0 and:

Filter out causal links with zero alpha

return DirectedAccount(filter(None, links))
7beggars commented 2 years ago

Now I see that this is due to a mess of me. I declared an unlikely Y_state when conditioning to the previous state X_state and this resulted in the described error.