CPM
Extends:
Direct Subclass:
The core CPM class. Can be used for two- or three-dimensional simulations.
Constructor Summary
Public Constructor | ||
public |
constructor(field_size: GridSize, conf: object) The constructor of class CA. |
Member Summary
Public Members | ||
public |
track border pixels for speed |
|
public |
cellvolume: *[] |
|
public |
Array of objects of (@link HardConstraint) subclasses attached to the CPM. |
|
public |
Object showing which constraints are where in soft_constraints. |
|
public |
To check from outside if an object is a CPM; doing this with instanceof doesn't work in some cases. Any other object will not have this variable and return 'undefined', which in an if-statement equates to a 'false'. @type{boolean} |
|
public |
Highest cell ID previously assigned. |
|
public |
Number of non-background cells currently on the grid. |
|
public get |
|
|
public |
Array of functions that need to be executed after every timeStep event. |
|
public |
Array of functions that need to be executed after every setpixi event. |
|
public |
Array of objects of (@link SoftConstraint) subclasses attached to the CPM. |
|
public |
Object showing which constraints are where in soft_constraints. |
|
public |
stat_values: {} |
|
public |
Store the {@CellKind} of each cell on the grid. |
|
public |
Track time in MCS. |
Private Members | ||
private |
Private property used by updateborderneari to track borders. |
Method Summary
Public Methods | ||
public |
add(t: Constraint) Add a constraint to the CPM, ensuring that its SoftConstraint#deltaH or HardConstraint#fulfilled methods are called appropriately during a copy attempt. |
|
public |
* cellBorderPixelIndices(): iPixel Iterator returning non-background border pixels on the grid. |
|
public |
* cellBorderPixels(): Pixel Iterator returning non-background border pixels on the grid. |
|
public | ||
public |
* cellPixels(): Pixel Iterator returning non-background pixels on the grid. |
|
public |
deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number returns total change in hamiltonian for all registered soft constraints together. |
|
public |
Determine whether copy attempt will succeed depending on deltaH (stochastic). |
|
public |
getAllConstraints(): * |
|
public |
getConstraint(constraintname: string, num: number): * Get a Constraint object linked to this CPM by the name of its class. |
|
public |
Get volume of the cell with CellId t |
|
public |
makeNewCellID(kind: CellKind): CellId |
|
public |
Simulate one Monte Carlo Step. |
|
public |
pixt(p: ArrayCoordinate): CellId Get CellId of the pixel at coordinates p. |
|
public |
reset() Completely reset; remove all cells and set time back to zero. |
|
public |
setCellKind(t: CellId, k: CellKind) |
|
public |
setpixi(i: IndexCoordinate, t: CellId) Change the pixel at position i into CellId t. |
|
public |
timeStep() A time step in the CPM is a Monte Carlo step. |
|
public |
updateborderneari(i: IndexCoordinate, t_old: CellId, t_new: CellId) Update border elements (borderpixels) after a successful copy attempt. |
Inherited Summary
From class GridBasedModel | ||
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 |
|
public |
Iterator for all the CellIds that are currently on the grid. |
|
public | ||
public |
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 |
pixt(p: ArrayCoordinate): CellId Get CellId of the pixel at coordinates p. |
|
public |
Get a random integer number between incl_min and incl_max, uniformly sampled. |
|
public |
Get a random number from the seeded number generator. |
|
public |
setpix(p: ArrayCoordinate, t: CellId) Change the pixel at position p into CellId t. |
|
public |
setpixi(i: IndexCoordinate, t: CellId) Change the pixel at position i into CellId t. |
|
public abstract |
timeStep() Update the grid in one timestep. |
Public Constructors
public constructor(field_size: GridSize, conf: object) source
The constructor of class CA.
Override:
GridBasedModel#constructorParams:
Name | Type | Attribute | Description |
field_size | GridSize | the size of the grid of the model. |
|
conf | object | configuration options; see below. In addition, the conf object can have parameters to constraints added to the CPM. See the different Constraint subclasses for options. For some constraints, adding its parameter to the CPM conf object automatically adds the constraint; see AutoAdderConfig to see for which constraints this is supported. |
|
conf.torus | boolean[] |
|
should the grid have linked borders? |
conf.T | number |
|
the temperature of this CPM. At higher temperatures, unfavourable copy attempts are more likely to be accepted. |
conf.seed | number |
|
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[]}
Override:
GridBasedModel#cellvolumepublic hard_constraints: Array source
Array of objects of (@link HardConstraint) subclasses attached to the CPM. These are used to determine which copy attempts are allowed in a timeStep.
public hard_constraints_indices: object source
Object showing which constraints are where in soft_constraints. Used by the getConstraint method to find an attached constraint by name.
public isCPM: boolean source
To check from outside if an object is a CPM; doing this with instanceof doesn't work in some cases. Any other object will not have this variable and return 'undefined', which in an if-statement equates to a 'false'. @type{boolean}
public get perimeterNeighbours: * source
public post_mcs_listeners: function[] source
Array of functions that need to be executed after every timeStep event. These functions are often implemented in subclasses of Constraint that need to track some specific property on the grid.
public post_setpix_listeners: function[] source
Array of functions that need to be executed after every setpixi event. These functions are often implemented in subclasses of Constraint that need to track some specific property on the grid.
public soft_constraints: Array source
Array of objects of (@link SoftConstraint) subclasses attached to the CPM. These are used to determine deltaH.
public soft_constraints_indices: object source
Object showing which constraints are where in soft_constraints. Used by the getConstraint method to find an attached constraint by name.
public stat_values: {} 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!
Override:
GridBasedModel#stat_valuespublic t2k: CellObject source
Store the {@CellKind} of each cell on the grid.
Example:
this.t2k[1] // cellkind of cell with cellId 1
Private Members
private _neighbours: Uint16Array source
Private property used by updateborderneari to track borders.
Public Methods
public add(t: Constraint) source
Add a constraint to the CPM, ensuring that its SoftConstraint#deltaH or HardConstraint#fulfilled methods are called appropriately during a copy attempt. Any postSetpixListeners and postMCSListeners are also executed at the appropriate times.
Params:
Name | Type | Attribute | Description |
t | Constraint | the constraint object to add. |
public * cellBorderPixelIndices(): iPixel source
Iterator returning non-background border pixels on the grid. See cellBorderPixels for a version returning pixels by their ArrayCoordinate instead of IndexCoordinate.
Return:
iPixel | for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value. |
public * cellBorderPixels(): Pixel source
Iterator returning non-background border pixels on the grid. See cellBorderPixelIndices for a version returning pixels by their IndexCoordinate instead of ArrayCoordinate.
Return:
Pixel | for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value. |
public cellKind(t: CellId): CellKind source
Get the CellKind of the cell with CellId t. Overwrites GridBasedModel#cellKind because in a CPM, the two are not the same.
Override:
GridBasedModel#cellKindParams:
Name | Type | Attribute | Description |
t | CellId | id of the cell to get kind of. |
public * cellPixels(): Pixel source
Iterator returning non-background pixels on the grid.
Return:
Pixel | for each pixel, return an array [p,v] where p are the pixel's array coordinates on the grid, and v its value. |
public deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number source
returns total change in hamiltonian for all registered soft constraints together.
Params:
Name | Type | Attribute | Description |
sourcei | IndexCoordinate | coordinate of the source pixel that tries to copy. |
|
targeti | IndexCoordinate | coordinate of the target pixel the source is trying to copy into. |
|
src_type | CellId | cellid of the source pixel. |
|
tgt_type | CellId | cellid of the target pixel. |
public docopy(deltaH: number): boolean source
Determine whether copy attempt will succeed depending on deltaH (stochastic).
Params:
Name | Type | Attribute | Description |
deltaH | number | energy change associated with the potential copy. |
public getConstraint(constraintname: string, num: number): * source
Get a Constraint object linked to this CPM by the name of its class. By default, the first constraint found of this class is returned. It is possible that there are multiple constraints of the same type on the CPM; in that case, supply its number (by order in which the constraints of this type were added) to get a specific one.
This function can be useful if you need to access information in the constraint object, such as the cell directions in a {@PersistenceConstraint}, from outside. You can use this for stuff like drawing.
Return:
* |
public getVolume(t: CellId): number source
Get volume of the cell with CellId t
Params:
Name | Type | Attribute | Description |
t | CellId | id of the cell to get volume of. |
public makeNewCellID(kind: CellKind): CellId source
Initiate a new CellId for a cell of CellKind "kind", and create elements for this cell in the relevant arrays (cellvolume, t2k).
Params:
Name | Type | Attribute | Description |
kind | CellKind | cellkind of the cell that has to be made. |
public monteCarloStep() source
Simulate one Monte Carlo Step. We now just use timeStep for consistency with other GridBasedModels, but we have kept this method for compatibility with earlier version. Internally, it just calls timeStep.
public pixt(p: ArrayCoordinate): CellId source
Get CellId of the pixel at coordinates p.
Override:
GridBasedModel#pixtParams:
Name | Type | Attribute | Description |
p | ArrayCoordinate | pixel to get cellid of. |
public reset() source
Completely reset; remove all cells and set time back to zero. Only the constraints remain.
public setpixi(i: IndexCoordinate, t: CellId) source
Change the pixel at position i into CellId t. This method overrides GridBasedModel#setpixi because we want to add postSetpixListeners for all the constraints, to keep track of relevant information.
See also setpix for a method working with ArrayCoordinates.
Override:
GridBasedModel#setpixiParams:
Name | Type | Attribute | Description |
i | IndexCoordinate | coordinate of pixel to change. |
|
t | CellId | cellid to change this pixel into. |
public timeStep() source
A time step in the CPM is a Monte Carlo step. This performs a number of copy attempts depending on grid size:
1) Randomly sample one of the border pixels for the copy attempt. 2) Compute the change in Hamiltonian for the suggested copy attempt. 3) With a probability depending on this change, decline or accept the copy attempt and update the grid accordingly.
Override:
GridBasedModel#timeStepTODO:
- TODO it is quite confusing that the "borderpixels" array also contains border pixels of the background.
public updateborderneari(i: IndexCoordinate, t_old: CellId, t_new: CellId) source
Update border elements (borderpixels) after a successful copy attempt.
Params:
Name | Type | Attribute | Description |
i | IndexCoordinate | coordinate of pixel that has changed. |
|
t_old | CellId | id of the cell the pixel belonged to before the copy. |
|
t_new | CellId | id of the cell the pixel has changed into. |
Listen:
because borders change when a copy succeeds. |