require 'torch'
require 'nn'
+
+-- require 'cunn'
+
require 'dagnn'
torch.setdefaulttensortype('torch.DoubleTensor')
local num = (loss1 - loss0) / (2 * epsilon)
if num ~= ana then
- err = math.max(err, math.abs(num - ana) / math.abs(num))
+ err = math.max(err, math.abs(num - ana) / math.max(epsilon, math.abs(num)))
end
end
criterion = nn.MSECriterion()
--- model:cuda()
--- criterion:cuda()
--- torch.setdefaulttensortype('torch.CudaTensor')
--- epsilon = 1e-4
+if cunn then
+ print("Using CUDA")
+ model:cuda()
+ criterion:cuda()
+ torch.setdefaulttensortype('torch.CudaTensor')
+ epsilon = 1e-3
+end
local input = torch.Tensor(30, 50):uniform()
local output = model:updateOutput(input):clone()