Home Reference Source
public class | source

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:

Calculating the decision boundaries for a classifier
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

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

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 constructor() source

Constructor. Initializes boundary object properties.

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 predictions: Array<mixed> source

List of classifier predictions for each grid point. The nth prediction is the prediction for the nth point in the features property. n-dimensional array.

public predictionsGrid: Array<Array<mixed>> source

Grid of classifier predictions for each grid point. m-by-n array, where the array element at index (j, i) contains the prediction for the grid point at x-index i and y-index j. This is simply a 2-dimensional version of the predictions property

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:

NameTypeAttributeDescription
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>
  • optional
  • default: [-1, -1, 1, 1]

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:

NameTypeAttributeDescription
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

Return:

Array<Array<number>>

Features for all data points (2-dimensional)

public getGridDecisionBoundaries(grid: Array<Array<mixed>>): Object<string, Array<Array<Array<number>>>> source

Determine the decision boundaries for a grid of class predictions

Params:

NameTypeAttributeDescription
grid Array<Array<mixed>>

Grid of predictions, an array of row arrays, where each row array contains the predictions for the cells in that row. For an m x n prediction grid, each of the m entries of grid should have n entries

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)

Params:

NameTypeAttributeDescription
grid Array<Array<number>>

See this.getGridDecisionBoundaries@param:grid

level string

Level (class label) to calculate boundaries for

Return:

Array<Array<Array<number>>>

Boundaries for this level (class label). See this.getGridDecisionBoundaries@return

public getPredictions(): Array<number> source

Obtain the predictions list for the last decision boundaries calculation

Return:

Array<number>

List of predicted class labels

public getPredictionsGrid(): Array<Array<number>> source

Obtain the grid of predictions for the last decision bundaries calculation

Return:

Array<Array<number>>

Predicted class labels for each grid point. m-by-n array for m rows, n columns