forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
217 lines (188 loc) · 6.28 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* NeuralNetwork section */
export interface INeuralNetworkOptions {
binaryThresh?: number;
hiddenLayers?: number[];
activation?: NeuralNetworkActivation;
leakyReluAlpha?: number;
}
export type NeuralNetworkActivation = 'sigmoid' | 'relu' | 'leaky-relu' | 'tanh';
export interface INeuralNetworkTrainingOptions {
iterations?: number;
errorThresh?: number;
log?: boolean | INeuralNetworkTrainingCallback;
logPeriod?: number;
learningRate?: number;
momentum?: number;
callback?: INeuralNetworkTrainingCallback | number;
callbackPeriod?: number;
timeout?: number;
praxis?: null | 'adam'
}
export interface INeuralNetworkTrainingCallback {
(state: INeuralNetworkState): void;
}
export interface INeuralNetworkState {
iterations: number;
error: number;
}
export interface INeuralNetworkJSON {
sizes: number[];
layers: object[];
outputLookup: any;
inputLookup: any;
activation: NeuralNetworkActivation,
trainOpts: INeuralNetworkTrainingOptions,
leakyReluAlpha?: number,
}
export interface INeuralNetworkTrainingData {
input: NeuralNetworkInput;
output: NeuralNetworkInput;
}
export type NeuralNetworkInput = number[];
export interface INeuralNetworkTestResult {
misclasses: any;
error: number;
total: number;
}
export interface INeuralNetworkBinaryTestResult extends INeuralNetworkTestResult {
trueNeg: number;
truePos: number;
falseNeg: number;
falsePos: number;
precision: number;
recall: number;
accuracy: number;
}
export class NeuralNetwork {
public constructor(options?: INeuralNetworkOptions);
public train(data: INeuralNetworkTrainingData[], options?: INeuralNetworkTrainingOptions): INeuralNetworkState;
public train<T>(data: T, options?: INeuralNetworkTrainingOptions): INeuralNetworkState;
public trainAsync(data: INeuralNetworkTrainingData, options?: INeuralNetworkTrainingOptions): Promise<INeuralNetworkState>;
public trainAsync<T>(data: T, options?: INeuralNetworkTrainingOptions): Promise<INeuralNetworkState>;
public test(data: INeuralNetworkTrainingData): INeuralNetworkTestResult | INeuralNetworkBinaryTestResult;
public run(data: NeuralNetworkInput): NeuralNetworkInput;
public run<T>(data: NeuralNetworkInput): T;
public run<TInput, TOutput>(data: TInput): TOutput;
public fromJSON(json: INeuralNetworkJSON): NeuralNetwork;
public toJSON(): INeuralNetworkJSON;
}
export class NeuralNetworkGPU extends NeuralNetwork {}
/* CrossValidate section */
export interface ICrossValidateJSON {
avgs: ICrossValidationTestPartitionResults;
stats: ICrossValidateStats;
sets: ICrossValidationTestPartitionResults[];
}
export interface ICrossValidateStats {
truePos: number;
trueNeg: number;
falsePos: number;
falseNeg: number;
total: number;
}
export interface ICrossValidationTestPartitionResults {
trainTime: number;
testTime: number;
iterations: number;
trainError: number;
learningRate: number;
hidden: number[];
network: NeuralNetwork;
}
export class CrossValidate {
public constructor(Classifier: typeof NeuralNetwork, options?: INeuralNetworkOptions);
public fromJSON(json: ICrossValidateJSON): NeuralNetwork;
public toJSON(): ICrossValidateJSON;
public train(
data: INeuralNetworkTrainingData[],
trainingOptions: INeuralNetworkTrainingOptions,
k?: number): ICrossValidateStats;
public train<T>(
data: T,
trainingOptions: INeuralNetworkTrainingOptions,
k?: number): ICrossValidateStats;
public testPartition(): ICrossValidationTestPartitionResults;
public toNeuralNetwork(): NeuralNetwork;
public toNeuralNetwork<T>(): T;
}
/* TrainStream section */
export interface ITrainStreamOptions {
neuralNetwork: NeuralNetwork,
neuralNetworkGPU: NeuralNetworkGPU,
floodCallback: () => void,
doneTrainingCallback: (state: INeuralNetworkState) => void
}
export class TrainStream {
public constructor(options: ITrainStreamOptions)
write(data: INeuralNetworkTrainingData): void;
write<T>(data: T): void;
endInputs(): void;
}
/* recurrent section */
export type RNNTrainingValue = string;
export interface IRNNTrainingData {
input: RNNTrainingValue,
output: RNNTrainingValue
}
export interface IRNNDefaultOptions extends INeuralNetworkOptions {
inputSize?: number;
outputSize?: number;
}
/* recurrent time step section */
export type RNNTimeStepInput = number[] | number[][] | object | object[] | object[][];
export type IRNNTimeStepTrainingDatum =
IRNNTimeStepTrainingNumbers
| IRNNTimeStepTrainingNumbers2D
| IRNNTimeStepTrainingObject
| IRNNTimeStepTrainingObjects
| IRNNTimeStepTrainingObject2D
| number[]
| number[][]
| object[]
| object[][];
export interface IRNNTimeStepTrainingNumbers {
input: number[],
output: number[]
}
export interface IRNNTimeStepTrainingNumbers2D {
input: number[][],
output: number[][]
}
export interface IRNNTimeStepTrainingObject {
input: object,
output: object
}
export interface IRNNTimeStepTrainingObjects {
input: object[],
output: object[]
}
export interface IRNNTimeStepTrainingObject2D {
input: object[][],
output: object[][]
}
export declare namespace recurrent {
class RNN extends NeuralNetwork {
constructor(options?: IRNNDefaultOptions)
run(data: RNNTrainingValue): RNNTrainingValue;
run<T>(data: RNNTrainingValue): T;
run<TInput, TOutput>(data: TInput): TOutput;
train(data: IRNNTrainingData[], options: INeuralNetworkTrainingOptions): INeuralNetworkState;
train<T>(data: T, options: INeuralNetworkTrainingOptions): INeuralNetworkState;
}
class LSTM extends recurrent.RNN {}
class GRU extends recurrent.RNN {}
class RNNTimeStep extends recurrent.RNN {
run(input: RNNTimeStepInput): RNNTimeStepInput;
run<T>(input: RNNTimeStepInput): T;
run<TInput, TOutput>(input: TInput): TOutput;
forecast(input: RNNTimeStepInput, count: number): RNNTimeStepInput;
forecast<T>(input: RNNTimeStepInput, count: number): T;
forecast<TInput, TOutput>(input: TInput, count: number): TOutput;
train(data: IRNNTimeStepTrainingDatum[], options: INeuralNetworkTrainingOptions): INeuralNetworkState;
train<T>(data: T, options: INeuralNetworkTrainingOptions): INeuralNetworkState;
}
class LSTMTimeStep extends recurrent.RNNTimeStep {}
class GRUTimeStep extends recurrent.RNNTimeStep {}
}
/* misc helper function section */
export function likely<T>(input: T, net: NeuralNetwork): any;