Boundaries
The decision boundary module calculates decision boundaries for a trained classifier on a 2-dimensional grid of points. It works by taking a classifier, predicting the output label for many points on a 2-D grid, and using the Marching Squares algorithm to calculate the decision boundaries.
Example:
var Boundaries = new Boundaries();
var classIndexBoundaries = boundaries.calculateClassifierDecisionBoundaries(
classifier, // The classifier you've trained
51, // Number of points on the x- and y-axis (so 51 x 51 = 2,601 points in total)
);
// Depending on the classifier used, the output will look something like this:
{
"0":[ // Decision boundaries for class 0
[ // First (and only, as binary classification) decision boundary or class 0
[-0.22, -0.96], // Point 1 of decision boundary
[-0.22, -1.00], // Point 2 of decision boundary
// <...23 more elements...>
[-0.24, -0.92],
[-0.26, -0.96]
]
],
"1":[ // Decision boundaries for class 1
[ // First (and only, as binary classification) decision boundary or class 1
[-0.22, -1.00], // Point 1 of decision boundary
[-0.22, -0.96], // Point 2 of decision boundary
// <...82 more elements...>
[-0.20, -1.00],
[-0.22, -1.00]
]
]
}
Constructor Summary
Public Constructor | ||
public |
Constructor. |
Member Summary
Public Members | ||
public |
Feature list of the grid points. |
|
public |
predictions: Array<mixed> List of classifier predictions for each grid point. |
|
public |
predictionsGrid: Array<Array<mixed>> Grid of classifier predictions for each grid point. |
Method Summary
Public Methods | ||
public |
calculateClassifierDecisionBoundaries(classifier: jsmlt.Supervised.Classifier, resolution: Array<number> | number, gridCoordinates: Array<number>): Object<string, Array<Array<Array<number>>>> Determine decision boundaries for a specific classifier. |
|
public |
generateFeaturesFromLinSpaceGrid(pointsX: number, pointsY: number, boundsX: Array<number>, boundsY: Array<number>): Array.Array<number> Generate a list of features from a grid of points with linear spacing |
|
public |
getFeatures(): Array<Array<number>> Obtain the features list corresponding with the grid coordinates of the last decision boundaries calculation |
|
public |
Determine the decision boundaries for a grid of class predictions |
|
public |
Determine the decision boundaries for a single grid level (class label) |
|
public |
Obtain the predictions list for the last decision boundaries calculation |
|
public |
Obtain the grid of predictions for the last decision bundaries calculation |
Public Constructors
Public Members
public features: Array<Array<number>> source
Feature list of the grid points. n-by-2 array, where each row consists of the x- and y-coordinates of a point on the grid.
Public Methods
public calculateClassifierDecisionBoundaries(classifier: jsmlt.Supervised.Classifier, resolution: Array<number> | number, gridCoordinates: Array<number>): Object<string, Array<Array<Array<number>>>> source
Determine decision boundaries for a specific classifier.
Params:
Name | Type | Attribute | Description |
classifier | jsmlt.Supervised.Classifier | Classifier for which to generate the decision boundaries |
|
resolution | Array<number> | number | Number of points on the x-axis and on the y-axis. Use integer for the same resolution on the x- and y-axis, and a 2-dimensional array to specify resolutions per axis |
|
gridCoordinates | Array<number> |
|
4-dimensional array containing, in order, the x1, y1, x2, and y2-coordinates of the grid |
Return:
Object<string, Array<Array<Array<number>>>> | The returned object contains the boundaries per level (class label). Each boundary then consists of some coordinates (forming a path), and each coordinate is a 2-dimensional array where the first entry is the x-coordinate and the second entry is the y-coordinate |
public generateFeaturesFromLinSpaceGrid(pointsX: number, pointsY: number, boundsX: Array<number>, boundsY: Array<number>): Array.Array<number> source
Generate a list of features from a grid of points with linear spacing
Params:
Name | Type | Attribute | Description |
pointsX | number | Number of points on the x-axis |
|
pointsY | number | Number of points on the y-axis |
|
boundsX | Array<number> | 2-dimensional array of left and right bound on the points on the x-axis |
|
boundsY | Array<number> | 2-dimensional array of left and right bound on the points on the y-axis |
Return:
Array.Array<number> | (pointsX * pointsY)-by-2 array, containing the coordinates of all grid points |
public getFeatures(): Array<Array<number>> source
Obtain the features list corresponding with the grid coordinates of the last decision boundaries calculation
public getGridDecisionBoundaries(grid: Array<Array<mixed>>): Object<string, Array<Array<Array<number>>>> source
Determine the decision boundaries for a grid of class predictions
Return:
Object<string, Array<Array<Array<number>>>> | The returned object contains the boundaries per level (class label). Each boundary then consists of some coordinates (forming a path), and each coordinate is a 2-dimensional array where the first entry is the x-coordinate and the second entry is the y-coordinate |
public getGridLevelBoundaries(grid: Array<Array<number>>, level: string): Array<Array<Array<number>>> source
Determine the decision boundaries for a single grid level (class label)