Last active
November 8, 2018 15:31
-
-
Save darden1/45b717b30f594ad49ca301444cd98594 to your computer and use it in GitHub Desktop.
my_time_series_dense.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeSeriesDense(Dense): | |
def forward_prop(self, Phi): | |
"""順伝播演算""" | |
n_samples, T = Phi.shape[0], Phi.shape[1] | |
Z = np.zeros([n_samples, T, self.units]) | |
for t in range(T): | |
Z[:,t,:] = np.dot(Phi[:,t,:], self.W) + self.b | |
return Z | |
def back_prop(self, Phi, Delta): | |
"""逆伝播演算""" | |
n_samples, T = Delta.shape[0], Delta.shape[1] # サンプル数で割って1サンプル当たりの平均値にする | |
self.dW = np.zeros(self.W.shape) | |
self.db = np.zeros(self.b.shape) | |
dPhi = np.zeros(Phi.shape) | |
for t in range(T): | |
self.dW += np.dot(Phi[:,t,:].T, Delta[:,t,:])/n_samples | |
self.db += np.dot(np.ones([1, n_samples]), Delta[:,t,:])/n_samples | |
dPhi[:,t,:] = np.dot(Delta[:,t,:], self.W.T) | |
return dPhi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment