示例#1
0
 def fprop(self):
     if self.phase == "train":
         ca.less(self.dropout, ca.random.uniform(size=self.mask_shape), self._tmp_mask)
         ca.multiply(self.x.out, self._tmp_mask, self.out)
     elif self.phase == "test":
         ca.multiply(self.x.out, 1.0 - self.dropout, self.out)
     else:
         raise ValueError("Invalid phase: %s" % self.phase)
示例#2
0
 def fprop(self):
     if self.phase == 'train':
         ca.less(self.dropout, ca.random.uniform(size=self.mask_shape),
                 self._tmp_mask)
         ca.multiply(self.x.array, self._tmp_mask, self.array)
     elif self.phase == 'test':
         ca.multiply(self.x.array, 1.0-self.dropout, self.array)
     else:
         raise ValueError('Invalid phase: %s' % self.phase)
示例#3
0
文件: dropout.py 项目: obinsc/deeppy
 def fprop(self):
     if self.phase == 'train':
         ca.less(self.dropout, ca.random.uniform(size=self.mask_shape),
                 self._tmp_mask)
         ca.multiply(self.x.out, self._tmp_mask, self.out)
     elif self.phase == 'test':
         ca.multiply(self.x.out, 1.0 - self.dropout, self.out)
     else:
         raise ValueError('Invalid phase: %s' % self.phase)
示例#4
0
def test_binary_cmp():
    a_np = np.random.normal(size=(5, 5))
    b_np = np.random.normal(size=(5, 5))
    a_ca = ca.array(a_np)
    b_ca = ca.array(b_np)

    c_np = np.greater(a_np, b_np)
    c_ca = ca.greater(a_ca, b_ca)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = np.greater(a_np, 0.1)
    c_ca = ca.greater(a_ca, 0.1)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = np.less(a_np, 0.1)
    c_ca = ca.less(a_ca, 0.1)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = 0.1 < a_np
    c_ca = 0.1 < a_ca
    print(np.allclose(c_np, np.array(c_ca)))
示例#5
0
文件: test.py 项目: rufrozen/cudarray
def test_binary_cmp():
    a_np = np.random.normal(size=(5, 5))
    b_np = np.random.normal(size=(5, 5))
    a_ca = ca.array(a_np)
    b_ca = ca.array(b_np)

    c_np = np.greater(a_np, b_np)
    c_ca = ca.greater(a_ca, b_ca)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = np.greater(a_np, 0.1)
    c_ca = ca.greater(a_ca, 0.1)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = np.less(a_np, 0.1)
    c_ca = ca.less(a_ca, 0.1)
    print(np.allclose(c_np, np.array(c_ca)))

    c_np = 0.1 < a_np
    c_ca = 0.1 < a_ca
    print(np.allclose(c_np, np.array(c_ca)))
示例#6
0
 def bprop(self):
     self.x.out_grad = ca.less(self.x.out, 0) * self.a
     pos = ca.nnet.relu_d(self.x.out)
     self.x.out_grad += pos
     self.x.out_grad *= self.out_grad
示例#7
0
 def bprop(self):
     self.x.grad_array = ca.less(self.x.array, 0) * self.a
     pos = ca.nnet.relu_d(self.x.array)
     self.x.grad_array += pos
     self.x.grad_array *= self.grad_array