module
= Mul(inputDimension)
Applies a single scaling factor to the incoming data, i.e. y= w x, where w is a scalar.
Example:
y=torch.Tensor(5); mlp=nn.Sequential() mlp:add(nn.Mul(5)) function gradUpdate(mlp, x, y, criterion, learningRate) local pred = mlp:forward(x) local err = criterion:forward(pred,y) local gradCriterion = criterion:backward(pred,y); mlp:zeroGradParameters(); mlp:backward(x, gradCriterion); mlp:updateParameters(learningRate); return err end for i=1,10000 do x=lab.rand(5) y:copy(x); y:mul(math.pi); err=gradUpdate(mlp,x,y,nn.MSECriterion(),0.01) end print(mlp:get(1).weight)gives the output:
3.1416 [torch.Tensor of dimension 1]i.e. the network successfully learns the input
x
has been scaled by
pi.