Exemplo n.º 1
0
def CAplot(rule, n, initiate):
    ca = CA.CA(rule, n)
    if initiate == "single":
        ca.start_single()
    else:
        ca.start_random()
    ca.loop(n - 1)
    drawer = CADrawer.PyplotDrawer()
    drawer.draw(ca)
Exemplo n.º 2
0
            return 1.0
#2.0,3.0 funny pattern
        else:
            return cur / 2.0


#            return cur/2.000000001
#tipping point, 2.0 -> grid, little more? no grid
    else:
        if 3 <= t < 4:
            return 1.
        else:
            return 0.

if __name__ == '__main__':
    img = array(
        I.open('Pics/building.jpg').resize((36 * 5, 48 * 5)).convert('L'))
    img = img / float(img.max())
    simulator = CA.CA(img, radius=1, rule=life_game_rule)

    plt.ion()
    simulator.plot()
    raw_input('sizing')
    iter = 0
    while iter < 1000:
        plt.clf()
        simulator.update()
        simulator.plot()
        plt.draw()
#        raw_input('pause')
        for j in range(len(cells[i])):
            if [i, j] not in input_data:
                test_inputs.append([i, j])
                targets.append([cells[i][j]])

    return torch.Tensor(np.array(input_data)), torch.Tensor(np.array(output_data)), torch.Tensor(np.array(test_inputs)), torch.Tensor(np.array(targets))

def display_results(x, y):
    plt.plot(x, y)
    plt.show()

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                                Main
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if __name__ == "__main__":
    ca = CA(N, N)
    for i in range(1000):
        ca.generate()
        if SHOW_MAP:
            plt.imshow(ca.get_cells(), cmap=plt.cm.gray, interpolation='nearest')
            plt.pause(0.01)
        if ca.check_for_stability():
            plt.title("Stable")
            plt.imshow(ca.get_cells(), cmap=plt.cm.gray, interpolation='nearest')
            plt.show()
            print("Generation: {}".format(i))
            break
    
    train_x, train_y, test_x, test_y = get_testing_data(ca.get_cells())

    runs = []
Exemplo n.º 4
0
import CA
from numpy.random import binomial
import matplotlib.pyplot as plt

def life_game_rule(k):
    cur = k[len(k)/2]
    t = (k==1).sum() - cur
    return (cur == 1 and int(t==2 or t==3)) or (cur != 1 and int(t==3))

if __name__ == '__main__':
    simulator = CA.CA(binomial(1, 0.15, (20, 40)), 1, life_game_rule, circular = True)

    plt.ion()
    simulator.plot()
    raw_input('sizing')
    iter = 0
    while iter < 1000:
        plt.clf()
        simulator.update()
        simulator.plot()
        plt.draw()

Exemplo n.º 5
0
#alpha = .9, portation = .2 is good

    ind = acc.flatten().argsort()[::-1]
    l, w = arg_grid.shape[:2]
    bp = int(l * w * .1)
#.2 no noise, little fuzzy
    for i in range(bp):
        cur_grid[ind[i]/w, ind[i]%w] = 1.
    for i in range(bp, l * w):
        cur_grid[ind[i]/w, ind[i]%w] = 0.
    return cur_grid


if __name__ == '__main__':
    img = array(I.open('Pics/road.jpg').resize((1024, 548)).convert('L'))
    img = img/float(img.max())
    simulator = CA.CA(img, radius = 1, rule = detector, global_update = True)



    plt.ion()
    simulator.plot()
    raw_input('sizing')
    iter = 0
    while iter < 1000:
        plt.clf()
        simulator.update()
        simulator.plot()
        plt.draw()
        raw_input('pause')
Exemplo n.º 6
0
            return 1.0
#2.0,3.0 funny pattern
        else:
            return cur / 2.0


#            return cur/2.000000001
#tipping point, 2.0 -> grid, little more? no grid
    else:
        if 3 <= t < 4:
            return 1.
        else:
            return 0.

if __name__ == '__main__':
    simulator = CA.CA(binomial(1, 0.15, (40, 40)),
                      1,
                      life_game_rule,
                      circular=False)

    plt.ion()
    simulator.plot()
    raw_input('sizing')
    iter = 0
    while iter < 1000:
        plt.clf()
        simulator.update()
        simulator.plot()
        plt.draw()
#        raw_input('pause')
Exemplo n.º 7
0
from CA import *
from CADrawer import *

# for i in xrange(256):
rule = 110
n = 300

ca = CA(rule, n)
ca.start_comp()
# ca.start_random()
ca.loop(n - 1)

drawer = PyplotDrawer()
drawer.draw(ca)
drawer.show()
raw_input('')