-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathoptimizers_test.ts
75 lines (70 loc) · 2.59 KB
/
optimizers_test.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
/**
* @license
* Copyright 2018 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
/**
* Unit tests for optimizers.ts.
*/
import {AdadeltaOptimizer, AdagradOptimizer, AdamaxOptimizer, AdamOptimizer, RMSPropOptimizer, SGDOptimizer} from '@tensorflow/tfjs-core';
import {getOptimizer} from './optimizers';
import {describeMathCPU} from './utils/test_utils';
describeMathCPU('getOptimizer', () => {
// TODO(nsthorat): Assert defaults by getting config from the optimizer.
it(`can instantiate SGD`, () => {
const optimizer = getOptimizer('SGD');
expect(optimizer instanceof SGDOptimizer).toBe(true);
});
it(`can instantiate sgd`, () => {
const optimizer = getOptimizer('sgd');
expect(optimizer instanceof SGDOptimizer).toBe(true);
});
it(`can instantiate Adam`, () => {
const optimizer = getOptimizer('Adam');
expect(optimizer instanceof AdamOptimizer).toBe(true);
});
it(`can instantiate adam`, () => {
const optimizer = getOptimizer('adam');
expect(optimizer instanceof AdamOptimizer).toBe(true);
});
it(`can instantiate RMSProp`, () => {
const optimizer = getOptimizer('RMSProp');
expect(optimizer instanceof RMSPropOptimizer).toBe(true);
});
it(`can instantiate rmsprop`, () => {
const optimizer = getOptimizer('rmsprop');
expect(optimizer instanceof RMSPropOptimizer).toBe(true);
});
it(`can instantiate Adagrad`, () => {
const optimizer = getOptimizer('Adagrad');
expect(optimizer instanceof AdagradOptimizer).toBe(true);
});
it(`can instantiate adagrad`, () => {
const optimizer = getOptimizer('adagrad');
expect(optimizer instanceof AdagradOptimizer).toBe(true);
});
it(`can instantiate Adadelta`, () => {
const optimizer = getOptimizer('Adadelta');
expect(optimizer instanceof AdadeltaOptimizer).toBe(true);
});
it(`can instantiate adadelta`, () => {
const optimizer = getOptimizer('adadelta');
expect(optimizer instanceof AdadeltaOptimizer).toBe(true);
});
it(`can instantiate Adamax`, () => {
const optimizer = getOptimizer('Adamax');
expect(optimizer instanceof AdamaxOptimizer).toBe(true);
});
it(`can instantiate adamax`, () => {
const optimizer = getOptimizer('adamax');
expect(optimizer instanceof AdamaxOptimizer).toBe(true);
});
it('throws for non-existent optimizer', () => {
expect(() => getOptimizer('not an optimizer'))
.toThrowError(/Unknown Optimizer/);
});
});