In [1]:
import numpy as np
from matplotlib import pyplot as plt
from __future__ import division
from spacetime.CA_Simulators.CAs import *
from spacetime.Local_Measures.Local_Complexity import *
%matplotlib inline

Domain 54 Transitions


In [2]:
dom_test = ECA(54,domain_54(20*4, 'a'))
dom_test.evolve(20*4)

In [7]:
diagram(dom_test.get_spacetime())



In [3]:
np.random.seed(0)
domain_states = epsilon_field(dom_test.get_spacetime())
domain_states.estimate_states(3,3,1)
domain_states.filter_data()

In [5]:
a = domain_states.state_transition((10,10), 'forward')
print a


(3, '1   1\n 1 0 \n  1  \n', 1)

In [6]:
b = domain_states.state_transition((10,10), 'right')
print b


(3, '    0\n   1 \n  0  \n', 5)

In [7]:
c = domain_states.state_transition((10,10), 'left')
print c


(3, '1    \n 1   \n  1  \n', 4)

In [8]:
print a == b


False

In [9]:
print a == a


True

In [10]:
transitions = [a, b]
print a in transitions


True

In [11]:
print c in transitions


False

In [12]:
transitions.append(c)

In [13]:
print c in transitions


True

In [14]:
print transitions


[(3, '1   1\n 1 0 \n  1  \n', 1), (3, '    0\n   1 \n  0  \n', 5), (3, '1    \n 1   \n  1  \n', 4)]

In [8]:
print '1   1\n 1 0 \n  1  '


1   1
 1 0 
  1  

In [7]:
print len(domain_states.all_transitions())


24

In [4]:
domain_states.all_transitions()


Out[4]:
[(2, 'f:10111', 8),
 (2, 'r:111', 4),
 (2, 'l:010', 5),
 (4, 'f:10011', 7),
 (4, 'r:010', 3),
 (4, 'l:010', 2),
 (3, 'f:11011', 1),
 (3, 'r:010', 5),
 (3, 'l:111', 4),
 (5, 'f:00000', 6),
 (5, 'r:000', 2),
 (5, 'l:000', 3),
 (8, 'f:00100', 3),
 (8, 'r:101', 7),
 (8, 'l:000', 6),
 (7, 'f:01100', 5),
 (7, 'r:101', 1),
 (7, 'l:101', 8),
 (1, 'f:01000', 2),
 (1, 'r:000', 6),
 (1, 'l:101', 7),
 (6, 'f:11111', 4),
 (6, 'r:111', 8),
 (6, 'l:111', 1)]

In [5]:
print domain_states.all_transitions(zipped = False)[2]


[8 4 5 7 3 2 1 5 4 6 2 3 3 7 6 5 1 8 2 6 7 4 8 1]

In [6]:
print domain_states.all_transitions()[23]


(6, 'l:111', 1)

In [9]:
state_overlay_diagram(dom_test.get_spacetime(), domain_states.get_causal_field(), t_max = 40, x_max = 40)



In [12]:
domain_states.all_transitions()


Out[12]:
[(2, 'f:10111', 8),
 (2, 'r:111', 4),
 (2, 'l:010', 5),
 (4, 'f:10011', 7),
 (4, 'r:010', 3),
 (4, 'l:010', 2),
 (3, 'f:11011', 1),
 (3, 'r:010', 5),
 (3, 'l:111', 4),
 (5, 'f:00000', 6),
 (5, 'r:000', 2),
 (5, 'l:000', 3),
 (8, 'f:00100', 3),
 (8, 'r:101', 7),
 (8, 'l:000', 6),
 (7, 'f:01100', 5),
 (7, 'r:101', 1),
 (7, 'l:101', 8),
 (1, 'f:01000', 2),
 (1, 'r:000', 6),
 (1, 'l:101', 7),
 (6, 'f:11111', 4),
 (6, 'r:111', 8),
 (6, 'l:111', 1)]

In [13]:
from_2 = []
for transition in domain_states.all_transitions():
    if transition[0] == 2:
        from_2.append(transition)

In [14]:
from_2


Out[14]:
[(2, 'f:10111', 8), (2, 'r:111', 4), (2, 'l:010', 5)]

In [4]:
print domain_states.transitions_from_state(2)


[(2, 'f:10111', 8), (2, 'r:111', 4), (2, 'l:010', 5)]

In [4]:
print domain_states.transitions_from_state(2)


[(2, 'f:10111', 8), (2, 'r:111', 4), (2, 'l:010', 5)]

In [5]:
print domain_states.transitions_from_state(2, zipped = False)


[array([2, 2, 2]), array(['f:10111', 'r:111', 'l:010'], 
      dtype='|S7'), array([8, 4, 5])]

In [6]:
to_2 = []
for transition in domain_states.all_transitions():
    if transition[2] == 2:
        to_2.append(transition)

In [7]:
to_2


Out[7]:
[(4, 'l:010', 2), (5, 'r:000', 2), (1, 'f:01000', 2)]

In [5]:
print domain_states.transitions_to_state(2)


[(4, 'l:010', 2), (5, 'r:000', 2), (1, 'f:01000', 2)]

In [4]:
print domain_states.transitions_to_state(2)


[(4, 'l:010', 2), (5, 'r:000', 2), (1, 'f:01000', 2)]

In [5]:
print domain_states.transitions_to_state(2, zipped = False)


[array([4, 5, 1]), array(['l:010', 'r:000', 'f:01000'], 
      dtype='|S7'), array([2, 2, 2])]

In [6]:
state_list = []
for state in domain_states.causal_states():
    state_list.append(state.index())

In [7]:
print state_list


[1, 2, 3, 4, 5, 6, 7, 8]

In [8]:
print np.unique(domain_states.get_causal_field())


[0 1 2 3 4 5 6 7 8]

In [18]:
to = []
sym = []
fro = []

for state in domain_states.all_transitions():
    to.append(state[0])
    sym.append(state[1])
    fro.append(state[2])
to = np.array(to)
sym = np.array(sym)
fro = np.array(fro)

In [22]:
zip(to,sym,fro)


Out[22]:
[(2, 'f:10111', 8),
 (2, 'r:111', 4),
 (2, 'l:010', 5),
 (4, 'f:10011', 7),
 (4, 'r:010', 3),
 (4, 'l:010', 2),
 (3, 'f:11011', 1),
 (3, 'r:010', 5),
 (3, 'l:111', 4),
 (5, 'f:00000', 6),
 (5, 'r:000', 2),
 (5, 'l:000', 3),
 (8, 'f:00100', 3),
 (8, 'r:101', 7),
 (8, 'l:000', 6),
 (7, 'f:01100', 5),
 (7, 'r:101', 1),
 (7, 'l:101', 8),
 (1, 'f:01000', 2),
 (1, 'r:000', 6),
 (1, 'l:101', 7),
 (6, 'f:11111', 4),
 (6, 'r:111', 8),
 (6, 'l:111', 1)]

In [24]:
test = [to, sym, fro]

In [27]:
zip(*test)


Out[27]:
[(2, 'f:10111', 8),
 (2, 'r:111', 4),
 (2, 'l:010', 5),
 (4, 'f:10011', 7),
 (4, 'r:010', 3),
 (4, 'l:010', 2),
 (3, 'f:11011', 1),
 (3, 'r:010', 5),
 (3, 'l:111', 4),
 (5, 'f:00000', 6),
 (5, 'r:000', 2),
 (5, 'l:000', 3),
 (8, 'f:00100', 3),
 (8, 'r:101', 7),
 (8, 'l:000', 6),
 (7, 'f:01100', 5),
 (7, 'r:101', 1),
 (7, 'l:101', 8),
 (1, 'f:01000', 2),
 (1, 'r:000', 6),
 (1, 'l:101', 7),
 (6, 'f:11111', 4),
 (6, 'r:111', 8),
 (6, 'l:111', 1)]

In [29]:
domain_states.all_transitions()


Out[29]:
[(2, 'f:10111', 8),
 (2, 'r:111', 4),
 (2, 'l:010', 5),
 (4, 'f:10011', 7),
 (4, 'r:010', 3),
 (4, 'l:010', 2),
 (3, 'f:11011', 1),
 (3, 'r:010', 5),
 (3, 'l:111', 4),
 (5, 'f:00000', 6),
 (5, 'r:000', 2),
 (5, 'l:000', 3),
 (8, 'f:00100', 3),
 (8, 'r:101', 7),
 (8, 'l:000', 6),
 (7, 'f:01100', 5),
 (7, 'r:101', 1),
 (7, 'l:101', 8),
 (1, 'f:01000', 2),
 (1, 'r:000', 6),
 (1, 'l:101', 7),
 (6, 'f:11111', 4),
 (6, 'r:111', 8),
 (6, 'l:111', 1)]

In [ ]:


In [4]:
np.random.seed(0)
dom_18 = ECA(18, domain_18(200))
dom_18.evolve(200)

In [5]:
np.random.seed(0)
dom_states = epsilon_field(dom_18.get_spacetime())
dom_states.estimate_states(3,3,1)
dom_states.filter_data()

In [11]:
print dom_states.number_of_states()


4

In [12]:
nonunifilar = []
for state in np.unique(dom_states.get_causal_field()):
    for i in dom_states.transitions_from_state(state):
        for j in dom_states.transitions_from_state(state):
            if i == j:
                pass
            else:
                if i[1] == j[1]:
                    nonunifilar.append(i)
                    nonunifilar.append(j)

In [13]:
print nonunifilar


[(2, 'r:000', 4), (2, 'r:000', 1), (2, 'l:000', 1), (2, 'l:000', 4), (2, 'r:000', 1), (2, 'r:000', 4), (2, 'l:000', 4), (2, 'l:000', 1), (3, 'f:00000', 1), (3, 'f:00000', 4), (3, 'f:00000', 4), (3, 'f:00000', 1)]

In [ ]:
nonunifilar = []
for state in np.unique(dom_states.get_causal_field()):
    transition_symbols = []

In [14]:
print len(dom_states.all_transitions())


37

In [25]:
fro, symb, to = dom_states.transitions_from_state(2, zipped = False)
uniques, inds, inverse, counts = np.unique(symb, True,True,True)

In [26]:
print symb


['f:00000' 'r:000' 'l:000' 'r:000' 'l:000']

In [27]:
print uniques[inverse]


['f:00000' 'r:000' 'l:000' 'r:000' 'l:000']

In [39]:
print inverse


[0 2 1 2 1]

In [29]:
print uniques
print counts


['f:00000' 'l:000' 'r:000']
[1 2 2]

In [30]:
print uniques[counts>1]


['l:000' 'r:000']

In [32]:
print zip(fro[inds[counts>1]], symb[inds[counts>1]], to[inds[counts>1]])


[(2, 'l:000', 1), (2, 'r:000', 4)]

In [33]:
print dom_states.transitions_from_state(2)


[(2, 'f:00000', 1), (2, 'r:000', 4), (2, 'l:000', 1), (2, 'r:000', 1), (2, 'l:000', 4)]

In [35]:
print np.where(counts>1)[0]


[1 2]

In [47]:
print np.where(symb == uniques[counts>1][0])[0]


[2 4]

In [49]:
print symb[(symb == uniques[counts>1][0] or symb == uniques[counts>1])][1]


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-49-588b56edf40f> in <module>()
----> 1 print symb[(symb == uniques[counts>1][0] or symb == uniques[counts>1])][1]

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

In [52]:
print symb[symb == np.any(uniques[counts>1])]


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-52-91a02a3cbf54> in <module>()
----> 1 print symb[symb == np.any(uniques[counts>1])]

/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in any(a, axis, out, keepdims)
   1968         return arr.any(axis=axis, out=out, keepdims=keepdims)
   1969     except TypeError:
-> 1970         return arr.any(axis=axis, out=out)
   1971 
   1972 

/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.pyc in _any(a, axis, dtype, out, keepdims)
     36 
     37 def _any(a, axis=None, dtype=None, out=None, keepdims=False):
---> 38     return umr_any(a, axis, dtype, out, keepdims)
     39 
     40 def _all(a, axis=None, dtype=None, out=None, keepdims=False):

TypeError: cannot perform reduce with flexible type

In [7]:
fro, symb, to = dom_states.transitions_from_state(2, zipped = False)
uniques, counts = np.unique(symb, False, False ,True)
for transition in dom_states.transitions_from_state(2):
    if transition[1] in uniques[counts>1]:
        print transition


(2, 'r:000', 4)
(2, 'l:000', 1)
(2, 'r:000', 1)
(2, 'l:000', 4)

In [8]:
fro, symb, to = dom_states.transitions_from_state(2, zipped = False)
uniques, counts = np.unique(symb, False, False ,True)
for transition in zip(fro, symb, to):
    if transition[1] in uniques[counts>1]:
        print transition


(2, 'r:000', 4)
(2, 'l:000', 1)
(2, 'r:000', 1)
(2, 'l:000', 4)

In [9]:
print np.unique(domain_states.all_transitions(zipped = False)[0])


[1 2 3 4 5 6 7 8]

In [10]:
print np.unique(dom_states.all_transitions(zipped = False)[0])


[1 2 3 4]

In [ ]:

Testing of the finalized methods in local_complexity.py

Rule 54 domain, should be no non-unifilar transitions


In [36]:
print domain_states.nonunifilar_transitions() == []


True

In [10]:
print len(domain_states.all_transitions())


24

In [6]:
print domain_states.spurious_states()


[]

Rule 18 domain, should be non-unifilar transitions going to state 4


In [9]:
print dom_states.nonunifilar_transitions()


[(2, 'r:000', 4), (2, 'l:000', 1), (2, 'r:000', 1), (2, 'l:000', 4), (3, 'f:00000', 1), (3, 'f:00000', 4)]

In [8]:
print np.all(dom_states.nonunifilar_transitions() == \
             [(2, 'r:000', 4), (2, 'l:000', 1), (2, 'r:000', 1), (2, 'l:000', 4), (3, 'f:00000', 1), (3, 'f:00000', 4)])


True

In [11]:
print len(dom_states.all_transitions())


37

Spurious state test not working out as I had hoped


In [7]:
print dom_states.spurious_states()


[]

In [10]:
print dom_states.transitions_to_state(4)


[(2, 'r:000', 4), (4, 'r:000', 4), (4, 'f:00000', 4), (4, 'l:000', 4), (2, 'l:000', 4), (3, 'f:00000', 4), (1, 'f:00000', 4)]

In [11]:
print dom_states.transitions_from_state(1)


[(1, 'f:11001', 2), (1, 'r:010', 3), (1, 'l:100', 2), (1, 'f:00011', 3), (1, 'r:011', 3), (1, 'l:010', 3), (1, 'l:011', 3), (1, 'f:10110', 2), (1, 'r:100', 2), (1, 'f:01100', 3), (1, 'r:101', 2), (1, 'f:11010', 2), (1, 'r:001', 3), (1, 'l:110', 2), (1, 'f:10101', 2), (1, 'r:110', 2), (1, 'l:001', 3), (1, 'l:101', 2), (1, 'f:01111', 3), (1, 'f:00000', 4)]

In [13]:
state_overlay_diagram(dom_18.get_spacetime(), dom_states.get_causal_field(), t_max = 50, x_max = 50)


Rule 54 from random initial condition


In [12]:
rule_54 = ECA(54, random_state(300, 2))
rule_54.evolve(300)

In [13]:
np.random.seed(0)
states_54 = epsilon_field(rule_54.get_spacetime())
states_54.estimate_states(3,3,1)
states_54.filter_data()

In [14]:
print len(states_54.all_transitions())


200

In [15]:
print states_54.nonunifilar_transitions()


[(4, 'l:010', 26), (4, 'r:010', 21), (4, 'l:010', 21), (4, 'r:010', 27)]

In [16]:
print states_54.number_of_states()


30

rule 18 from random initial condition


In [17]:
rule_18 = ECA(18, random_state(300, 2))
rule_18.evolve(300)

In [31]:
np.random.seed(0)
states_18 = epsilon_field(rule_18.get_spacetime())
states_18.estimate_states(3,3,1)
states_18.filter_data()

In [23]:
print states_18.number_of_states()


17

In [24]:
print len(states_18.all_transitions())


172

In [32]:
print len(states_18.nonunifilar_transitions())


47

same as above but now with alpha = 0 in state estimation algorithm


In [26]:
np.random.seed(0)
states_18 = epsilon_field(rule_18.get_spacetime())
states_18.estimate_states(3,3,1, alpha = 0)
states_18.filter_data()

In [27]:
print states_18.number_of_states()


5

In [28]:
print len(states_18.all_transitions())


94

In [30]:
print len(states_18.nonunifilar_transitions())


28

In [ ]:

Possible fix to numpy deprecation warning for indexing arrays with non-integer values (strings in my case)


In [46]:
print '00010'
print [0,0,0,1,0]
print np.array([0,0,0,1,0])
print np.array(list('00010')).astype(int)


00010
[0, 0, 0, 1, 0]
[0 0 0 1 0]
[0 0 0 1 0]

In [ ]:


In [ ]:

Look at spurious state tests on rule 18 domain with different lightcone depths


In [2]:
np.random.seed(0)
domain = ECA(18, domain_18(400))
domain.evolve(400)

In [3]:
np.random.seed(0)
dom_states = epsilon_field(domain.get_spacetime())
dom_states.estimate_states(3,3,1, alpha=0)
dom_states.filter_data()

In [17]:
print dom_states.spurious_states()


[]

In [7]:
print dom_states.nonunifilar_transitions()


[(2, 'r:000', 4), (2, 'l:000', 1), (2, 'r:000', 1), (2, 'l:000', 4), (3, 'f:00000', 1), (3, 'f:00000', 4)]

In [19]:
print dom_states.transitions_to_state(2)


[(2, 'f:00000', 2), (2, 'r:000', 2), (2, 'l:000', 2), (4, 'l:000', 2), (4, 'r:000', 2), (1, 'f:00000', 2), (3, 'f:00000', 2)]

In [4]:
dom_states.all_transitions()


Out[4]:
[(2, 'f:00000', 1),
 (2, 'r:000', 4),
 (2, 'l:000', 1),
 (4, 'f:11010', 2),
 (4, 'r:000', 4),
 (4, 'l:111', 2),
 (4, 'f:00000', 4),
 (4, 'l:000', 4),
 (4, 'f:10101', 2),
 (4, 'r:111', 2),
 (2, 'r:000', 1),
 (2, 'l:000', 4),
 (1, 'f:11001', 2),
 (1, 'r:010', 3),
 (1, 'l:100', 2),
 (3, 'f:00000', 1),
 (3, 'r:000', 1),
 (3, 'l:000', 1),
 (1, 'f:00011', 3),
 (1, 'r:011', 3),
 (1, 'l:010', 3),
 (1, 'l:011', 3),
 (1, 'f:10110', 2),
 (1, 'r:100', 2),
 (4, 'f:01111', 3),
 (1, 'f:01100', 3),
 (1, 'r:101', 2),
 (1, 'f:11010', 2),
 (1, 'r:001', 3),
 (1, 'l:110', 2),
 (3, 'f:00000', 4),
 (1, 'f:10101', 2),
 (1, 'r:110', 2),
 (1, 'l:001', 3),
 (1, 'l:101', 2),
 (1, 'f:01111', 3),
 (1, 'f:00000', 4)]

In [5]:
state_overlay_diagram(domain.get_spacetime(), dom_states.get_causal_field(), t_max = 40, x_max = 40)



In [ ]: