MCPcopy Create free account
hub / github.com/apache/singa / forward

Method forward

python/singa/autograd.py:1165–1182  ·  view source on GitHub ↗

Args: x (CTensor): 1d or 2d tensor, the prediction data(output) of current network. t (CTensor): 1d or 2d tensor, the target data for training. Returns: loss (CTensor): scalar.

(self, x)

Source from the content-addressed store, hash-verified

1163 """
1164
1165 def forward(self, x):
1166 """
1167 Args:
1168 x (CTensor): 1d or 2d tensor, the prediction data(output)
1169 of current network.
1170 t (CTensor): 1d or 2d tensor, the target data for training.
1171 Returns:
1172 loss (CTensor): scalar.
1173 """
1174 posx = singa.AddFloat(x, 0.0001)
1175 loss = singa.SumAll(singa.__mul__(self.t, singa.Log(posx)))
1176 negt = singa.AddFloat(singa.MultFloat(self.t, -1.0), 1.0)
1177 negx = singa.AddFloat(singa.MultFloat(x, -1.0), 1.0001)
1178 negLoss = singa.SumAll(singa.__mul__(negt, singa.Log(negx)))
1179 loss += negLoss
1180 loss /= -x.shape()[0]
1181 self.x = singa.AddFloat(x, 0.0001)
1182 return loss
1183
1184 def backward(self, dy=1.0):
1185 """

Callers

nothing calls this directly

Calls 2

shapeMethod · 0.80
__mul__Method · 0.45

Tested by

no test coverage detected