Neighbour count statistics collector script

For scripts to aid with computation or simulation in cellular automata.
Post Reply
Naszvadi
Posts: 571
Joined: May 7th, 2016, 8:53 am
Contact:

Neighbour count statistics collector script

Post by Naszvadi » December 12th, 2016, 2:48 pm

Very early phase, but it was handy for me.

Code: Select all

# Collects statistics from neighbourhood counts.
# Author: NASZVADI P., 2016 Dec 12.

import golly as g

if g.empty():
    if g.getwidth() == 0 or g.getheight() == 0:
        g.exit("Senseless!")
else:
    r = g.getrect()
    if len(r) == 0:
        g.exit("Senseless too!")
    minx = r[0]
    miny = r[1]
    maxx = minx + r[2]
    maxy = miny + r[3]
    stats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

def checkneighbour(x, y):
    return g.getcell(x, y)+2*(g.getcell(x+1, y+1)+g.getcell(x+1, y-1)+g.getcell(x-1, y+1)+g.getcell(x-1, y-1)+g.getcell(x-1, y)+g.getcell(x, y-1)+g.getcell(x, y+1)+g.getcell(x+1, y))

def neighbourstats():

    # main loop
    for x in range(minx,maxx):
        for y in range(miny,maxy):
            stats[checkneighbour(x, y)] += 1

try:
    neighbourstats()
finally:
    resultall = ""
    for j in range(9):
        for i in [0,1]:
            if i+j and stats[i+2*j]:
                resultall += "[" + `i` + ", " + `j` + "] = " + `stats[i+2*j]` + "; "
    g.show(" Results: " + resultall)
The usual disclaimer I put together with my cr@p, is not here, but is valid (e.g. my country's laws must be kept, no violation is allowed etc.)

User avatar
Rhombic
Posts: 1064
Joined: June 1st, 2013, 5:41 pm

Re: Neighbour count statistics collector script

Post by Rhombic » December 12th, 2016, 3:24 pm

It could be interesting to study the variations in neighbourhood in random soups in CGoL.

Also the variations in neighbourhood in explosive rules enclosed in large tori (for example, a random explosive soup in Seeds within a 1024x1024 torus) for frequency of neighbourhood. Of course, this could be expanded to account for all non-totalistic positions, which could end up being a bit overkill.

The other one might be studying spaceships with this, comparing to a large amount of natural still+oscillating ash, check the proportions and then infer the most stable phase of the spaceship (i.e. that closest in neighbourhood to naturally-generated random ash).
SoL : FreeElectronics : DeadlyEnemies : 6a-ite : Rule X3VI
what is “sesame oil”?

User avatar
Rhombic
Posts: 1064
Joined: June 1st, 2013, 5:41 pm

Re: Neighbour count statistics collector script

Post by Rhombic » April 3rd, 2017, 10:16 am

I have expanded the script to calculate the neighbourhood for n generations and print it in a text file. It's slightly slow for methuselae due to increasing bounding box (any ideas for improvement, especially with this particular issue, would be greatly appreciated) but interesting nonetheless.

Code: Select all

# Collects statistics from neighbourhood counts over a specified number of generations.
# Expanded from neighbour.py (Author: NASZVADI P., 2016 Dec 12.) by Rhombic

import golly as g

gens = open("neighbour_result.txt","w")
gens.write("Generation; [10]; [01]; [11]; [02]; [12]; [03]; [13]; [04]; [14]; [05]; [15]; [06]; [16]; [07]; [17]; [08]; [18]"+"\n")
allgens = int(g.getstring("Number of generations to calculate: ", "1"))
generation = 0

for generation in range(allgens):
    if g.empty():
        if g.getwidth() == 0 or g.getheight() == 0:
            g.exit("Senseless!")
    else:
        r = g.getrect()
        if len(r) == 0:
            g.exit("Senseless too!")
        minx = r[0]
        miny = r[1]
        maxx = minx + r[2]
        maxy = miny + r[3]
        stats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

    def checkneighbour(x, y):
        return g.getcell(x, y)+2*(g.getcell(x+1, y+1)+g.getcell(x+1, y-1)+g.getcell(x-1, y+1)+g.getcell(x-1, y-1)+g.getcell(x-1, y)+g.getcell(x, y-1)+g.getcell(x, y+1)+g.getcell(x+1, y))

    def neighbourstats():

        # main loop
        for x in range(minx,maxx):
            for y in range(miny,maxy):
                stats[checkneighbour(x, y)] += 1

    try:
        neighbourstats()
    finally:
        resultall = ""
        for j in range(9):
            for i in [0,1]:
                if i+j:
                    resultall += `stats[i+2*j]` + "; "
        gens.write(str(generation) + "; " + resultall + "\n")
        g.run(1)
        generation += 1
SoL : FreeElectronics : DeadlyEnemies : 6a-ite : Rule X3VI
what is “sesame oil”?

User avatar
BlinkerSpawn
Posts: 1964
Joined: November 8th, 2014, 8:48 pm
Location: Getting a snacker from R-Bee's

Re: Neighbour count statistics collector script

Post by BlinkerSpawn » April 3rd, 2017, 10:35 am

What information does this collect? Just frequency of neighbor counts or specific isotropic neighborhoods?
LifeWiki: Like Wikipedia but with more spaceships. [citation needed]

Image

User avatar
Rhombic
Posts: 1064
Joined: June 1st, 2013, 5:41 pm

Re: Neighbour count statistics collector script

Post by Rhombic » April 3rd, 2017, 10:51 am

BlinkerSpawn wrote:What information does this collect? Just frequency of neighbor counts or specific isotropic neighborhoods?
It collects the number of live cells adjacent to a dead cell [0n] or to a live cell [1n] over a number of generations.

Saving the population and correlating [12]+[03]+[13] against population of the following generation gives a linear fit of R^2 = 0.9997 for the r pentomino ( pop = 1.0005x - 1.0852; x = the sum)

Plotting born ([03]), survive ([12]+[13]), die ([11]+[14]+[15]+[16]+[17]+[18]) and ground (sum [0n] - [03]) against generations shows many interesting features for methuselae:
When "ground" drops very clearly, a diehard is likely to have disappeared.
When "survive" is fairly steady and "born" and "die" are rather low, it is likely to be a bottleneck of the kind Pi + still lives.
When "ground" grows sharply, it implies a local explosive behaviour, most probably the creation of a spark.
A low "survive" with high "born" and "die" implies a high heat, obviously.
SoL : FreeElectronics : DeadlyEnemies : 6a-ite : Rule X3VI
what is “sesame oil”?

Post Reply