The Seeds (xentica.seeds)

The package helping you to construct initial CA state (seed).

Classes from modules below are intended for use in Experiment classes.

For example to initialize the whole board with random values:

from xentica import core, seeds

class MyExperiment(core.Experiment):
    # ...
    seed = seeds.patterns.PrimordialSoup(
        vals={
            "state": seeds.random.RandInt(0, 1),
        }
   )

Patterns (xentica.seeds.patterns)

Module containing different patterns for CA seed initialization.

Each pattern class having one mandatory method generate() which is called automatically at the initialization stage.

Patterns are intended to use in Experiment classes. See the example of general usage above.

class xentica.seeds.patterns.RandomPattern(vals)

Bases: object

Base class for random patterns.

Parameters:vals – Dictionary with mixed values. May contain descriptor classes.
generate(cells, bsca)

Generate the entire initial state.

This is an abstract method, you must implement it in RandomPattern subclasses.

Parameters:
  • cells – NumPy array with cells’ states as items. The seed will be generated over this array.
  • cells_num – Total number of cells in cells array.
  • field_size – Tuple with field sizes per each dimension.
  • index_to_coord – Function translating cell’s index to coordinate.
  • pack_state – Function packing state into single integer.
class xentica.seeds.patterns.BigBang(vals, pos=None, size=None)

Bases: xentica.seeds.patterns.RandomPattern

Random init pattern, known as “Big Bang”.

Citation from The Concept:

“A small area of space is initialized with a high amount of energy and random parameters per each quantum. Outside the area, quanta has either zero or minimum possible amount of energy. This is a good test for the ability of energy to spread in empty space.”

The current implementation allows to generate a value for every cell inside specified N-cube area. Cells outside the area have zero values.

Parameters:
  • vals – Dictionary with mixed values. May contain descriptor classes.
  • pos – A tuple with the coordinates of the lowest corner of the Bang area.
  • size – A tuple with the size of Bang area per each dimension.
generate(cells, bsca)

Generate the entire initial state.

See RandomPattern.generate() for details.

class xentica.seeds.patterns.PrimordialSoup(vals)

Bases: xentica.seeds.patterns.RandomPattern

Random init pattern, known as “Primordial Soup”.

Citation from The Concept:

“Each and every quantum initially has an equally small amount of energy, other parameters are random. This is a good test for the ability of energy to self-organize in clusters from the completely uniform distribution.”

The current implementation allows to populate the entire board with generated values.

Parameters:vals – Dictionary with mixed values. May contain descriptor classes.
generate(cells, bsca)

Generate the entire initial state.

See RandomPattern.generate() for details.

class xentica.seeds.patterns.ValDict(d, parent=None)

Bases: object

Wrapper over Python dictionary.

It can keep descriptor classes along with regular values. Then, on the item getting, the necessary value is automatically obtaining either directly or via descriptor logic.

Readonly, you should set all dictionary values at the class initialization.

Example of usage:

>>> from xentica.seeds.random import RandInt
>>> from xentica.seeds.patterns import ValDict
>>> d = {'a': 2, 's': RandInt(11, 23), 'd': 3.3}
>>> vd = ValDict(d)
>>> vd['a']
2
>>> vd['s']
14
>>> vd['d']
3.3
Parameters:
  • d – Dictionary with mixed values. May contain descriptor classes.
  • parent – A reference to class holding the dictionary. Optional.
items()

Iterate over dictionary items.

keys()

Iterate over dictionary keys.

RNG (xentica.seeds.random)

The module for package-wide RNG.

The main intention is to keep separate deterministic random streams for every CellularAutomaton instance. So, is you’re initialized RNG for a particular CA with some seed, you’re get the guarantee that the random sequence will be the same, no matter how many other CA’s you’re running in parallel.

class xentica.seeds.random.LocalRandom(seed=None)

Bases: object

The holder class for the RNG sequence.

It is incapsulating both standart Python random stream and NumPy one.

Once instantiated, you can use them as follows:

from xentica.seeds.random import LocalRandom

random = LocalRandom()
# get random number from standard stream
val = random.std.randint(1, 10)
# get 100 random numbers from NumPy stream
vals = random.numpy.randint(1, 10, 100)
load(rng)

Load random state from the class.

Parameters:rngLocalRandom instance.
class xentica.seeds.random.RandInt(min_val, max_val)

Bases: object

Class, generating a sequence of random integers in some interval.

It is intended to be used in Experiment seeds. See the example of initializing CA property above.

Parameters:
  • min_val – Lower bound for random value.
  • max_val – Upper bound for random value.