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
    
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
    
    
In [6]:
    
b = domain_states.state_transition((10,10), 'right')
print b
    
    
In [7]:
    
c = domain_states.state_transition((10,10), 'left')
print c
    
    
In [8]:
    
print a == b
    
    
In [9]:
    
print a == a
    
    
In [10]:
    
transitions = [a, b]
print a in transitions
    
    
In [11]:
    
print c in transitions
    
    
In [12]:
    
transitions.append(c)
    
In [13]:
    
print c in transitions
    
    
In [14]:
    
print transitions
    
    
In [8]:
    
print '1   1\n 1 0 \n  1  '
    
    
In [7]:
    
print len(domain_states.all_transitions())
    
    
In [4]:
    
domain_states.all_transitions()
    
    Out[4]:
In [5]:
    
print domain_states.all_transitions(zipped = False)[2]
    
    
In [6]:
    
print domain_states.all_transitions()[23]
    
    
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]:
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]:
In [4]:
    
print domain_states.transitions_from_state(2)
    
    
In [4]:
    
print domain_states.transitions_from_state(2)
    
    
In [5]:
    
print domain_states.transitions_from_state(2, zipped = False)
    
    
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]:
In [5]:
    
print domain_states.transitions_to_state(2)
    
    
In [4]:
    
print domain_states.transitions_to_state(2)
    
    
In [5]:
    
print domain_states.transitions_to_state(2, zipped = False)
    
    
In [6]:
    
state_list = []
for state in domain_states.causal_states():
    state_list.append(state.index())
    
In [7]:
    
print state_list
    
    
In [8]:
    
print np.unique(domain_states.get_causal_field())
    
    
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]:
In [24]:
    
test = [to, sym, fro]
    
In [27]:
    
zip(*test)
    
    Out[27]:
In [29]:
    
domain_states.all_transitions()
    
    Out[29]:
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()
    
    
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
    
    
In [ ]:
    
nonunifilar = []
for state in np.unique(dom_states.get_causal_field()):
    transition_symbols = []
    
In [14]:
    
print len(dom_states.all_transitions())
    
    
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
    
    
In [27]:
    
print uniques[inverse]
    
    
In [39]:
    
print inverse
    
    
In [29]:
    
print uniques
print counts
    
    
In [30]:
    
print uniques[counts>1]
    
    
In [32]:
    
print zip(fro[inds[counts>1]], symb[inds[counts>1]], to[inds[counts>1]])
    
    
In [33]:
    
print dom_states.transitions_from_state(2)
    
    
In [35]:
    
print np.where(counts>1)[0]
    
    
In [47]:
    
print np.where(symb == uniques[counts>1][0])[0]
    
    
In [49]:
    
print symb[(symb == uniques[counts>1][0] or symb == uniques[counts>1])][1]
    
    
In [52]:
    
print symb[symb == np.any(uniques[counts>1])]
    
    
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
    
    
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
    
    
In [9]:
    
print np.unique(domain_states.all_transitions(zipped = False)[0])
    
    
In [10]:
    
print np.unique(dom_states.all_transitions(zipped = False)[0])
    
    
In [ ]:
    
    
Rule 54 domain, should be no non-unifilar transitions
In [36]:
    
print domain_states.nonunifilar_transitions() == []
    
    
In [10]:
    
print len(domain_states.all_transitions())
    
    
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()
    
    
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)])
    
    
In [11]:
    
print len(dom_states.all_transitions())
    
    
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)
    
    
In [11]:
    
print dom_states.transitions_from_state(1)
    
    
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())
    
    
In [15]:
    
print states_54.nonunifilar_transitions()
    
    
In [16]:
    
print states_54.number_of_states()
    
    
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()
    
    
In [24]:
    
print len(states_18.all_transitions())
    
    
In [32]:
    
print len(states_18.nonunifilar_transitions())
    
    
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()
    
    
In [28]:
    
print len(states_18.all_transitions())
    
    
In [30]:
    
print len(states_18.nonunifilar_transitions())
    
    
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)
    
    
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()
    
    
In [19]:
    
print dom_states.transitions_to_state(2)
    
    
In [4]:
    
dom_states.all_transitions()
    
    Out[4]:
In [5]:
    
state_overlay_diagram(domain.get_spacetime(), dom_states.get_causal_field(), t_max = 40, x_max = 40)
    
    
In [ ]: