diff --git a/docs/VECTOR.api.md b/docs/VECTOR.api.md index 01aa6f5..f524497 100644 --- a/docs/VECTOR.api.md +++ b/docs/VECTOR.api.md @@ -11,7 +11,7 @@ export type ApproximationFunction = (input: Vector) => S; export type ApproximationFunctionTemplate = (coefficients: Vector) => ApproximationFunction; // @public -export abstract class ArrayMatrix implements Matrix { +export abstract class ArrayMatrix implements Matrix { // @internal protected constructor(data: MatrixData); add(other: Matrix): Matrix; @@ -43,7 +43,7 @@ export abstract class ArrayMatrix implements Matrix { } // @public -export abstract class ArrayVector implements Vector { +export abstract class ArrayVector implements Vector { // @internal protected constructor(data: VectorData); add(other: Vector): Vector; @@ -107,9 +107,9 @@ export interface CholeskyDecomposition { // @public export interface Classifier { getHyperParameters(): H; - predict(data: Matrix, pThreshold: number): Vector; - predictProbabilities(data: Matrix): Vector; - train(data: Matrix, target: Vector): void; + predict(data: Matrix, pThreshold: number): Vector; + predictProbabilities(data: Matrix): Vector; + train(data: Matrix, target: Vector): void; } // @public @@ -202,11 +202,11 @@ export interface Cost { // (undocumented) cost: number; // (undocumented) - gradient: Vector; + gradient: Vector; } // @public -export type CostFunction = (theta: Vector) => Cost; +export type CostFunction = (theta: Vector) => Cost; // @public export function covariance(first: Vector, second: Vector): S; @@ -218,13 +218,13 @@ export function covariance(A: Matrix): Matrix; export function crossProduct(first: Vector, second: Vector): Vector; // @public -export function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector; +export function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector; // @public export function determinant(matrix: Matrix): S; // @public -export function diag(elements: number[]): Matrix; +export function diag(elements: number[]): Matrix; // Warning: (ae-forgotten-export) The symbol "DimensionReductionType" needs to be exported by the entry point index.d.ts // @@ -254,7 +254,7 @@ export function euclideanNorm(v: Vector): number; export function exp(A: Matrix, order?: number): Matrix; // @public -export function eye(size: number): Matrix; +export function eye(size: number): Matrix; // @public export class FloatMatrix implements Matrix { @@ -382,13 +382,13 @@ export function isSymmetric(matrix: Matrix): boolean; export function isUpperTriangular(matrix: Matrix): boolean; // @public -export type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; +export type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; // @public export function kroneckerProduct(first: Matrix, second: Matrix): Matrix; // @public -export type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector; +export type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector; // @public export interface LeastSquaresApproximation { @@ -397,15 +397,15 @@ export interface LeastSquaresApproximation { } // @public -export function LinearKernel(data: Matrix): Matrix; +export function LinearKernel(data: Matrix): Matrix; // @public export class LinearRegressor implements Regressor { constructor(hyperParameters: Partial); getHyperParameters(): LinearRegressorHyperparams; - getParameters(): Vector | undefined; - predict(data: Matrix): Vector; - train(data: Matrix, target: Vector): void; + getParameters(): Vector | undefined; + predict(data: Matrix): Vector; + train(data: Matrix, target: Vector): void; } // @public @@ -425,10 +425,10 @@ export function linspace(xMin: number, xMax: number, binCount: number): NumberVe export class LogisticRegressionClassifier implements Classifier { constructor(hyperParameters: Partial); getHyperParameters(): LogisticRegressionHyperparams; - getParameters(): Vector | undefined; - predict(data: Matrix): Vector; - predictProbabilities(data: Matrix): Vector; - train(data: Matrix, target: Vector): void; + getParameters(): Vector | undefined; + predict(data: Matrix): Vector; + predictProbabilities(data: Matrix): Vector; + train(data: Matrix, target: Vector): void; } // @public @@ -447,10 +447,10 @@ export interface LUDecomposition { } // @public -export function mat(data: number[][]): Matrix; +export function mat(data: number[][]): Matrix; // @public -export interface Matrix extends LinearTransformation, Vector> { +export interface Matrix extends LinearTransformation, Vector> { add(other: Matrix): Matrix; adjoint(): Matrix; apply(vector: Vector): Vector; @@ -597,10 +597,10 @@ export class NumberVector extends ArrayVector { } // @public -export function ones(entries: number): Vector; +export function ones(entries: number): Vector; // @public -export function ones(shape: MatrixShape): Matrix; +export function ones(shape: MatrixShape): Matrix; // @public export function pca(A: Matrix, useCorrelation?: boolean): PrincipalComponentAnalysis; @@ -644,7 +644,7 @@ export function RadialBasisFunction(distanceMetric: SimilarityMetric): Kernel; export function rank(matrix: Matrix): number; // @public -export function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix; +export function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix; // @public export function reducedRowEchelonForm(matrix: Matrix): Matrix; @@ -652,8 +652,8 @@ export function reducedRowEchelonForm(matrix: Matrix): Matrix; // @public export interface Regressor { getHyperParameters(): H; - predict(data: Matrix): Vector; - train(data: Matrix, target: Vector): void; + predict(data: Matrix): Vector; + train(data: Matrix, target: Vector): void; } // @public @@ -704,7 +704,7 @@ export abstract class ScalarOperations { } // @public -export type SimilarityMetric = (v1: Vector, v2: Vector) => number; +export type SimilarityMetric = (v1: Vector, v2: Vector) => number; // @public export interface SingularValueDecomposition { @@ -725,7 +725,7 @@ export function solveByGaussianElimination(A: Matrix, b: Vector): Linea export function solveOverdeterminedSystem(A: Matrix, b: Vector): Vector; // @public -export abstract class SparseMatrix implements Matrix { +export abstract class SparseMatrix implements Matrix { // @internal protected constructor(data: MatrixData); add(other: Matrix): Matrix; @@ -791,7 +791,7 @@ export class SparseNumberVector extends SparseVector { } // @public -export abstract class SparseVector implements Vector { +export abstract class SparseVector implements Vector { // @internal protected constructor(data: VectorData); add(other: Vector): Vector; @@ -838,10 +838,10 @@ export function sumNorm(v: Vector): number; export class SupportVectorMachineClassifier implements Classifier { constructor(hyperParameters: Partial); getHyperParameters(): SupportVectorMachineHyperparams; - getParameters(): Vector | undefined; - predict(data: Matrix): Vector; - predictProbabilities(_data: Matrix): Vector; - train(data: Matrix, target: Vector): void; + getParameters(): Vector | undefined; + predict(data: Matrix): Vector; + predictProbabilities(_data: Matrix): Vector; + train(data: Matrix, target: Vector): void; } // @public @@ -863,10 +863,10 @@ export function variance(x: Vector): S; export function variance(A: Matrix): Vector; // @public -export function vec(data: number[]): Vector; +export function vec(data: number[]): Vector; // @public -export interface Vector { +export interface Vector { add(other: Vector): Vector; builder(): VectorBuilder>; combine(other: Vector, combineEntries: (a: S, b: S) => S): Vector; @@ -929,10 +929,10 @@ export type VectorData = readonly S[]; export type VectorIndexFunction = (index: number) => S; // @public -export function zeros(entries: number): Vector; +export function zeros(entries: number): Vector; // @public -export function zeros(shape: MatrixShape): Matrix; +export function zeros(shape: MatrixShape): Matrix; // (No @packageDocumentation comment for this package) diff --git a/docs/api/vector.arraymatrix.md b/docs/api/vector.arraymatrix.md index 689e5f4..f7aa3a0 100644 --- a/docs/api/vector.arraymatrix.md +++ b/docs/api/vector.arraymatrix.md @@ -9,7 +9,7 @@ Implements [Matrix](./vector.matrix.md) with a 2-dimensional array of values. Signature: ```typescript -export declare abstract class ArrayMatrix implements Matrix +export declare abstract class ArrayMatrix implements Matrix ``` ## Remarks diff --git a/docs/api/vector.arrayvector.md b/docs/api/vector.arrayvector.md index f2ada3c..76defc5 100644 --- a/docs/api/vector.arrayvector.md +++ b/docs/api/vector.arrayvector.md @@ -9,7 +9,7 @@ Implements [Vector](./vector.vector.md) with an array of values. Signature: ```typescript -export declare abstract class ArrayVector implements Vector +export declare abstract class ArrayVector implements Vector ``` ## Remarks diff --git a/docs/api/vector.classifier.predict.md b/docs/api/vector.classifier.predict.md index 24f2ab4..5df1a2b 100644 --- a/docs/api/vector.classifier.predict.md +++ b/docs/api/vector.classifier.predict.md @@ -9,19 +9,19 @@ Uses the learned parameters to make predictions based on a set of input data. Signature: ```typescript -predict(data: Matrix, pThreshold: number): Vector; +predict(data: Matrix, pThreshold: number): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | | pThreshold | number | The probability threshold above which an event will be predicted | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.classifier.predictprobabilities.md b/docs/api/vector.classifier.predictprobabilities.md index 6875e20..579789d 100644 --- a/docs/api/vector.classifier.predictprobabilities.md +++ b/docs/api/vector.classifier.predictprobabilities.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions for the probability of an event Signature: ```typescript -predictProbabilities(data: Matrix): Vector; +predictProbabilities(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.classifier.train.md b/docs/api/vector.classifier.train.md index 913be6b..7e17c2c 100644 --- a/docs/api/vector.classifier.train.md +++ b/docs/api/vector.classifier.train.md @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model. Signature: ```typescript -train(data: Matrix, target: Vector): void; +train(data: Matrix, target: Vector): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | -| target | Vector<number> | A [Vector](./vector.vector.md) whose entries are the target values in the training set | +| data | Matrix | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | +| target | Vector | A [Vector](./vector.vector.md) whose entries are the target values in the training set | Returns: diff --git a/docs/api/vector.cost.gradient.md b/docs/api/vector.cost.gradient.md index 8b5b054..6e006b2 100644 --- a/docs/api/vector.cost.gradient.md +++ b/docs/api/vector.cost.gradient.md @@ -7,5 +7,5 @@ Signature: ```typescript -gradient: Vector; +gradient: Vector; ``` diff --git a/docs/api/vector.cost.md b/docs/api/vector.cost.md index 4fd54cf..12138ba 100644 --- a/docs/api/vector.cost.md +++ b/docs/api/vector.cost.md @@ -17,5 +17,5 @@ export interface Cost | Property | Type | Description | | --- | --- | --- | | [cost](./vector.cost.cost.md) | number | | -| [gradient](./vector.cost.gradient.md) | Vector<number> | | +| [gradient](./vector.cost.gradient.md) | Vector | | diff --git a/docs/api/vector.costfunction.md b/docs/api/vector.costfunction.md index 957c4dd..07592ff 100644 --- a/docs/api/vector.costfunction.md +++ b/docs/api/vector.costfunction.md @@ -9,5 +9,5 @@ A function that evaluates the cost of a set of parameters `theta` Signature: ```typescript -export declare type CostFunction = (theta: Vector) => Cost; +export declare type CostFunction = (theta: Vector) => Cost; ``` diff --git a/docs/api/vector.derivative.md b/docs/api/vector.derivative.md index ecce052..354e77b 100644 --- a/docs/api/vector.derivative.md +++ b/docs/api/vector.derivative.md @@ -9,7 +9,7 @@ Uses finite differences to build a vector containing approximate values of the d Signature: ```typescript -export declare function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector; +export declare function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector; ``` ## Parameters @@ -23,7 +23,7 @@ export declare function derivative(f: (x: number) => number, xMin: number, xMax: Returns: -`Vector` +`Vector` A linearly spaced vector whose values represent the values of the derivative diff --git a/docs/api/vector.diag.md b/docs/api/vector.diag.md index 6279a73..8837655 100644 --- a/docs/api/vector.diag.md +++ b/docs/api/vector.diag.md @@ -9,7 +9,7 @@ Creates a new matrix with the specified entries on the diagonal. See [MatrixBuil Signature: ```typescript -export declare function diag(elements: number[]): Matrix; +export declare function diag(elements: number[]): Matrix; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function diag(elements: number[]): Matrix; Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.eye.md b/docs/api/vector.eye.md index 8d360a3..e380b55 100644 --- a/docs/api/vector.eye.md +++ b/docs/api/vector.eye.md @@ -9,7 +9,7 @@ Creates a new identity matrix of size `size`. See [MatrixBuilder.identit Signature: ```typescript -export declare function eye(size: number): Matrix; +export declare function eye(size: number): Matrix; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function eye(size: number): Matrix; Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.kernel.md b/docs/api/vector.kernel.md index 62241bd..ac71ae6 100644 --- a/docs/api/vector.kernel.md +++ b/docs/api/vector.kernel.md @@ -11,5 +11,5 @@ Generally intended for use with a [SupportVectorMachineClassifier](./vector.supp Signature: ```typescript -export declare type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; +export declare type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; ``` diff --git a/docs/api/vector.learningalgorithm.md b/docs/api/vector.learningalgorithm.md index d914ebe..f1bad91 100644 --- a/docs/api/vector.learningalgorithm.md +++ b/docs/api/vector.learningalgorithm.md @@ -9,5 +9,5 @@ An function which, given an initial value of `theta` and a CostFunction, will co Signature: ```typescript -export declare type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector; +export declare type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector; ``` diff --git a/docs/api/vector.linearkernel.md b/docs/api/vector.linearkernel.md index abf8ed8..4a2cf02 100644 --- a/docs/api/vector.linearkernel.md +++ b/docs/api/vector.linearkernel.md @@ -9,16 +9,16 @@ A linear kernel for use in a [SupportVectorMachineClassifier](./vector.supportve Signature: ```typescript -export declare function LinearKernel(data: Matrix): Matrix; +export declare function LinearKernel(data: Matrix): Matrix; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | The variance of the gaussian distribution used in the kernel | +| data | Matrix | The variance of the gaussian distribution used in the kernel | Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.linearregressor.getparameters.md b/docs/api/vector.linearregressor.getparameters.md index 8dd5f20..e886263 100644 --- a/docs/api/vector.linearregressor.getparameters.md +++ b/docs/api/vector.linearregressor.getparameters.md @@ -9,9 +9,9 @@ Get the coefficients of the trained linear regression model, or `undefined` if t Signature: ```typescript -getParameters(): Vector | undefined; +getParameters(): Vector | undefined; ``` Returns: -`Vector | undefined` +`Vector | undefined` diff --git a/docs/api/vector.linearregressor.predict.md b/docs/api/vector.linearregressor.predict.md index af853a4..4882fb9 100644 --- a/docs/api/vector.linearregressor.predict.md +++ b/docs/api/vector.linearregressor.predict.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions based on a set of input data. Signature: ```typescript -predict(data: Matrix): Vector; +predict(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.linearregressor.train.md b/docs/api/vector.linearregressor.train.md index 0db7717..7ef8b85 100644 --- a/docs/api/vector.linearregressor.train.md +++ b/docs/api/vector.linearregressor.train.md @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model. Signature: ```typescript -train(data: Matrix, target: Vector): void; +train(data: Matrix, target: Vector): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | -| target | Vector<number> | A [Vector](./vector.vector.md) whose entries are the target values in the training set | +| data | Matrix | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | +| target | Vector | A [Vector](./vector.vector.md) whose entries are the target values in the training set | Returns: diff --git a/docs/api/vector.logisticregressionclassifier.getparameters.md b/docs/api/vector.logisticregressionclassifier.getparameters.md index e073c82..90bf2cf 100644 --- a/docs/api/vector.logisticregressionclassifier.getparameters.md +++ b/docs/api/vector.logisticregressionclassifier.getparameters.md @@ -9,9 +9,9 @@ Get the coefficients of the trained linear regression model, or `undefined` if t Signature: ```typescript -getParameters(): Vector | undefined; +getParameters(): Vector | undefined; ``` Returns: -`Vector | undefined` +`Vector | undefined` diff --git a/docs/api/vector.logisticregressionclassifier.predict.md b/docs/api/vector.logisticregressionclassifier.predict.md index 306ceaf..2ef3237 100644 --- a/docs/api/vector.logisticregressionclassifier.predict.md +++ b/docs/api/vector.logisticregressionclassifier.predict.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions based on a set of input data. Signature: ```typescript -predict(data: Matrix): Vector; +predict(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.logisticregressionclassifier.predictprobabilities.md b/docs/api/vector.logisticregressionclassifier.predictprobabilities.md index 37e50e0..be883a5 100644 --- a/docs/api/vector.logisticregressionclassifier.predictprobabilities.md +++ b/docs/api/vector.logisticregressionclassifier.predictprobabilities.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions for the probability of an event Signature: ```typescript -predictProbabilities(data: Matrix): Vector; +predictProbabilities(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.logisticregressionclassifier.train.md b/docs/api/vector.logisticregressionclassifier.train.md index 31174ea..2fbaf1e 100644 --- a/docs/api/vector.logisticregressionclassifier.train.md +++ b/docs/api/vector.logisticregressionclassifier.train.md @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model. Signature: ```typescript -train(data: Matrix, target: Vector): void; +train(data: Matrix, target: Vector): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | -| target | Vector<number> | A [Vector](./vector.vector.md) whose entries are the target values in the training set | +| data | Matrix | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | +| target | Vector | A [Vector](./vector.vector.md) whose entries are the target values in the training set | Returns: diff --git a/docs/api/vector.mat.md b/docs/api/vector.mat.md index 46623bd..7c47c5f 100644 --- a/docs/api/vector.mat.md +++ b/docs/api/vector.mat.md @@ -9,7 +9,7 @@ Creates a new [Matrix](./vector.matrix.md) of numbers. See [MatrixBuilder.fromAr Signature: ```typescript -export declare function mat(data: number[][]): Matrix; +export declare function mat(data: number[][]): Matrix; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function mat(data: number[][]): Matrix; Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.matrix.md b/docs/api/vector.matrix.md index e01e048..afa35a8 100644 --- a/docs/api/vector.matrix.md +++ b/docs/api/vector.matrix.md @@ -9,7 +9,7 @@ A generalized Matrix - one of the core data types Signature: ```typescript -export interface Matrix extends LinearTransformation, Vector> +export interface Matrix extends LinearTransformation, Vector> ``` ## Methods diff --git a/docs/api/vector.ones.md b/docs/api/vector.ones.md index fa16767..8d53e61 100644 --- a/docs/api/vector.ones.md +++ b/docs/api/vector.ones.md @@ -9,7 +9,7 @@ Creates a new vector of all 1s. See [VectorBuilder.ones()](./vector.vectorbuilde Signature: ```typescript -export declare function ones(entries: number): Vector; +export declare function ones(entries: number): Vector; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function ones(entries: number): Vector; Returns: -`Vector` +`Vector` diff --git a/docs/api/vector.ones_1.md b/docs/api/vector.ones_1.md index a728a1c..be0c787 100644 --- a/docs/api/vector.ones_1.md +++ b/docs/api/vector.ones_1.md @@ -9,7 +9,7 @@ Creates a new matrix of all 1s. See [MatrixBuilder.ones()](./vector.matrixbuilde Signature: ```typescript -export declare function ones(shape: MatrixShape): Matrix; +export declare function ones(shape: MatrixShape): Matrix; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function ones(shape: MatrixShape): Matrix; Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.reducedimensions.md b/docs/api/vector.reducedimensions.md index 1cec603..9b0ee9e 100644 --- a/docs/api/vector.reducedimensions.md +++ b/docs/api/vector.reducedimensions.md @@ -9,17 +9,17 @@ Reduce the number of dimensions of a data matrix `A` while losing as little info Signature: ```typescript -export declare function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix; +export declare function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| A | Matrix<number> | The data matrix | +| A | Matrix | The data matrix | | options | DimensionReductionOptions | Specify how the dimension reduction should be done. useCorrelation: boolean - use the correlation rather than covariance matrix when conducting the PCA; keep: number - the desired number of dimensions; remove: number - the number of dimensions to remove; proportionOfVariance: number - the desired proportion of the total variance in the data that should be explained by the remaining columns | Returns: -`Matrix` +`Matrix` diff --git a/docs/api/vector.regressor.predict.md b/docs/api/vector.regressor.predict.md index d1bfda9..404c168 100644 --- a/docs/api/vector.regressor.predict.md +++ b/docs/api/vector.regressor.predict.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions based on a set of input data. Signature: ```typescript -predict(data: Matrix): Vector; +predict(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.regressor.train.md b/docs/api/vector.regressor.train.md index 0a4d33f..71aba58 100644 --- a/docs/api/vector.regressor.train.md +++ b/docs/api/vector.regressor.train.md @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model. Signature: ```typescript -train(data: Matrix, target: Vector): void; +train(data: Matrix, target: Vector): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | -| target | Vector<number> | A [Vector](./vector.vector.md) whose entries are the target values in the training set | +| data | Matrix | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | +| target | Vector | A [Vector](./vector.vector.md) whose entries are the target values in the training set | Returns: diff --git a/docs/api/vector.similaritymetric.md b/docs/api/vector.similaritymetric.md index 4f2e9ea..3cb3855 100644 --- a/docs/api/vector.similaritymetric.md +++ b/docs/api/vector.similaritymetric.md @@ -9,5 +9,5 @@ A function which expresses the similarity of two [Vector](./vector.vector.md)Signature: ```typescript -export declare type SimilarityMetric = (v1: Vector, v2: Vector) => number; +export declare type SimilarityMetric = (v1: Vector, v2: Vector) => number; ``` diff --git a/docs/api/vector.sparsematrix.md b/docs/api/vector.sparsematrix.md index 374ec30..15e1d42 100644 --- a/docs/api/vector.sparsematrix.md +++ b/docs/api/vector.sparsematrix.md @@ -9,7 +9,7 @@ Implements [Matrix](./vector.matrix.md) with a map of indices to nonzero values. Signature: ```typescript -export declare abstract class SparseMatrix implements Matrix +export declare abstract class SparseMatrix implements Matrix ``` ## Remarks diff --git a/docs/api/vector.sparsevector.md b/docs/api/vector.sparsevector.md index 17fc801..d8c253c 100644 --- a/docs/api/vector.sparsevector.md +++ b/docs/api/vector.sparsevector.md @@ -9,7 +9,7 @@ Implements [Vector](./vector.vector.md) as a map of indices to nonzero values. Signature: ```typescript -export declare abstract class SparseVector implements Vector +export declare abstract class SparseVector implements Vector ``` ## Remarks diff --git a/docs/api/vector.supportvectormachineclassifier.getparameters.md b/docs/api/vector.supportvectormachineclassifier.getparameters.md index 3944860..2863e12 100644 --- a/docs/api/vector.supportvectormachineclassifier.getparameters.md +++ b/docs/api/vector.supportvectormachineclassifier.getparameters.md @@ -9,9 +9,9 @@ Get the weights of the trained SVM, or `undefined` if the model has not been tra Signature: ```typescript -getParameters(): Vector | undefined; +getParameters(): Vector | undefined; ``` Returns: -`Vector | undefined` +`Vector | undefined` diff --git a/docs/api/vector.supportvectormachineclassifier.predict.md b/docs/api/vector.supportvectormachineclassifier.predict.md index 73b3756..ee17dc9 100644 --- a/docs/api/vector.supportvectormachineclassifier.predict.md +++ b/docs/api/vector.supportvectormachineclassifier.predict.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions based on a set of input data. Signature: ```typescript -predict(data: Matrix): Vector; +predict(data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Vector](./vector.vector.md) whose rows are the observations in the test set | +| data | Matrix | A [Vector](./vector.vector.md) whose rows are the observations in the test set | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.supportvectormachineclassifier.predictprobabilities.md b/docs/api/vector.supportvectormachineclassifier.predictprobabilities.md index 2d1a102..4d924db 100644 --- a/docs/api/vector.supportvectormachineclassifier.predictprobabilities.md +++ b/docs/api/vector.supportvectormachineclassifier.predictprobabilities.md @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions for the probability of an event Signature: ```typescript -predictProbabilities(_data: Matrix): Vector; +predictProbabilities(_data: Matrix): Vector; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| \_data | Matrix<number> | | +| \_data | Matrix | | Returns: -`Vector` +`Vector` ## Remarks diff --git a/docs/api/vector.supportvectormachineclassifier.train.md b/docs/api/vector.supportvectormachineclassifier.train.md index 626bd95..3dd2a7d 100644 --- a/docs/api/vector.supportvectormachineclassifier.train.md +++ b/docs/api/vector.supportvectormachineclassifier.train.md @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model. Signature: ```typescript -train(data: Matrix, target: Vector): void; +train(data: Matrix, target: Vector): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| data | Matrix<number> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | -| target | Vector<number> | A [Vector](./vector.vector.md) whose entries are the target values in the training set | +| data | Matrix | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set | +| target | Vector | A [Vector](./vector.vector.md) whose entries are the target values in the training set | Returns: diff --git a/docs/api/vector.vec.md b/docs/api/vector.vec.md index 0993ee7..44f3808 100644 --- a/docs/api/vector.vec.md +++ b/docs/api/vector.vec.md @@ -9,7 +9,7 @@ Creates a new [Vector](./vector.vector.md) of numbers. See [VectorBuilder.fromAr Signature: ```typescript -export declare function vec(data: number[]): Vector; +export declare function vec(data: number[]): Vector; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function vec(data: number[]): Vector; Returns: -`Vector` +`Vector` diff --git a/docs/api/vector.vector.md b/docs/api/vector.vector.md index 011b762..b7e9d77 100644 --- a/docs/api/vector.vector.md +++ b/docs/api/vector.vector.md @@ -9,7 +9,7 @@ A generalized Vector - one of the core data types Signature: ```typescript -export interface Vector +export interface Vector ``` ## Methods diff --git a/docs/api/vector.zeros.md b/docs/api/vector.zeros.md index 75b7299..17c7c5a 100644 --- a/docs/api/vector.zeros.md +++ b/docs/api/vector.zeros.md @@ -9,7 +9,7 @@ Creates a new vector of all 0s. See [VectorBuilder.zeros()](./vector.vectorbuild Signature: ```typescript -export declare function zeros(entries: number): Vector; +export declare function zeros(entries: number): Vector; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function zeros(entries: number): Vector; Returns: -`Vector` +`Vector` diff --git a/docs/api/vector.zeros_1.md b/docs/api/vector.zeros_1.md index 548a502..0535b9e 100644 --- a/docs/api/vector.zeros_1.md +++ b/docs/api/vector.zeros_1.md @@ -9,7 +9,7 @@ Creates a new matrix of all 0s. See [MatrixBuilder.zeros()](./vector.matrixbuild Signature: ```typescript -export declare function zeros(shape: MatrixShape): Matrix; +export declare function zeros(shape: MatrixShape): Matrix; ``` ## Parameters @@ -20,5 +20,5 @@ export declare function zeros(shape: MatrixShape): Matrix; Returns: -`Matrix` +`Matrix` diff --git a/src/applications/calculus/FiniteDifferences.ts b/src/applications/calculus/FiniteDifferences.ts index 1b8d4e4..4dbb643 100644 --- a/src/applications/calculus/FiniteDifferences.ts +++ b/src/applications/calculus/FiniteDifferences.ts @@ -146,7 +146,7 @@ export function derivative( xMin: number, xMax: number, binCount: number -): Vector { +): Vector { const x = linspace(xMin, xMax, binCount); const y = x.map(f); const delta = x.getEntry(1) - x.getEntry(0); diff --git a/src/applications/machine-learning/GradientDescent.ts b/src/applications/machine-learning/GradientDescent.ts index e715d95..8f7ef81 100644 --- a/src/applications/machine-learning/GradientDescent.ts +++ b/src/applications/machine-learning/GradientDescent.ts @@ -20,7 +20,7 @@ export type GradientDescentParameters = { export function gradientDescent(parameters: Partial): LearningAlgorithm { const { alpha = 0.1, maxIterations = 10000 } = parameters; - return function(initialTheta: Vector, costFn: CostFunction) { + return function(initialTheta: Vector, costFn: CostFunction) { let theta = initialTheta; let i = 0; const zeros = theta.builder().zeros(theta.getDimension()); diff --git a/src/applications/machine-learning/LearningAlgorithm.ts b/src/applications/machine-learning/LearningAlgorithm.ts index 223121a..90ba9ba 100644 --- a/src/applications/machine-learning/LearningAlgorithm.ts +++ b/src/applications/machine-learning/LearningAlgorithm.ts @@ -6,21 +6,18 @@ import { Vector } from '../../types/vector/Vector'; */ export interface Cost { cost: number; - gradient: Vector; + gradient: Vector; } /** * A function that evaluates the cost of a set of parameters `theta` * @public */ -export type CostFunction = (theta: Vector) => Cost; +export type CostFunction = (theta: Vector) => Cost; /** * An function which, given an initial value of `theta` and a CostFunction, * will compute the optimal value of `theta` * @public */ -export type LearningAlgorithm = ( - initialTheta: Vector, - costFn: CostFunction -) => Vector; +export type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector; diff --git a/src/applications/machine-learning/clustering/kMeansClustering.ts b/src/applications/machine-learning/clustering/kMeansClustering.ts index d7d622f..d0ca511 100644 --- a/src/applications/machine-learning/clustering/kMeansClustering.ts +++ b/src/applications/machine-learning/clustering/kMeansClustering.ts @@ -10,14 +10,11 @@ interface KMeansParameters { } interface ClusteringResult { - centroids: Vector[]; - labels: Vector; + centroids: Vector[]; + labels: Vector; } -export function kMeansClustering( - X: Matrix, - params: Partial -): ClusteringResult { +export function kMeansClustering(X: Matrix, params: Partial): ClusteringResult { const rows = X.getRowVectors(); const [m, n] = X.getShape(); const { k = 5, norm = euclideanNorm, maxIterations = 100 } = params; @@ -40,11 +37,7 @@ export function kMeansClustering( return { centroids, labels }; } -function updateLabels( - rows: Vector[], - centroids: Vector[], - norm: Norm -): Vector { +function updateLabels(rows: Vector[], centroids: Vector[], norm: Norm): Vector { const m = rows.length; const vectorBuilder = rows[0].builder(); return vectorBuilder.fromIndexFunction(m, i => @@ -52,11 +45,7 @@ function updateLabels( ); } -function getIndexOfClosestCentroid( - row: Vector, - centroids: Vector[], - norm: Norm -): number { +function getIndexOfClosestCentroid(row: Vector, centroids: Vector[], norm: Norm): number { let min = Number.MAX_VALUE; let index = -1; @@ -71,10 +60,10 @@ function getIndexOfClosestCentroid( return index; } -function updateCentroids(rows: Vector[], labels: Vector): Vector[] { +function updateCentroids(rows: Vector[], labels: Vector): Vector[] { const n = rows[0].getDimension(); const zero = rows[0].builder().zeros(n); - const clusters: Vector[][] = []; + const clusters: Vector[][] = []; rows.forEach((row, i) => { const label = labels.getEntry(i); @@ -94,14 +83,14 @@ function updateCentroids(rows: Vector[], labels: Vector): Vector return centroids; } -function initializeCentroids(X: Matrix, k: number, n: number): Vector[] { +function initializeCentroids(X: Matrix, k: number, n: number): Vector[] { const vectorBuilder = X.vectorBuilder(); const ops = X.ops(); ops.randomNormal; const means = mean(X); const stdDevs = standardDeviation(X).map(x => 2 * x); - const cols: Vector[] = []; + const cols: Vector[] = []; for (let i = 0; i < n; i++) { cols.push(vectorBuilder.randomNormal(k, means.getEntry(i), stdDevs.getEntry(i))); } diff --git a/src/applications/machine-learning/kernels/GaussianKernel.ts b/src/applications/machine-learning/kernels/GaussianKernel.ts index e7d9b52..6a77140 100644 --- a/src/applications/machine-learning/kernels/GaussianKernel.ts +++ b/src/applications/machine-learning/kernels/GaussianKernel.ts @@ -20,7 +20,7 @@ export function GaussianKernel(sigmaSquared: number): Kernel { /** * {@see SimilarityMetric} */ -function gaussianSimilarity(sigmaSquared: number, v1: Vector, v2: Vector): number { +function gaussianSimilarity(sigmaSquared: number, v1: Vector, v2: Vector): number { const diff = euclideanNorm(v1.add(v2.scalarMultiply(-1))); return gaussian(diff, sigmaSquared); } diff --git a/src/applications/machine-learning/kernels/Kernel.ts b/src/applications/machine-learning/kernels/Kernel.ts index 27174aa..4bf4b68 100644 --- a/src/applications/machine-learning/kernels/Kernel.ts +++ b/src/applications/machine-learning/kernels/Kernel.ts @@ -9,4 +9,4 @@ import { Matrix } from '../../../types/matrix/Matrix'; * * @public */ -export type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; +export type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix; diff --git a/src/applications/machine-learning/kernels/LinearKernel.ts b/src/applications/machine-learning/kernels/LinearKernel.ts index 3cdb57f..8a81eee 100644 --- a/src/applications/machine-learning/kernels/LinearKernel.ts +++ b/src/applications/machine-learning/kernels/LinearKernel.ts @@ -10,7 +10,7 @@ import { Matrix } from '../../../types/matrix/Matrix'; * * @public */ -export function LinearKernel(data: Matrix): Matrix { +export function LinearKernel(data: Matrix): Matrix { const m = data.getNumberOfRows(); const ones = data.builder().ones([m, 1]); return data.builder().augment(ones, data); diff --git a/src/applications/machine-learning/kernels/RadialBasisFunction.ts b/src/applications/machine-learning/kernels/RadialBasisFunction.ts index bebdb10..a23831a 100644 --- a/src/applications/machine-learning/kernels/RadialBasisFunction.ts +++ b/src/applications/machine-learning/kernels/RadialBasisFunction.ts @@ -8,7 +8,7 @@ import { Kernel } from './Kernel'; * * @public */ -export type SimilarityMetric = (v1: Vector, v2: Vector) => number; +export type SimilarityMetric = (v1: Vector, v2: Vector) => number; /** * Creates a {@link Kernel} for use in a {@link SupportVectorMachineClassifier}. @@ -22,7 +22,7 @@ export type SimilarityMetric = (v1: Vector, v2: Vector) => numbe * @public */ export function RadialBasisFunction(distanceMetric: SimilarityMetric): Kernel { - return (data: Matrix, trainingData: Matrix = data) => { + return (data: Matrix, trainingData: Matrix = data) => { const [m] = data.getShape(); const [n] = trainingData.getShape(); diff --git a/src/applications/machine-learning/kernels/__tests__/RadialBasisFunction.spec.ts b/src/applications/machine-learning/kernels/__tests__/RadialBasisFunction.spec.ts index f169489..4ef3200 100644 --- a/src/applications/machine-learning/kernels/__tests__/RadialBasisFunction.spec.ts +++ b/src/applications/machine-learning/kernels/__tests__/RadialBasisFunction.spec.ts @@ -8,8 +8,7 @@ describe('RadialBasisFunction', () => { it('constructs a similarity matrix given a similarity metric', () => { // Note: this is a distance metric rather than a similarity metric, // but for testing purposes it works just fine. - const metric = (v1: Vector, v2: Vector) => - euclideanNorm(v1.add(v2.scalarMultiply(-1))); + const metric = (v1: Vector, v2: Vector) => euclideanNorm(v1.add(v2.scalarMultiply(-1))); const data = loadTestData('iris'); const kerneled = RadialBasisFunction(metric)(data); diff --git a/src/applications/machine-learning/models/Classifier.ts b/src/applications/machine-learning/models/Classifier.ts index 301f624..887f0e8 100644 --- a/src/applications/machine-learning/models/Classifier.ts +++ b/src/applications/machine-learning/models/Classifier.ts @@ -13,7 +13,7 @@ export interface Classifier { * @param target - A {@link Vector} whose entries are the target values in the training set * @public */ - train(data: Matrix, target: Vector): void; + train(data: Matrix, target: Vector): void; /** * Uses the learned parameters to make predictions for the probability of an event @@ -25,7 +25,7 @@ export interface Classifier { * @param data - A {@link Vector} whose rows are the observations in the test set * @public */ - predictProbabilities(data: Matrix): Vector; + predictProbabilities(data: Matrix): Vector; /** * Uses the learned parameters to make predictions based on a set of input data. @@ -37,7 +37,7 @@ export interface Classifier { * @param pThreshold - The probability threshold above which an event will be predicted * @public */ - predict(data: Matrix, pThreshold: number): Vector; + predict(data: Matrix, pThreshold: number): Vector; /** * Return the full set of hyperparameters used to train the model, including defaults. diff --git a/src/applications/machine-learning/models/LinearRegressor.ts b/src/applications/machine-learning/models/LinearRegressor.ts index aeececa..eea1bae 100644 --- a/src/applications/machine-learning/models/LinearRegressor.ts +++ b/src/applications/machine-learning/models/LinearRegressor.ts @@ -28,7 +28,7 @@ export type LinearRegressorHyperparams = GradientDescentParameters & { */ export class LinearRegressor implements Regressor { private readonly _hyperParameters: Readonly>; - private _theta: Vector | undefined; + private _theta: Vector | undefined; constructor(hyperParameters: Partial) { this._hyperParameters = Object.freeze(hyperParameters); @@ -40,7 +40,7 @@ export class LinearRegressor implements Regressor { * `undefined` if the model has not been trained. * @public */ - public getParameters(): Vector | undefined { + public getParameters(): Vector | undefined { return this._theta; } @@ -57,7 +57,7 @@ export class LinearRegressor implements Regressor { /** * {@inheritDoc Regressor.train} */ - public train(data: Matrix, target: Vector): void { + public train(data: Matrix, target: Vector): void { const initialTheta = FloatVector.builder().random(data.getNumberOfColumns() + 1, -0.01, 0.01); this._theta = gradientDescent(this._hyperParameters)(initialTheta, theta => ({ cost: this.calculateCost(data, target, theta), @@ -68,16 +68,12 @@ export class LinearRegressor implements Regressor { /** * {@inheritDoc Regressor.predict} */ - public predict(data: Matrix): Vector { + public predict(data: Matrix): Vector { if (!this._theta) throw new Error(`Cannot call predict before train`); return this.makePredictions(data, this._theta); } - private calculateCost( - data: Matrix, - target: Vector, - theta: Vector - ): number { + private calculateCost(data: Matrix, target: Vector, theta: Vector): number { const { lambda } = this.getHyperParameters(); const predictions = this.makePredictions(data, theta); const residuals = target.scalarMultiply(-1).add(predictions); @@ -92,11 +88,7 @@ export class LinearRegressor implements Regressor { return meanSquaredError + regularizationTerm; } - private calculateGradient( - data: Matrix, - target: Vector, - theta: Vector - ): Vector { + private calculateGradient(data: Matrix, target: Vector, theta: Vector): Vector { const { lambda } = this.getHyperParameters(); const m = data.getNumberOfRows(); @@ -113,7 +105,7 @@ export class LinearRegressor implements Regressor { return gradientTerm.add(regularizationTerm); } - private makePredictions(data: Matrix, theta: Vector): Vector { + private makePredictions(data: Matrix, theta: Vector): Vector { return LinearKernel(data).apply(theta); } diff --git a/src/applications/machine-learning/models/LogisticRegressionClassifier.ts b/src/applications/machine-learning/models/LogisticRegressionClassifier.ts index 149cb29..1053069 100644 --- a/src/applications/machine-learning/models/LogisticRegressionClassifier.ts +++ b/src/applications/machine-learning/models/LogisticRegressionClassifier.ts @@ -28,7 +28,7 @@ export type LogisticRegressionHyperparams = GradientDescentParameters & { */ export class LogisticRegressionClassifier implements Classifier { private readonly _hyperParameters: Readonly>; - private _theta: Vector | undefined; + private _theta: Vector | undefined; constructor(hyperParameters: Partial) { this._hyperParameters = Object.freeze(hyperParameters); @@ -39,7 +39,7 @@ export class LogisticRegressionClassifier implements Classifier | undefined { + public getParameters(): Vector | undefined { return this._theta; } @@ -56,7 +56,7 @@ export class LogisticRegressionClassifier implements Classifier, target: Vector): void { + public train(data: Matrix, target: Vector): void { const initialTheta = FloatVector.builder().random(data.getNumberOfColumns() + 1, -0.01, 0.01); this._theta = gradientDescent(this._hyperParameters)(initialTheta, theta => ({ cost: this.calculateCost(data, target, theta), @@ -67,7 +67,7 @@ export class LogisticRegressionClassifier implements Classifier): Vector { + public predictProbabilities(data: Matrix): Vector { if (!this._theta) throw new Error(`Cannot call predictProbabilities before train`); return this.makeProbabilityPredictions(data, this._theta); } @@ -75,30 +75,22 @@ export class LogisticRegressionClassifier implements Classifier): Vector { + public predict(data: Matrix): Vector { if (!this._theta) throw new Error(`Cannot call predict before train`); return this.makePredictions(data, this._theta); } - private makePredictions( - data: Matrix, - theta: Vector, - threshold?: number - ): Vector { + private makePredictions(data: Matrix, theta: Vector, threshold?: number): Vector { return this.makeProbabilityPredictions(data, theta).map(p => (p > (threshold || 0.5) ? 1 : 0)); } - private makeProbabilityPredictions(data: Matrix, theta: Vector): Vector { + private makeProbabilityPredictions(data: Matrix, theta: Vector): Vector { return LinearKernel(data) .apply(theta) .map(sigmoid); } - private calculateCost( - data: Matrix, - target: Vector, - theta: Vector - ): number { + private calculateCost(data: Matrix, target: Vector, theta: Vector): number { const { lambda } = this.getHyperParameters(); const probabilities = this.makeProbabilityPredictions(data, theta); @@ -126,11 +118,7 @@ export class LogisticRegressionClassifier implements Classifier, - target: Vector, - theta: Vector - ): Vector { + private calculateGradient(data: Matrix, target: Vector, theta: Vector): Vector { const m = data.getNumberOfRows(); const { lambda } = this.getHyperParameters(); diff --git a/src/applications/machine-learning/models/Regressor.ts b/src/applications/machine-learning/models/Regressor.ts index 2c277d4..61674e5 100644 --- a/src/applications/machine-learning/models/Regressor.ts +++ b/src/applications/machine-learning/models/Regressor.ts @@ -13,7 +13,7 @@ export interface Regressor { * @param target - A {@link Vector} whose entries are the target values in the training set * @public */ - train(data: Matrix, target: Vector): void; + train(data: Matrix, target: Vector): void; /** * Uses the learned parameters to make predictions based on a set of input data. @@ -24,7 +24,7 @@ export interface Regressor { * @param data - A {@link Vector} whose rows are the observations in the test set * @public */ - predict(data: Matrix): Vector; + predict(data: Matrix): Vector; /** * Return the full set of hyperparameters used to train the model, including defaults. diff --git a/src/applications/machine-learning/models/SupportVectorMachineClassifier.ts b/src/applications/machine-learning/models/SupportVectorMachineClassifier.ts index 1f936a4..705f333 100644 --- a/src/applications/machine-learning/models/SupportVectorMachineClassifier.ts +++ b/src/applications/machine-learning/models/SupportVectorMachineClassifier.ts @@ -34,8 +34,8 @@ export type SupportVectorMachineHyperparams = GradientDescentParameters & { */ export class SupportVectorMachineClassifier implements Classifier { private readonly _hyperParameters: Readonly>; - private _weights: Vector | undefined; - private _trainingData: Matrix | undefined; + private _weights: Vector | undefined; + private _trainingData: Matrix | undefined; constructor(hyperParameters: Partial) { this._hyperParameters = Object.freeze(hyperParameters); @@ -46,14 +46,14 @@ export class SupportVectorMachineClassifier implements Classifier | undefined { + public getParameters(): Vector | undefined { return this._weights; } /** * {@inheritDoc Classifier.train} */ - public train(data: Matrix, target: Vector): void { + public train(data: Matrix, target: Vector): void { const { kernel } = this.getHyperParameters(); this._trainingData = data; @@ -69,14 +69,14 @@ export class SupportVectorMachineClassifier implements Classifier): Vector { + public predictProbabilities(_data: Matrix): Vector { throw Error(`Probability predictions not implemented for SVM Classifier`); } /** * {@inheritDoc Classifier.predict} */ - public predict(data: Matrix): Vector { + public predict(data: Matrix): Vector { if (!this._weights) throw new Error(`Cannot call predict before train`); const { kernel } = this.getHyperParameters(); @@ -95,16 +95,12 @@ export class SupportVectorMachineClassifier implements Classifier, weights: Vector): Vector { + private makePredictions(X: Matrix, weights: Vector): Vector { const scores = this.calculateScores(X, weights); return scores.map(score => (score > 0 ? 1 : 0)); } - private calculateCost( - X: Matrix, - target: Vector, - weights: Vector - ): number { + private calculateCost(X: Matrix, target: Vector, weights: Vector): number { const [m] = X.getShape(); const scores = this.calculateScores(X, weights); const costs = scores.map((score, i) => { @@ -114,11 +110,7 @@ export class SupportVectorMachineClassifier implements Classifier, - target: Vector, - weights: Vector - ): Vector { + private calculateGradient(X: Matrix, target: Vector, weights: Vector): Vector { const [m] = X.getShape(); const scores = this.calculateScores(X, weights); @@ -144,7 +136,7 @@ export class SupportVectorMachineClassifier implements Classifier, weights: Vector): Vector { + private calculateScores(X: Matrix, weights: Vector): Vector { return X.apply(weights); } diff --git a/src/applications/statistics/PrincipalComponentAnalysis.ts b/src/applications/statistics/PrincipalComponentAnalysis.ts index 5629117..a9d16a8 100644 --- a/src/applications/statistics/PrincipalComponentAnalysis.ts +++ b/src/applications/statistics/PrincipalComponentAnalysis.ts @@ -105,10 +105,7 @@ export type DimensionReductionOptions = DimensionReductionType & { * be explained by the remaining columns * @public */ -export function reduceDimensions( - A: Matrix, - options: DimensionReductionOptions -): Matrix { +export function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix { let keep = A.getNumberOfColumns(); if (hasKeep(options) && (options.keep > keep || options.keep < 0)) { throw Error(`Cannot keep ${options.keep} dimensions of a matrix with ${keep} columns`); diff --git a/src/applications/statistics/__tests__/LeastSquares.spec.ts b/src/applications/statistics/__tests__/LeastSquares.spec.ts index 12a5ef5..57c3ce6 100644 --- a/src/applications/statistics/__tests__/LeastSquares.spec.ts +++ b/src/applications/statistics/__tests__/LeastSquares.spec.ts @@ -82,7 +82,7 @@ describe('LeastSquares', () => { describe('calculateGeneralLeastSquaresApproximation', () => { test('calculates a quadratic regression', () => { const data = singleVariableTestData.getRowVectors(); - const quadraticTemplate = (coefficients: Vector) => (inputs: Vector) => { + const quadraticTemplate = (coefficients: Vector) => (inputs: Vector) => { const x = inputs.getEntry(0); const constantTerm = coefficients.getEntry(0); const linearTerm = coefficients.getEntry(1) * x; diff --git a/src/operations/__tests__/GaussJordan.spec.ts b/src/operations/__tests__/GaussJordan.spec.ts index b018f26..6a02481 100644 --- a/src/operations/__tests__/GaussJordan.spec.ts +++ b/src/operations/__tests__/GaussJordan.spec.ts @@ -227,7 +227,7 @@ describe('GaussJordan', () => { const I = eye(3); const iInv = inverse(I); expect(iInv).not.toBeUndefined; - expect((iInv as Matrix).equals(I)).toBe(true); + expect((iInv as Matrix).equals(I)).toBe(true); }); test('calculates the inverse of a square matrix', () => { @@ -239,7 +239,7 @@ describe('GaussJordan', () => { [0.6, -0.7], [-0.2, 0.4] ]); - const aInv = inverse(A) as Matrix; + const aInv = inverse(A) as Matrix; expect(aInv).not.toBeUndefined; expect(aInv.equals(expectedInverse)).toBe(true); }); diff --git a/src/types/matrix/ArrayMatrix.ts b/src/types/matrix/ArrayMatrix.ts index 7731df7..e693e4c 100644 --- a/src/types/matrix/ArrayMatrix.ts +++ b/src/types/matrix/ArrayMatrix.ts @@ -18,7 +18,7 @@ import { MatrixBuilder } from './MatrixBuilder'; * * @public */ -export abstract class ArrayMatrix implements Matrix { +export abstract class ArrayMatrix implements Matrix { private readonly _data: MatrixData; /** diff --git a/src/types/matrix/Matrix.ts b/src/types/matrix/Matrix.ts index aed63f8..83fce1e 100644 --- a/src/types/matrix/Matrix.ts +++ b/src/types/matrix/Matrix.ts @@ -32,7 +32,7 @@ export interface MatrixConstructor, M extends Matrix> * A generalized Matrix - one of the core data types * @public */ -export interface Matrix extends LinearTransformation, Vector> { +export interface Matrix extends LinearTransformation, Vector> { /** * Returns a {@link ScalarOperations} object which will allow consumers to work generically * with the scalars contained in the vector. diff --git a/src/types/matrix/SparseMatrix.ts b/src/types/matrix/SparseMatrix.ts index d663416..e3c13da 100644 --- a/src/types/matrix/SparseMatrix.ts +++ b/src/types/matrix/SparseMatrix.ts @@ -31,7 +31,7 @@ type MutableSparseMatrixData = Map>; * * @public */ -export abstract class SparseMatrix implements Matrix { +export abstract class SparseMatrix implements Matrix { private readonly _shape: MatrixShape; private readonly _sparseData: SparseMatrixData; diff --git a/src/types/vector/ArrayVector.ts b/src/types/vector/ArrayVector.ts index 01f32fd..1a62df6 100644 --- a/src/types/vector/ArrayVector.ts +++ b/src/types/vector/ArrayVector.ts @@ -13,7 +13,7 @@ import { Matrix } from '../matrix/Matrix'; * * @public */ -export abstract class ArrayVector implements Vector { +export abstract class ArrayVector implements Vector { private readonly _data: VectorData; /** diff --git a/src/types/vector/SparseVector.ts b/src/types/vector/SparseVector.ts index 1691d18..9b10a8e 100644 --- a/src/types/vector/SparseVector.ts +++ b/src/types/vector/SparseVector.ts @@ -32,7 +32,7 @@ export function isSparse(vector: Vector): vector is SparseVector { * * @public */ -export abstract class SparseVector implements Vector { +export abstract class SparseVector implements Vector { private readonly _dimension: number; private readonly _sparseData: SparseVectorData; diff --git a/src/types/vector/Vector.ts b/src/types/vector/Vector.ts index 75032c4..600f8f3 100644 --- a/src/types/vector/Vector.ts +++ b/src/types/vector/Vector.ts @@ -22,7 +22,7 @@ export interface VectorConstructor> { * A generalized Vector - one of the core data types * @public */ -export interface Vector { +export interface Vector { /** * Returns a {@link ScalarOperations} object which will allow consumers to work generically * with the scalars contained in the vector. diff --git a/src/utilities/aliases.ts b/src/utilities/aliases.ts index fddabba..e14eb76 100644 --- a/src/utilities/aliases.ts +++ b/src/utilities/aliases.ts @@ -10,7 +10,7 @@ const mb = FloatMatrix.builder(); * Creates a new {@link Vector} of numbers. See {@link VectorBuilder.fromArray} * @public */ -export function vec(data: number[]): Vector { +export function vec(data: number[]): Vector { return vb.fromArray(data); } @@ -18,7 +18,7 @@ export function vec(data: number[]): Vector { * Creates a new {@link Matrix} of numbers. See {@link MatrixBuilder.fromArray} * @public */ -export function mat(data: number[][]): Matrix { +export function mat(data: number[][]): Matrix { return mb.fromArray(data); } @@ -26,7 +26,7 @@ export function mat(data: number[][]): Matrix { * Creates a new identity matrix of size `size`. See {@link MatrixBuilder.identity} * @public */ -export function eye(size: number): Matrix { +export function eye(size: number): Matrix { return mb.identity(size); } @@ -34,13 +34,13 @@ export function eye(size: number): Matrix { * Creates a new vector of all 1s. See {@link VectorBuilder.ones} * @public */ -export function ones(entries: number): Vector; +export function ones(entries: number): Vector; /** * Creates a new matrix of all 1s. See {@link MatrixBuilder.ones} * @public */ -export function ones(shape: MatrixShape): Matrix; -export function ones(shapeOrDim: number | MatrixShape): Matrix | Vector { +export function ones(shape: MatrixShape): Matrix; +export function ones(shapeOrDim: number | MatrixShape): Matrix | Vector { return Array.isArray(shapeOrDim) ? mb.ones(shapeOrDim) : vb.ones(shapeOrDim); } @@ -48,13 +48,13 @@ export function ones(shapeOrDim: number | MatrixShape): Matrix | Vector< * Creates a new vector of all 0s. See {@link VectorBuilder.zeros} * @public */ -export function zeros(entries: number): Vector; +export function zeros(entries: number): Vector; /** * Creates a new matrix of all 0s. See {@link MatrixBuilder.zeros} * @public */ -export function zeros(shape: MatrixShape): Matrix; -export function zeros(shapeOrDim: number | MatrixShape): Matrix | Vector { +export function zeros(shape: MatrixShape): Matrix; +export function zeros(shapeOrDim: number | MatrixShape): Matrix | Vector { return Array.isArray(shapeOrDim) ? mb.zeros(shapeOrDim) : vb.zeros(shapeOrDim); } @@ -62,6 +62,6 @@ export function zeros(shapeOrDim: number | MatrixShape): Matrix | Vector * Creates a new matrix with the specified entries on the diagonal. See {@link MatrixBuilder.diagonal} * @public */ -export function diag(elements: number[]): Matrix { +export function diag(elements: number[]): Matrix { return mb.diagonal(vec(elements)); } diff --git a/test/utils/rounding.ts b/test/utils/rounding.ts index 1d4afde..bb47ffb 100644 --- a/test/utils/rounding.ts +++ b/test/utils/rounding.ts @@ -1,11 +1,11 @@ import { Vector } from '../../src/types/vector/Vector'; import { Matrix } from '../../src/types/matrix/Matrix'; -export function roundMatrix(M: Matrix, decimals: number): Matrix { +export function roundMatrix(M: Matrix, decimals: number): Matrix { return M.map(x => round(x, decimals)); } -export function roundVector(v: Vector, decimals: number): Vector { +export function roundVector(v: Vector, decimals: number): Vector { return v.map(x => round(x, decimals)); } diff --git a/test/utils/testData.ts b/test/utils/testData.ts index 6887741..5c17e90 100644 --- a/test/utils/testData.ts +++ b/test/utils/testData.ts @@ -5,17 +5,17 @@ import csvWriter from 'csv-stringify/lib/sync'; import { Matrix } from '../../src/types/matrix/Matrix'; import { mat } from '../../src/utilities/aliases'; -const cache: Map> = new Map(); +const cache: Map = new Map(); -export function loadTestData(name: string): Matrix { - if (cache.has(name)) return cache.get(name) as Matrix; +export function loadTestData(name: string): Matrix { + if (cache.has(name)) return cache.get(name) as Matrix; const contents = fs.readFileSync(path.resolve(__dirname, '../data/', name + '.csv')).toString(); const data = (csvParser(contents) as any[][]).map(row => row.map(entry => parseFloat(entry))); return mat(data); } -export function writeTestData(name: string, matrix: Matrix): void { +export function writeTestData(name: string, matrix: Matrix): void { const contents = csvWriter(matrix.toArray()); fs.writeFileSync(path.resolve(__dirname, '../data/', name + '.csv'), contents); }