import GridBasedModel from 'Artistoo/src/models/GridBasedModel.js'
public class | source

GridBasedModel

Direct Subclass:

CA, CPM

Indirect Subclass:

CPMEvol

Base class for grid-based models. This class is not used by itself; see CPM for a Cellular Potts Model and CA for a Cellular Automaton.

Constructor Summary

Public Constructor
public

constructor(extents: GridSize, conf: object, seed: number)

The constructor of a GridBasedModel automatically attaches a grid of class Grid2D or Grid3D, depending on the grid dimensions given in the 'extents' parameter.

Member Summary

Public Members
public

cellvolume: *[]

This tracks the volumes of all non-background cells on the grid.

public

Input parameter settings; see the constructor of subclasses documentation.

public

Size of the grid.

public

Size of the grid in object format.

public

grid: *

public

Midpoint of the grid.

public

Attach a random number generation with a seed.

public

Dimensionality of the grid

public

The Grid2D#neighi or Grid3D#neighi iterator function of the underlying grid.

public

The Grid2D#pixels or Grid3D#pixels iterator function of the underlying grid.

public

The Grid#pixti iterator function of the underlying grid.

public

Cached values of these stats.

public

Objects of class Stat that have been computed on this model.

public

Tracks the elapsed time in MCS

Method Summary

Public Methods
public

Iterator for all the CellIds that are currently on the grid.

public

Get the CellKind of the cell with CellId t.

public

getStat(s: Stat): anything

Compute a statistic on this model.

public

neigh(p: ArrayCoordinate, torus: boolean[]): *

Get neighbourhood of position p, using neighborhood functions of the underlying grid class.

public

Get CellId of the pixel at coordinates p.

public

ran(incl_min: number, incl_max: number): number

Get a random integer number between incl_min and incl_max, uniformly sampled.

public

Get a random number from the seeded number generator.

public

Change the pixel at position p into CellId t.

public

Change the pixel at position i into CellId t.

public abstract

Update the grid in one timestep.

Public Constructors

public constructor(extents: GridSize, conf: object, seed: number) source

The constructor of a GridBasedModel automatically attaches a grid of class Grid2D or Grid3D, depending on the grid dimensions given in the 'extents' parameter. Configuration options for the model can be supplied in 'conf'.

Params:

NameTypeAttributeDescription
extents GridSize

the size of the grid of the model.

conf object

configuration options. See below for its elements, but subclasses can have more.

conf.torus boolean[]
  • optional
  • default: [true,true,...]

should the grid have linked borders?

conf.hexGrid boolean
  • optional
  • default: false

should the grid be hexagonal? Grids are square by default.

seed number
  • optional

seed for the random number generator. If left unspecified, a random number from the Math.random() generator is used to make one.

Public Members

public cellvolume: *[] source

This tracks the volumes of all non-background cells on the grid. cellvolumes will be added with key = CellId, value = volume. @type{number[]}

public conf: object source

Input parameter settings; see the constructor of subclasses documentation.

public extents: GridSize source

Size of the grid.

public field_size: object source

Size of the grid in object format.

public grid: * source

public midpoint: ArrayCoordinate source

Midpoint of the grid.

public mt: MersenneTwister source

Attach a random number generation with a seed.

public ndim: number source

Dimensionality of the grid

public neighi: function source

The Grid2D#neighi or Grid3D#neighi iterator function of the underlying grid.

public pixels: function source

The Grid2D#pixels or Grid3D#pixels iterator function of the underlying grid.

public pixti: function source

The Grid#pixti iterator function of the underlying grid.

public stat_values: object source

Cached values of these stats. Object with stat name as key and its cached value as value. The cache must be cleared when the grid changes!

public stats: Stat source

Objects of class Stat that have been computed on this model.

public time: number source

Tracks the elapsed time in MCS

Public Methods

public * cellIDs(): CellId source

Iterator for all the CellIds that are currently on the grid.

Return:

CellId

public cellKind(t: CellId): CellKind source

Get the CellKind of the cell with CellId t. For this model, they are just the same.

Params:

NameTypeAttributeDescription
t CellId

id of the cell to get kind of.

Return:

CellKind

the cellkind.

public getStat(s: Stat): anything source

Compute a statistic on this model. If necessary, this produces an object of the right Stat subclass and runs the compute method. Stats are cached because many stats use each other; this prevents that 'expensive' stats are computed twice.

Params:

NameTypeAttributeDescription
s Stat

the stat to compute.

Return:

anything

the value of the computed stat. This is often a CellObject or a CellArrayObject.

Example:

let CPM = require( "path/to/dir")
let C = new CPM.CPM( [200,200], {T:20, torus:[false,false]} )
let gm = new CPM.GridManipulator( C )
gm.seedCell( 1 )
gm.seedCell( 1 )
C.getStat( Centroids )

public neigh(p: ArrayCoordinate, torus: boolean[]): * source

Get neighbourhood of position p, using neighborhood functions of the underlying grid class.

Params:

NameTypeAttributeDescription
p ArrayCoordinate

coordinate of a pixel to get the neighborhood of.

torus boolean[]
  • optional
  • default: [true,true,...]

Does the grid have linked borders? If left unspecified, this is determined by this.conf.torus.

Return:

*

public pixt(p: ArrayCoordinate): CellId source

Get CellId of the pixel at coordinates p.

Params:

NameTypeAttributeDescription
p ArrayCoordinate

pixel to get cellid of.

Return:

CellId

ID of the cell p belongs to.

public ran(incl_min: number, incl_max: number): number source

Get a random integer number between incl_min and incl_max, uniformly sampled.

Params:

NameTypeAttributeDescription
incl_min number

lower end of the sampling range.

incl_max number

upper end of the sampling range.

Return:

number

the randomly sampled integer.

public random(): number source

Get a random number from the seeded number generator.

Return:

number

a random number between 0 and 1, uniformly sampled.

public setpix(p: ArrayCoordinate, t: CellId) source

Change the pixel at position p into CellId t. This just calls the setpixi method internally.

Params:

NameTypeAttributeDescription
p ArrayCoordinate

coordinate of pixel to change.

t CellId

cellid to change this pixel into.

public setpixi(i: IndexCoordinate, t: CellId) source

Change the pixel at position i into CellId t. This standard implementation also keeps track of cell volumes for all nonzero cell IDs. Subclasses may want to do more, such as also keeping track of perimeters or even centroids. In that case, this method needs to be overridden.

See also setpix for a method working with ArrayCoordinates.

Params:

NameTypeAttributeDescription
i IndexCoordinate

coordinate of pixel to change.

t CellId

cellid to change this pixel into.

public abstract timeStep() source

Update the grid in one timestep. This method is model-dependent and must be implemented in the subclass.