## Neighbour count statistics collector script

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

### Neighbour count statistics collector script

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
miny = r
maxx = minx + r
maxy = miny + r
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.)

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

### Re: Neighbour count statistics collector script

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”?

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

### Re: Neighbour count statistics collector script

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; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; "+"\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
miny = r
maxx = minx + r
maxy = miny + r
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”?

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

### Re: Neighbour count statistics collector script

What information does this collect? Just frequency of neighbor counts or specific isotropic neighborhoods?
LifeWiki: Like Wikipedia but with more spaceships. [citation needed] Rhombic
Posts: 1064
Joined: June 1st, 2013, 5:41 pm

### Re: Neighbour count statistics collector script

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 ++ 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 (), survive (+), die (+++++) and ground (sum [0n] - ) 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”?