-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathgenerateTestCases.py
125 lines (107 loc) · 3.3 KB
/
generateTestCases.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
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
# New Generate Test Cases
from solutions import *
import numpy as np
import math
import os,sys
# import tensorflow as tf
sys.path.append('../')
sys.path.append('../../')
from grader_support import stdout_redirector
from grader_support import util
mFiles = [
"rnn_cell_forward.py",
"rnn_forward.py",
"lstm_cell_forward.py",
"lstm_forward.py"
]
# generating test cases for rnn_cell_forward
xt = np.random.randn(3,6)
a_prev = np.random.randn(4,6)
Waa = np.random.randn(4,4)
Wax = np.random.randn(4,3)
Wya = np.random.randn(2,4)
ba = np.random.randn(4,1)
by = np.random.randn(2,1)
parameters = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}
a_next, yt_pred, cache = rnn_cell_forward(xt, a_prev, parameters)
# -------------------------------------------------------
# generating test cases for rnn_forward
x1 = np.random.randn(3,6,4)
a01 = np.random.randn(4,6)
parameters1 = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}
a, y_pred, caches = rnn_forward(x1, a01, parameters1)
# -------------------------------------------------------
# generate test cases for lstm_cell_forward
xt1 = np.random.randn(3,4)
a_prev1 = np.random.randn(5,4)
c_prev1 = np.random.randn(5,4)
Wf = np.random.randn(5, 5+3)
bf = np.random.randn(5,1)
Wi = np.random.randn(5, 5+3)
bi = np.random.randn(5,1)
Wo = np.random.randn(5, 5+3)
bo = np.random.randn(5,1)
Wc = np.random.randn(5, 5+3)
bc = np.random.randn(5,1)
Wy = np.random.randn(2,5)
by = np.random.randn(2,1)
parameters2 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}
a_next_lstm, c_next_lstm, yt_lstm, cache_lstm = lstm_cell_forward(xt1, a_prev1, c_prev1, parameters2)
# -------------------------------------------------------
# generate test cases for lstm_cell_forward
# lstm_forward
np.random.seed(1)
x2 = np.random.randn(3,10,4)
a02 = np.random.randn(5,10)
Wf = np.random.randn(5, 5+3)
bf = np.random.randn(5,1)
Wi = np.random.randn(5, 5+3)
bi = np.random.randn(5,1)
Wo = np.random.randn(5, 5+3)
bo = np.random.randn(5,1)
Wc = np.random.randn(5, 5+3)
bc = np.random.randn(5,1)
Wy = np.random.randn(2,5)
by = np.random.randn(2,1)
parameters3 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}
af, yf, cf, cachesf = lstm_forward(x2, a02, parameters3)
def generateTestCases():
testCases = {
'rnn_cell_forward': {
'partId': 'KrqbT',
'testCases': [
{
'testInput': (xt, a_prev, parameters),
'testOutput': (a_next, yt_pred, cache)
}
]
},
'rnn_forward': {
'partId': 'CzGAI',
'testCases': [
{
'testInput': (x1, a01, parameters1),
'testOutput': (a, y_pred, caches)
}
]
},
'lstm_cell_forward': {
'partId': '7tvdt',
'testCases': [
{
'testInput': (xt1, a_prev1, c_prev1, parameters2),
'testOutput': (a_next_lstm, c_next_lstm, yt_lstm, cache_lstm)
}
]
},
'lstm_forward': {
'partId': 'SAQvR',
'testCases': [
{
'testInput': (x2, a02, parameters3),
'testOutput': (af, yf, cf, cachesf)
}
]
}
}
return testCases