def test_mult_by_sigmoid_deriv(): m = 256 n = 128 c_targets = np.array(np.random.randn(m, n)*10, dtype=np.float32, order='F') c_acts = np.array(np.random.rand(m, n), dtype=np.float32, order='F') g_targets = cm.CUDAMatrix(c_targets) g_acts = cm.CUDAMatrix(c_acts) c_targets = c_targets * c_acts * (1. - c_acts) cl.mult_by_sigmoid_deriv(g_targets, g_acts) assert np.max(np.abs(c_acts - g_acts.asarray())) < 10**-2, "Error in cudamat.learn.mult_by_sigmoid_deriv exceeded threshold"
def test_mult_by_sigmoid_deriv(): m = 256 n = 128 c_targets = np.array(np.random.randn(m, n) * 10, dtype=np.float32, order='F') c_acts = np.array(np.random.rand(m, n), dtype=np.float32, order='F') g_targets = cm.CUDAMatrix(c_targets) g_acts = cm.CUDAMatrix(c_acts) c_targets = c_targets * c_acts * (1. - c_acts) cl.mult_by_sigmoid_deriv(g_targets, g_acts) assert np.max( np.abs(c_acts - g_acts.asarray()) ) < 10**-2, "Error in cudamat.learn.mult_by_sigmoid_deriv exceeded threshold"
def backProp(self, error): # print 'back propagation' self.dW[self.H-1].add_dot(self.vis[self.H-1],error.T) # print 'self.vis' # self.vis[self.H-1].copy_to_host() # print self.vis[self.H-1].numpy_array # print 'self.dW' # self.dW[self.H-1].copy_to_host() # print self.dW[self.H-1].numpy_array # print 'error 2' # error.copy_to_host() # print error.numpy_array self.db[self.H-1].add_sums(error,axis =1 ) for i in list(reversed(range(self.H-1))): delta = cm.empty((self.W[i+1].shape[0],error.shape[1])) cm.dot(self.W[i+1],error,target = delta)# delta : 2000*256 learn.mult_by_sigmoid_deriv(delta, self.vis[i+1]) self.dW[i].add_dot(self.vis[i], delta.T) self.db[i].add_sums(delta, axis = 1) error = delta