-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDNTest.py
52 lines (36 loc) · 1.1 KB
/
DNTest.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 18 15:32:58 2019
@author: rohrdr
"""
import numpy as np
import DenseNetworks as dn
import ActivationFunctions as af
import CostFunctions as cf
from Tools import eval_err
def test_suite():
np.random.seed(1)
layers = list()
firstlayer = list()
firstlayer.append(4)
firstlayer.append(3)
firstlayer.append(af.ReLU())
secondlayer = list()
secondlayer.append(3)
secondlayer.append(1)
secondlayer.append(af.Sigmoid())
layers.append(firstlayer)
layers.append(secondlayer)
my_dn = dn.DenseNN(layers, cf.CrossEntropy())
x = np.random.randn(4, 2)
y = np.array([1.0, 0.0]).reshape(1, 2)
loss = my_dn.get_loss(x, y)
my_dn.train_dn(x, y, maxiter=1000, print_frequency=10000, print_flag=False)
y_target = np.array([[0.98678318, 0.16073323]])
yhat = my_dn.forward_propagation(x)
res = eval_err(y_target, yhat, errmsg='error in train_dn')
if res: print('All tests on Dense Networks ran successfully')
return res
if __name__ == '__main__':
test_suite()