In [3]:
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 *
from spacetime.Local_Measures.Spacetime_Information import *
%matplotlib inline

In [61]:
rule_18 = ECA(18, domain_18(100))
rule_18.evolve(100)

In [ ]:


In [4]:
def overlay_test(data_field, state_field, size = 20, colors = plt.cm.Greys, colorbar = False, edgecolors_option=None, \
                t_min = 0, t_max = None, x_min = 0, x_max = None, text_color = 'red'):

    h,w = np.shape(data_field)
    if t_max is None:
        t_max = h
    if x_max is None:
        x_max = w
    H = t_max - t_min
    W = x_max - x_min
    t_ind = np.arange(t_min, t_max, 1)
    x_ind = np.arange(x_min, x_max, 1)
    x, y = np.meshgrid(x_ind, t_ind)
    if colorbar:
        plt.figure(figsize = (size, (H/W)*size))
        plt.pcolor(data_field, cmap=colors, edgecolors=edgecolors_option)
        plt.colorbar()
        plt.axis('tight')
        plt.axis([x_min, x_max, t_min, t_max])
        plt.gca().invert_yaxis()
        #add state label text
        for x_val, y_val in zip(x.flatten(), y.flatten()):
            c = state_field[y_val][x_val]
            plt.text(x_val+0.5, y_val+0.5, c, va='center', ha='center', color = text_color)
        plt.show()
    else:
        plt.figure(figsize = (size, (H/W)*size))
        plt.pcolor(data_field, cmap=colors, edgecolors=edgecolors_option)
        plt.axis('tight')
        plt.axis([x_min, x_max, t_min, t_max])
        plt.gca().invert_yaxis()
        #add state label text
        for x_val, y_val in zip(x.flatten(), y.flatten()):
            c = state_field[y_val][x_val]
            plt.text(x_val+0.5, y_val+0.5, c, va='center', ha='center', color = text_color)
        plt.show()

Tests overlaying rule 18 values on top of spacetime diagram


In [67]:
overlay_test(rule_18.get_spacetime(),rule_18.get_spacetime(),t_max=20, x_max=20, text_color='red')



In [68]:
overlay_test(rule_18.get_spacetime(),rule_18.get_spacetime(),t_max=20, x_max=20, colors=plt.cm.Set2, text_color='black')



In [70]:
overlay_test(rule_18.get_spacetime(),rule_18.get_spacetime(),t_max=20, x_max=20, colorbar=True)



In [ ]:

Tests overlaying inferred states on top of rule 18 spacetime diagram


In [71]:
rule_18 = ECA(18, domain_18(500))
rule_18.evolve(500)

In [72]:
states_18 = epsilon_field(rule_18.get_spacetime())
states_18.estimate_states(3,3,1,alpha=0)
states_18.filter_data()

In [73]:
overlay_test(rule_18.get_spacetime(), states_18.get_causal_field(), t_min=200, t_max=240, x_min=200, x_max=240)



In [75]:
overlay_test(rule_18.get_spacetime(), states_18.get_causal_field(), t_min=200, t_max=220, x_min=200, x_max=220)



In [76]:
print states_18.get_causal_field()[200:220, 200:220]


[[1 2 1 2 3 2 1 2 1 4 1 2 3 2 1 4 4 4 4 4]
 [2 3 2 1 4 1 2 3 2 3 2 1 2 1 2 1 4 4 4 4]
 [3 2 1 2 3 2 1 2 3 2 1 2 3 2 3 2 1 4 4 4]
 [4 1 2 1 2 1 2 1 4 1 2 1 2 3 2 1 2 1 4 1]
 [1 2 3 2 3 2 3 2 3 2 3 2 1 4 1 2 3 2 3 2]
 [2 1 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1]
 [1 2 1 4 4 4 4 4 4 4 1 2 1 2 1 2 1 4 1 2]
 [2 3 2 1 4 4 4 4 4 1 2 3 2 3 2 3 2 3 2 1]
 [1 2 1 2 1 4 4 4 1 2 1 2 3 2 3 2 3 2 1 2]
 [2 3 2 3 2 1 4 1 2 3 2 1 4 4 4 4 4 1 2 3]
 [1 2 3 2 1 2 3 2 1 2 1 2 1 4 4 4 1 2 1 2]
 [2 1 4 1 2 1 2 1 2 3 2 3 2 1 4 1 2 3 2 3]
 [1 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 3 2]
 [2 1 2 3 2 3 2 1 2 1 4 1 2 1 2 1 2 1 4 4]
 [1 2 1 4 4 4 1 2 3 2 3 2 3 2 3 2 3 2 1 4]
 [2 3 2 1 4 1 2 1 2 3 2 3 2 3 2 3 2 1 2 1]
 [1 2 1 2 3 2 3 2 1 4 4 4 4 4 4 4 1 2 3 2]
 [2 3 2 1 2 3 2 1 2 1 4 4 4 4 4 1 2 1 2 3]
 [1 2 1 2 1 4 1 2 3 2 1 4 4 4 1 2 3 2 1 4]
 [2 3 2 3 2 3 2 1 2 1 2 1 4 1 2 1 2 1 2 1]]

In [ ]: