-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
329 lines (280 loc) · 9.96 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
declare namespace brain {
/* NeuralNetwork section */
interface INeuralNetworkOptions {
/**
* @default 0.5
*/
binaryThresh?: number;
/**
* array of int for the sizes of the hidden layers in the network
*
* @default [3]
*/
hiddenLayers?: number[];
/**
* supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
*
* @default 'sigmoid'
*/
activation?: NeuralNetworkActivation;
/**
* supported for activation type 'leaky-relu'
*
* @default 0.01
*/
leakyReluAlpha?: number;
}
type NeuralNetworkActivation = 'sigmoid' | 'relu' | 'leaky-relu' | 'tanh';
interface INeuralNetworkTrainingOptions {
/**
* the maximum times to iterate the training data --> number greater than 0
* @default 20000
*/
iterations?: number;
/**
* the acceptable error percentage from training data --> number between 0 and 1
* @default 0.005
*/
errorThresh?: number;
/**
* true to use console.log, when a function is supplied it is used --> Either true or a function
* @default false
*/
log?: boolean | INeuralNetworkTrainingCallback;
/**
* iterations between logging out --> number greater than 0
* @default 10
*/
logPeriod?: number;
/**
* scales with delta to effect training rate --> number between 0 and 1
* @default 0.3
*/
learningRate?: number;
/**
* scales with next layer's change value --> number between 0 and 1
* @default 0.1
*/
momentum?: number;
/**
* a periodic call back that can be triggered while training --> null or function
* @default null
*/
callback?: INeuralNetworkTrainingCallback | number;
/**
* the number of iterations through the training data between callback calls --> number greater than 0
* @default 10
*/
callbackPeriod?: number;
/**
* the max number of milliseconds to train for --> number greater than 0
* @default Infinity
*/
timeout?: number;
praxis?: null | 'adam'
}
interface INeuralNetworkTrainingCallback {
(state: INeuralNetworkState): void;
}
interface INeuralNetworkState {
iterations: number;
error: number;
}
interface INeuralNetworkJSON {
sizes: number[];
layers: object[];
outputLookup: any;
inputLookup: any;
activation: NeuralNetworkActivation,
trainOpts: INeuralNetworkTrainingOptions,
leakyReluAlpha?: number,
}
interface INeuralNetworkTrainingData {
input: NeuralNetworkInput;
output: NeuralNetworkOutput;
}
type NeuralNetworkInput = number[];
type NeuralNetworkOutput = number[];
interface INeuralNetworkTestResult {
misclasses: any;
error: number;
total: number;
}
interface INeuralNetworkBinaryTestResult extends INeuralNetworkTestResult {
trueNeg: number;
truePos: number;
falseNeg: number;
falsePos: number;
precision: number;
recall: number;
accuracy: number;
}
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;
}
class NeuralNetworkGPU extends NeuralNetwork { }
/* CrossValidate section */
interface ICrossValidateJSON {
avgs: ICrossValidationTestPartitionResults;
stats: ICrossValidateStats;
sets: ICrossValidationTestPartitionResults[];
}
interface ICrossValidateStats {
truePos: number;
trueNeg: number;
falsePos: number;
falseNeg: number;
total: number;
}
interface ICrossValidationTestPartitionResults {
trainTime: number;
testTime: number;
iterations: number;
trainError: number;
learningRate: number;
hidden: number[];
network: NeuralNetwork;
}
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 */
interface ITrainStreamOptions {
neuralNetwork: NeuralNetwork,
neuralNetworkGPU: NeuralNetworkGPU,
floodCallback: () => void,
doneTrainingCallback: (state: INeuralNetworkState) => void
}
class TrainStream {
public constructor(options: ITrainStreamOptions)
write(data: INeuralNetworkTrainingData): void;
write<T>(data: T): void;
endInputs(): void;
}
/* recurrent section */
type RNNTrainingValue = string;
interface IRNNTrainingData {
input: RNNTrainingValue,
output: RNNTrainingValue
}
interface IRNNDefaultOptions extends INeuralNetworkOptions {
decayRate?: number;
inputRange?: number;
inputSize?: number;
learningRate?: number;
outputSize?: number;
}
/* recurrent time step section */
type RNNTimeStepInput = number[] | number[][] | object | object[] | object[][];
type IRNNTimeStepTrainingDatum =
IRNNTimeStepTrainingNumbers
| IRNNTimeStepTrainingNumbers2D
| IRNNTimeStepTrainingObject
| IRNNTimeStepTrainingObjects
| IRNNTimeStepTrainingObject2D
| number[]
| number[][]
| object[]
| object[][];
interface IRNNTimeStepTrainingNumbers {
input: number[],
output: number[]
}
interface IRNNTimeStepTrainingNumbers2D {
input: number[][],
output: number[][]
}
interface IRNNTimeStepTrainingObject {
input: object,
output: object
}
interface IRNNTimeStepTrainingObjects {
input: object[],
output: object[]
}
interface IRNNTimeStepTrainingObject2D {
input: object[][],
output: object[][]
}
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 */
function likely<T>(input: T, net: NeuralNetwork): any;
class FeedForward {
constructor(options?: IFeedForwardOptions);
}
interface IFeedForwardOptions {
learningRate?: number;
binaryThresh?: number;
hiddenLayers?: any;
inputLayer?: any;
outputLayer?: any;
praxisOpts?: object;
praxis?: any;
}
class Layer { }
class Activation extends Layer { }
class Model extends Layer { }
class Input extends Model { }
class Filter { }
class Target extends Filter { }
class Sigmoid extends Activation { }
class Relu extends Activation { }
class Tanh extends Activation { }
class LeakyRelu extends Activation { }
type layer = {
input: (settings) => Input;
feedForward: (settings, inputLayer) => Sigmoid;
arthurFeedForward: (settings, inputLayer) => Sigmoid;
target: (settings, inputLayer) => Target;
sigmoid: (settings, inputLayer) => Sigmoid;
relu: (settings, inputLayer) => Relu;
tanh: (settings, inputLayer) => Tanh;
leakyRely: (Settings, inputLayer) => LeakyRelu;
};
}