Skip to content

Commit

Permalink
feat: Add default scalar type to Vector and Matrix (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrown1618 authored Feb 24, 2020
1 parent f06600c commit 100b05b
Show file tree
Hide file tree
Showing 66 changed files with 196 additions and 242 deletions.
76 changes: 38 additions & 38 deletions docs/VECTOR.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ApproximationFunction<S> = (input: Vector<S>) => S;
export type ApproximationFunctionTemplate<S> = (coefficients: Vector<S>) => ApproximationFunction<S>;

// @public
export abstract class ArrayMatrix<S> implements Matrix<S> {
export abstract class ArrayMatrix<S = number> implements Matrix<S> {
// @internal
protected constructor(data: MatrixData<S>);
add(other: Matrix<S>): Matrix<S>;
Expand Down Expand Up @@ -43,7 +43,7 @@ export abstract class ArrayMatrix<S> implements Matrix<S> {
}

// @public
export abstract class ArrayVector<S> implements Vector<S> {
export abstract class ArrayVector<S = number> implements Vector<S> {
// @internal
protected constructor(data: VectorData<S>);
add(other: Vector<S>): Vector<S>;
Expand Down Expand Up @@ -107,9 +107,9 @@ export interface CholeskyDecomposition<S> {
// @public
export interface Classifier<H> {
getHyperParameters(): H;
predict(data: Matrix<number>, pThreshold: number): Vector<number>;
predictProbabilities(data: Matrix<number>): Vector<number>;
train(data: Matrix<number>, target: Vector<number>): void;
predict(data: Matrix, pThreshold: number): Vector;
predictProbabilities(data: Matrix): Vector;
train(data: Matrix, target: Vector): void;
}

// @public
Expand Down Expand Up @@ -202,11 +202,11 @@ export interface Cost {
// (undocumented)
cost: number;
// (undocumented)
gradient: Vector<number>;
gradient: Vector;
}

// @public
export type CostFunction = (theta: Vector<number>) => Cost;
export type CostFunction = (theta: Vector) => Cost;

// @public
export function covariance<S>(first: Vector<S>, second: Vector<S>): S;
Expand All @@ -218,13 +218,13 @@ export function covariance<S>(A: Matrix<S>): Matrix<S>;
export function crossProduct<S>(first: Vector<S>, second: Vector<S>): Vector<S>;

// @public
export function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector<number>;
export function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector;

// @public
export function determinant<S>(matrix: Matrix<S>): S;

// @public
export function diag(elements: number[]): Matrix<number>;
export function diag(elements: number[]): Matrix;

// Warning: (ae-forgotten-export) The symbol "DimensionReductionType" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -254,7 +254,7 @@ export function euclideanNorm<S>(v: Vector<S>): number;
export function exp<S>(A: Matrix<S>, order?: number): Matrix<S>;

// @public
export function eye(size: number): Matrix<number>;
export function eye(size: number): Matrix;

// @public
export class FloatMatrix implements Matrix<number> {
Expand Down Expand Up @@ -382,13 +382,13 @@ export function isSymmetric<S>(matrix: Matrix<S>): boolean;
export function isUpperTriangular<S>(matrix: Matrix<S>): boolean;

// @public
export type Kernel = (data: Matrix<number>, trainingData?: Matrix<number>) => Matrix<number>;
export type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix;

// @public
export function kroneckerProduct<S>(first: Matrix<S>, second: Matrix<S>): Matrix<S>;

// @public
export type LearningAlgorithm = (initialTheta: Vector<number>, costFn: CostFunction) => Vector<number>;
export type LearningAlgorithm = (initialTheta: Vector, costFn: CostFunction) => Vector;

// @public
export interface LeastSquaresApproximation<S> {
Expand All @@ -397,15 +397,15 @@ export interface LeastSquaresApproximation<S> {
}

// @public
export function LinearKernel(data: Matrix<number>): Matrix<number>;
export function LinearKernel(data: Matrix): Matrix;

// @public
export class LinearRegressor implements Regressor<LinearRegressorHyperparams> {
constructor(hyperParameters: Partial<LinearRegressorHyperparams>);
getHyperParameters(): LinearRegressorHyperparams;
getParameters(): Vector<number> | undefined;
predict(data: Matrix<number>): Vector<number>;
train(data: Matrix<number>, target: Vector<number>): void;
getParameters(): Vector | undefined;
predict(data: Matrix): Vector;
train(data: Matrix, target: Vector): void;
}

// @public
Expand All @@ -425,10 +425,10 @@ export function linspace(xMin: number, xMax: number, binCount: number): NumberVe
export class LogisticRegressionClassifier implements Classifier<LogisticRegressionHyperparams> {
constructor(hyperParameters: Partial<LogisticRegressionHyperparams>);
getHyperParameters(): LogisticRegressionHyperparams;
getParameters(): Vector<number> | undefined;
predict(data: Matrix<number>): Vector<number>;
predictProbabilities(data: Matrix<number>): Vector<number>;
train(data: Matrix<number>, target: Vector<number>): void;
getParameters(): Vector | undefined;
predict(data: Matrix): Vector;
predictProbabilities(data: Matrix): Vector;
train(data: Matrix, target: Vector): void;
}

// @public
Expand All @@ -447,10 +447,10 @@ export interface LUDecomposition<S> {
}

// @public
export function mat(data: number[][]): Matrix<number>;
export function mat(data: number[][]): Matrix;

// @public
export interface Matrix<S> extends LinearTransformation<Vector<S>, Vector<S>> {
export interface Matrix<S = number> extends LinearTransformation<Vector<S>, Vector<S>> {
add(other: Matrix<S>): Matrix<S>;
adjoint(): Matrix<S>;
apply(vector: Vector<S>): Vector<S>;
Expand Down Expand Up @@ -597,10 +597,10 @@ export class NumberVector extends ArrayVector<number> {
}

// @public
export function ones(entries: number): Vector<number>;
export function ones(entries: number): Vector;

// @public
export function ones(shape: MatrixShape): Matrix<number>;
export function ones(shape: MatrixShape): Matrix;

// @public
export function pca<S>(A: Matrix<S>, useCorrelation?: boolean): PrincipalComponentAnalysis<S>;
Expand Down Expand Up @@ -644,16 +644,16 @@ export function RadialBasisFunction(distanceMetric: SimilarityMetric): Kernel;
export function rank<S>(matrix: Matrix<S>): number;

// @public
export function reduceDimensions(A: Matrix<number>, options: DimensionReductionOptions): Matrix<number>;
export function reduceDimensions(A: Matrix, options: DimensionReductionOptions): Matrix;

// @public
export function reducedRowEchelonForm<S>(matrix: Matrix<S>): Matrix<S>;

// @public
export interface Regressor<H> {
getHyperParameters(): H;
predict(data: Matrix<number>): Vector<number>;
train(data: Matrix<number>, target: Vector<number>): void;
predict(data: Matrix): Vector;
train(data: Matrix, target: Vector): void;
}

// @public
Expand Down Expand Up @@ -704,7 +704,7 @@ export abstract class ScalarOperations<S> {
}

// @public
export type SimilarityMetric = (v1: Vector<number>, v2: Vector<number>) => number;
export type SimilarityMetric = (v1: Vector, v2: Vector) => number;

// @public
export interface SingularValueDecomposition<S> {
Expand All @@ -725,7 +725,7 @@ export function solveByGaussianElimination<S>(A: Matrix<S>, b: Vector<S>): Linea
export function solveOverdeterminedSystem<S>(A: Matrix<S>, b: Vector<S>): Vector<S>;

// @public
export abstract class SparseMatrix<S> implements Matrix<S> {
export abstract class SparseMatrix<S = number> implements Matrix<S> {
// @internal
protected constructor(data: MatrixData<S>);
add(other: Matrix<S>): Matrix<S>;
Expand Down Expand Up @@ -791,7 +791,7 @@ export class SparseNumberVector extends SparseVector<number> {
}

// @public
export abstract class SparseVector<S> implements Vector<S> {
export abstract class SparseVector<S = number> implements Vector<S> {
// @internal
protected constructor(data: VectorData<S>);
add(other: Vector<S>): Vector<S>;
Expand Down Expand Up @@ -838,10 +838,10 @@ export function sumNorm<S>(v: Vector<S>): number;
export class SupportVectorMachineClassifier implements Classifier<SupportVectorMachineHyperparams> {
constructor(hyperParameters: Partial<SupportVectorMachineHyperparams>);
getHyperParameters(): SupportVectorMachineHyperparams;
getParameters(): Vector<number> | undefined;
predict(data: Matrix<number>): Vector<number>;
predictProbabilities(_data: Matrix<number>): Vector<number>;
train(data: Matrix<number>, target: Vector<number>): void;
getParameters(): Vector | undefined;
predict(data: Matrix): Vector;
predictProbabilities(_data: Matrix): Vector;
train(data: Matrix, target: Vector): void;
}

// @public
Expand All @@ -863,10 +863,10 @@ export function variance<S>(x: Vector<S>): S;
export function variance<S>(A: Matrix<S>): Vector<S>;

// @public
export function vec(data: number[]): Vector<number>;
export function vec(data: number[]): Vector;

// @public
export interface Vector<S> {
export interface Vector<S = number> {
add(other: Vector<S>): Vector<S>;
builder(): VectorBuilder<S, Vector<S>>;
combine(other: Vector<S>, combineEntries: (a: S, b: S) => S): Vector<S>;
Expand Down Expand Up @@ -929,10 +929,10 @@ export type VectorData<S> = readonly S[];
export type VectorIndexFunction<S> = (index: number) => S;

// @public
export function zeros(entries: number): Vector<number>;
export function zeros(entries: number): Vector;

// @public
export function zeros(shape: MatrixShape): Matrix<number>;
export function zeros(shape: MatrixShape): Matrix;


// (No @packageDocumentation comment for this package)
Expand Down
2 changes: 1 addition & 1 deletion docs/api/vector.arraymatrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Implements [Matrix](./vector.matrix.md) with a 2-dimensional array of values.
<b>Signature:</b>

```typescript
export declare abstract class ArrayMatrix<S> implements Matrix<S>
export declare abstract class ArrayMatrix<S = number> implements Matrix<S>
```
## Remarks
Expand Down
2 changes: 1 addition & 1 deletion docs/api/vector.arrayvector.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Implements [Vector](./vector.vector.md) with an array of values.
<b>Signature:</b>

```typescript
export declare abstract class ArrayVector<S> implements Vector<S>
export declare abstract class ArrayVector<S = number> implements Vector<S>
```
## Remarks
Expand Down
6 changes: 3 additions & 3 deletions docs/api/vector.classifier.predict.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ Uses the learned parameters to make predictions based on a set of input data.
<b>Signature:</b>

```typescript
predict(data: Matrix<number>, pThreshold: number): Vector<number>;
predict(data: Matrix, pThreshold: number): Vector;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| data | <code>Matrix&lt;number&gt;</code> | A [Vector](./vector.vector.md) whose rows are the observations in the test set |
| data | <code>Matrix</code> | A [Vector](./vector.vector.md) whose rows are the observations in the test set |
| pThreshold | <code>number</code> | The probability threshold above which an event will be predicted |

<b>Returns:</b>

`Vector<number>`
`Vector`

## Remarks

Expand Down
6 changes: 3 additions & 3 deletions docs/api/vector.classifier.predictprobabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Uses the learned parameters to make predictions for the probability of an event
<b>Signature:</b>

```typescript
predictProbabilities(data: Matrix<number>): Vector<number>;
predictProbabilities(data: Matrix): Vector;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| data | <code>Matrix&lt;number&gt;</code> | A [Vector](./vector.vector.md) whose rows are the observations in the test set |
| data | <code>Matrix</code> | A [Vector](./vector.vector.md) whose rows are the observations in the test set |

<b>Returns:</b>

`Vector<number>`
`Vector`

## Remarks

Expand Down
6 changes: 3 additions & 3 deletions docs/api/vector.classifier.train.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Learns the optimal set of parameters for the model.
<b>Signature:</b>

```typescript
train(data: Matrix<number>, target: Vector<number>): void;
train(data: Matrix, target: Vector): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| data | <code>Matrix&lt;number&gt;</code> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set |
| target | <code>Vector&lt;number&gt;</code> | A [Vector](./vector.vector.md) whose entries are the target values in the training set |
| data | <code>Matrix</code> | A [Matrix](./vector.matrix.md) whose rows are the individual observations in the training set |
| target | <code>Vector</code> | A [Vector](./vector.vector.md) whose entries are the target values in the training set |

<b>Returns:</b>

Expand Down
2 changes: 1 addition & 1 deletion docs/api/vector.cost.gradient.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
gradient: Vector<number>;
gradient: Vector;
```
2 changes: 1 addition & 1 deletion docs/api/vector.cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface Cost
| Property | Type | Description |
| --- | --- | --- |
| [cost](./vector.cost.cost.md) | <code>number</code> | |
| [gradient](./vector.cost.gradient.md) | <code>Vector&lt;number&gt;</code> | |
| [gradient](./vector.cost.gradient.md) | <code>Vector</code> | |

2 changes: 1 addition & 1 deletion docs/api/vector.costfunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ A function that evaluates the cost of a set of parameters `theta`
<b>Signature:</b>

```typescript
export declare type CostFunction = (theta: Vector<number>) => Cost;
export declare type CostFunction = (theta: Vector) => Cost;
```
4 changes: 2 additions & 2 deletions docs/api/vector.derivative.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Uses finite differences to build a vector containing approximate values of the d
<b>Signature:</b>

```typescript
export declare function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector<number>;
export declare function derivative(f: (x: number) => number, xMin: number, xMax: number, binCount: number): Vector;
```

## Parameters
Expand All @@ -23,7 +23,7 @@ export declare function derivative(f: (x: number) => number, xMin: number, xMax:

<b>Returns:</b>

`Vector<number>`
`Vector`

A linearly spaced vector whose values represent the values of the derivative

Expand Down
4 changes: 2 additions & 2 deletions docs/api/vector.diag.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Creates a new matrix with the specified entries on the diagonal. See [MatrixBuil
<b>Signature:</b>

```typescript
export declare function diag(elements: number[]): Matrix<number>;
export declare function diag(elements: number[]): Matrix;
```

## Parameters
Expand All @@ -20,5 +20,5 @@ export declare function diag(elements: number[]): Matrix<number>;

<b>Returns:</b>

`Matrix<number>`
`Matrix`

4 changes: 2 additions & 2 deletions docs/api/vector.eye.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Creates a new identity matrix of size `size`<!-- -->. See [MatrixBuilder.identit
<b>Signature:</b>

```typescript
export declare function eye(size: number): Matrix<number>;
export declare function eye(size: number): Matrix;
```

## Parameters
Expand All @@ -20,5 +20,5 @@ export declare function eye(size: number): Matrix<number>;

<b>Returns:</b>

`Matrix<number>`
`Matrix`

2 changes: 1 addition & 1 deletion docs/api/vector.kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Generally intended for use with a [SupportVectorMachineClassifier](./vector.supp
<b>Signature:</b>

```typescript
export declare type Kernel = (data: Matrix<number>, trainingData?: Matrix<number>) => Matrix<number>;
export declare type Kernel = (data: Matrix, trainingData?: Matrix) => Matrix;
```
Loading

0 comments on commit 100b05b

Please sign in to comment.