import PerimeterConstraint from 'Artistoo/src/hamiltonian/PerimeterConstraint.js'
PerimeterConstraint
Extends:
Implements the perimeter constraint of Potts models. A cell's "perimeter" is the number over all its borderpixels of the number of neighbors that do not belong to the cell itself.
This constraint is typically used together with Adhesion and {@VolumeConstraint}.
See PerimeterConstraint#constructor for the required parameters.
Example:
// Build a CPM and add the constraint
let CPM = require( "path/to/build" )
let C = new CPM.CPM( [200,200], {
T : 20,
J : [[0,20],[20,10]],
V : [0,500],
LAMBDA_V : [0,5]
})
C.add( new CPM.PerimeterConstraint( {
P : [0,260],
LAMBDA_P : [0,2]
} ) )
// Or add automatically by entering the parameters in the CPM
let C2 = new CPM.CPM( [200,200], {
T : 20,
J : [[0,20],[20,10]],
V : [0,500],
LAMBDA_V : [0,5],
P : [0,260],
LAMBDA_P : [0,2]
})
Constructor Summary
Public Constructor | ||
public |
constructor(conf: object) The constructor of the PerimeterConstraint requires a conf object with parameters. |
Member Summary
Public Members | ||
public set |
Set the CPM attached to this constraint. |
|
public |
The perimeter size of each pixel is tracked. |
Method Summary
Public Methods | ||
public |
This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format. |
|
public |
deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number Method to compute the Hamiltonian for this constraint. |
|
public |
This method initializes the this.cellperimeters object when the constraint is added to a non-empty CPM. |
|
public |
postSetpixListener(i: IndexCoordinate, t_old: CellId, t_new: CellId) The postSetpixListener of the PerimeterConstraint ensures that cell perimeters are updated after each copy in the CPM. |
Inherited Summary
From class Constraint | ||
public get abstract |
This method is actually implemented in the subclass. |
|
public set |
This function attaches the relevant CPM to this constraint, so that information about this cpm can be requested from the constraint. |
|
public get |
parameters: object: * Get the parameters of this constraint from the conf object. |
|
public |
CPM on which this constraint acts. |
|
public |
Configuration object for this constraint. |
|
public abstract |
cellParameter(param: string, cid: CellId): any Get a cellid or cellkind-specific parameter for a constraint. |
|
public abstract |
The optional confChecker method should verify that all the required conf parameters are actually present in the conf object and have the right format. |
|
public |
paramOfCell(param: string, cid: CellId): any Get a cellId specific parameter, only used if CPMEvol is used: looks whether the requested parameter is overwritten in an @object Cell and otherwise returns @function paramOfKind |
|
public |
paramOfKind(param: string, cid: CellId): any Returns a cellKind specfic variable: Assumes that the parameter is indexable by cellkind. |
From class SoftConstraint | ||
public get |
Let the CPM know that this is a soft constraint, so return 'soft'. |
|
public abstract |
deltaH(src_i: IndexCoordinate, tgt_i: IndexCoordinate, src_type: CellId, tgt_type: CellId): number Soft constraints must have a deltaH method to compute the Hamiltonian. |
Public Constructors
public constructor(conf: object) source
The constructor of the PerimeterConstraint requires a conf object with parameters.
Override:
Constraint#constructorParams:
Name | Type | Attribute | Description |
conf | object | parameter object for this constraint |
|
conf.LAMBDA_P | PerKindNonNegative | strength of the perimeter constraint per cellkind. |
|
conf.P | PerKindNonNegative | Target perimeter per cellkind. |
Public Members
Public Methods
public confChecker() source
This method checks that all required parameters are present in the object supplied to the constructor, and that they are of the right format. It throws an error when this is not the case.
Override:
Constraint#confCheckerpublic deltaH(sourcei: IndexCoordinate, targeti: IndexCoordinate, src_type: CellId, tgt_type: CellId): number source
Method to compute the Hamiltonian for this constraint.
Override:
SoftConstraint#deltaHParams:
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 initializePerimeters() source
This method initializes the this.cellperimeters object when the constraint is added to a non-empty CPM.
public postSetpixListener(i: IndexCoordinate, t_old: CellId, t_new: CellId) source
The postSetpixListener of the PerimeterConstraint ensures that cell perimeters are updated after each copy in the CPM.
Params:
Name | Type | Attribute | Description |
i | IndexCoordinate | the coordinate of the pixel that is changed. |
|
t_old | CellId | the cellid of this pixel before the copy |
|
t_new | CellId | the cellid of this pixel after the copy. |
Listen:
because when a new pixel is set (which is determined in the CPM), some of the cell perimeters will change. |