Skip to content

Commit

Permalink
Fix seeds.* docs (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed Jun 20, 2019
1 parent 6fffb77 commit 7f1556e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 46 deletions.
11 changes: 6 additions & 5 deletions examples/evolife.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ class EvoLife6DExperiment(RegularExperiment):
"""Generic experiment for 6D EvoLife: 2 spatial, 4 micro-dimensions."""

word = "SP1RALS 1N HYPERSP@CE"
size = (640, 360, 3, 3, 3, 3)
pos = [0, 0, 0, 0, 0, 0]
death_speed = 25
size = (640, 380, 7, 5, 3, 3)
pos = [50, 50, 0, 0, 0, 0]
death_speed = 64
max_genes = 13
mutation_prob = 0.0001
fade_in = 63
fade_out = 18
mask_random = RandInt(0, 2 ** 26 - 1, constant=True)
seed_bang = seeds.patterns.BigBang(
pos=(0, 0, 0, 0, 0, 0),
size=(100, 100, 3, 3, 3, 3),
size=(100, 100, 1, 1, 1, 1),
vals={
"energy": RandInt(0, 1) * 255,
"rule": RandInt(0, 2 ** 26 - 1) & mask_random,
Expand All @@ -241,4 +241,5 @@ class EvoLife6DExperiment(RegularExperiment):


if __name__ == "__main__":
run_simulation(EvoLife, CrossbreedingExperiment2)
run_simulation(EvoLife6D, EvoLife6DExperiment)
# run_simulation(EvoLife, CrossbreedingExperiment2)
4 changes: 2 additions & 2 deletions xentica/seeds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
The package helping you to construct initial CA state (seed).
The package for the initial CA state (seed) generation.
Classes from modules below are intended for use in
:class:`Experiment <xentica.core.experiments.Experiment>` classes.
For example to initialize the whole board with random values::
For example, to initialize the whole board with random values::
from xentica import core, seeds
Expand Down
54 changes: 24 additions & 30 deletions xentica/seeds/patterns.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Module containing different patterns for CA seed initialization.
The module containing different patterns for CA seed initialization.
Each pattern class having one mandatory method ``generate()`` which is
Each pattern class have one mandatory method ``generate()`` which is
called automatically at the initialization stage.
Patterns are intended to use in
Patterns are intended for use in
:class:`Experiment <xentica.core.experiments.Experiment>` classes.
See the example of general usage above.
Expand All @@ -22,21 +22,21 @@


class ValDictMeta(type):
"""Placeholder for :class:`ValDict` metaclass."""
"""A placeholder for :class:`ValDict` metaclass."""


class ValDict(metaclass=ValDictMeta):
"""
Wrapper over Python dictionary.
A wrapper over the Python dictionary.
It can keep descriptor classes along with regular values. Then, on
the item getting, the necessary value is automatically obtaining
It can keep descriptor classes along with regular values. When you
get the item, the necessary value is automatically obtaining
either directly or via descriptor logic.
Readonly, you should set all dictionary values at the class
Read-only, you should set all dictionary values at the class
initialization.
Example of usage::
The example of usage::
>>> from xentica.seeds.random import RandInt
>>> from xentica.seeds.patterns import ValDict
Expand All @@ -52,12 +52,12 @@ class ValDict(metaclass=ValDictMeta):
:param d:
Dictionary with mixed values. May contain descriptor classes.
:param parent:
A reference to class holding the dictionary. Optional.
A reference to the class holding the dictionary. Optional.
"""

def __init__(self, d, parent=None):
"""Initialize class."""
"""Initialize the class."""
self._d = d
self.parent = parent
if parent is None:
Expand Down Expand Up @@ -90,26 +90,26 @@ def __setitem__(self, key, val):

class RandomPattern:
"""
Base class for random patterns.
The base class for random patterns.
:param vals:
Dictionary with mixed values. May contain descriptor classes.
"""

def __init__(self, vals):
"""Initialize class."""
"""Initialize the class."""
self._random = LocalRandom()
self.vals = ValDict(vals, self)

@property
def random(self):
"""Get random stream."""
"""Get the random stream."""
return self._random

@random.setter
def random(self, val):
"""Set random stream."""
"""Set the random stream."""
self._random = val

def __add__(self, other):
Expand All @@ -127,14 +127,9 @@ def generate(self, cells, bsca):
:param cells:
NumPy array with cells' states as items. The seed will be
generated over this array.
:param cells_num:
Total number of cells in ``cells`` array.
:param field_size:
Tuple with field sizes per each dimension.
:param index_to_coord:
Function translating cell's index to coordinate.
:param pack_state:
Function packing state into single integer.
:param bsca:
:class:`xentica.core.CellularAutomaton` instance, to access
the field's size and other attributes.
"""

Expand All @@ -149,7 +144,7 @@ def __init__(self, pattern1, pattern2):

@RandomPattern.random.setter
def random(self, val):
"""Set random stream."""
"""Set the random stream."""
self._pattern1.random = val
self._pattern2.random = val

Expand All @@ -175,16 +170,15 @@ class BigBang(RandomPattern):
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.
The current implementation generates a value for every cell inside a
specified N-cube area. Cells outside the area remain unchanged.
:param vals:
Dictionary with mixed values. May contain descriptor classes.
:param pos:
A tuple with the coordinates of the lowest corner of the Bang area.
:param size:
A tuple with the size of Bang area per each dimension.
A tuple with the size of the Bang area per each dimension.
"""

Expand Down Expand Up @@ -251,8 +245,8 @@ class PrimordialSoup(RandomPattern):
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.
The current implementation populates the entire board with
generated values.
:param vals:
Dictionary with mixed values. May contain descriptor classes.
Expand Down
21 changes: 12 additions & 9 deletions xentica/seeds/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
The main intention is to keep separate deterministic random streams
for every :class:`CellularAutomaton<xentica.core.base.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
instance. So, if you've initialized RNG for a particular CA with some
seed, you're geting the guarantee that the random sequence will be the
same, no matter how many other CA's you're running in parallel.
"""
Expand All @@ -23,7 +23,7 @@ class LocalRandom:
"""
The holder class for the RNG sequence.
It is incapsulating both standart Python random stream and NumPy one.
It is encapsulating both standard Python random stream and NumPy one.
Once instantiated, you can use them as follows::
Expand All @@ -45,7 +45,7 @@ def __init__(self, seed=None):

def load(self, rng):
"""
Load random state from the class.
Load a random state from the class.
:param rng: :class:`LocalRandom` instance.
Expand All @@ -58,13 +58,16 @@ class RandInt(PatternExpression):
"""
Class, generating a sequence of random integers in some interval.
It is intended to be used in
It is intended for use in
:class:`Experiment <xentica.core.experiments.Experiment>`
seeds. See the example of initializing CA property above.
:param min_val: Lower bound for random value.
:param max_val: Upper bound for random value.
:param constant: Is the value constant different for every cell.
:param min_val:
Lower bound for a random value.
:param max_val:
Upper bound for a random value.
:param constant:
If ``True``, will force the use of the standard random stream.
"""

Expand All @@ -77,7 +80,7 @@ def __init__(self, min_val, max_val, constant=False):

def __get__(self, instance, owner):
"""
Get the random value in specified range from standard stream.
Get random value(s) in specified range from Numpy or standard stream.
This method is used automatically from
:class:`CellularAutomaton<xentica.core.base.CellularAutomaton>`,
Expand Down

0 comments on commit 7f1556e

Please sign in to comment.