def __call__(self, x): x = F.relu(self.linear(x)) x = F.reshape(x, (-1,) + self.to_shape) # reshape to (-1, C, H, W) x = F.relu(self.deconv(x)) x = self.conv(x) x = F.sigmoid(x) return x
def __call__(self, x): if self.h is None: N, D = x.shape H, H = self.h2f.W.shape self.h = np.zeros((N, H), np.float32) self.c = np.zeros((N, H), np.float32) f = F.sigmoid(self.x2f(x) + self.h2f(self.h)) i = F.sigmoid(self.x2i(x) + self.h2i(self.h)) o = F.sigmoid(self.x2o(x) + self.h2o(self.h)) u = F.tanh(self.x2u(x) + self.h2u(self.h)) c = (f * self.c) + (i * u) h = o * F.tanh(c) self.h, self.c = h, c return h
def predict(x): y = F.linear(x, W1, b1) y = F.sigmoid(y) y = F.linear(y, W2, b2) #y = F.matmul(x, W1) + b1 #y = F.sigmoid_simple(y) #y = F.matmul(y, W2) + b2 return y
def test_sigmoid(self): x = Variable(np.array([[1], [2]])) y = sigmoid(x) y.backward() assert_array_equal( y.data, np.array([[1 / (1 + np.exp(-1))], [1 / (1 + np.exp(-2))]])) assert_array_equal( x.grad.data, np.array([[np.exp(-1) / (1 + np.exp(-1))**2], [np.exp(-2) / (1 + np.exp(-2))**2]]))
def forward(self, x): if self.h is None: f = F.sigmoid(self.x2f(x)) i = F.sigmoid(self.x2i(x)) o = F.sigmoid(self.x2o(x)) u = F.sigmoid(self.x2u(x)) else: f = F.sigmoid(self.x2f(x) + self.h2f(self.h)) i = F.sigmoid(self.x2i(x) + self.h2i(self.h)) o = F.sigmoid(self.x2u(x) + self.h2u(self.h)) u = F.tanh(self.x2u(x) + self.h2u(self.h)) if self.c is None: c_new = (i * u) else: c_new = (f * self.c) + (i * u) h_new = o * F.tanh(c_new) self.h, self.c = h_new, c_new return h_new
def __call__(self, x): if self.h is None: f = F.sigmoid(self.x2f(x)) i = F.sigmoid(self.x2i(x)) o = F.sigmoid(self.x2o(x)) u = F.tanh(self.x2u(x)) else: f = F.sigmoid(self.x2f(x) + self.h2f(self.h)) i = F.sigmoid(self.x2i(x) + self.h2i(self.h)) o = F.sigmoid(self.x2o(x) + self.h2o(self.h)) u = F.tanh(self.x2u(x) + self.h2u(self.h)) if self.c is None: c = (i * u) else: c = (f * self.c) + (i * u) h = o * F.tanh(c) self.h, self.c = h, c return h
def predict(x): y = l1(x) y = F.sigmoid(y) y = l2(y) return y
def test_forward1(self): x = np.array([[0, 1, 2], [0, 2, 4]], np.float32) y2 = CF.sigmoid(x) y = F.sigmoid(Variable(x)) res = np.allclose(y.data, y2.data) self.assertTrue(res)
def forward(self, x): y = F.sigmoid(self.l1(x)) y = self.l2(y) return y
def __call__(self, x): y = F.sigmoid(self.l1(x)) y = self.l2(y) return y
def test_forward2(self): x = np.random.randn(10, 10).astype(np.float32) y2 = CF.sigmoid(x) y = F.sigmoid(Variable(x)) res = np.allclose(y.data, y2.data) self.assertTrue(res)
def predict(x): y = l1.forward(x) y = F.sigmoid(y) y = l2.forward(y) return y
def predict(x): y = F.linear(x, W1, b1) y = F.sigmoid(y) y = F.linear(y, W2, b2) return y
def predict(x): x2 = F.sigmoid(F.linear(x, W1, b1)) x2 = F.linear(x2, W2, b2) return x2
def test_backward(self): out = 0.88079707 x = Variable(np.array([2.0, 2.0])) y = sigmoid(x) y.backward() assert_almost_equal(x.grad.data, [(1 - out) * out] * 2)
def test_forward(self): x = Variable(np.array([2.0, 2.0])) y = sigmoid(x) assert_almost_equal(y.data, np.array([0.88079707, 0.88079707]))
def predict(model, x): y = model.l1(x) y = F.sigmoid(y) y = model.l2(y) return y
def predict(x): y = F.matmul(x, w1) + b1 y = F.sigmoid(y) y = F.matmul(y, w2) + b2 return y