Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testing.md « doc - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 424c492e174295a70872ef0c5d41cbed5878e00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Testing #
For those who want to implement their own modules, we suggest using
the `nn.Jacobian` class for testing the derivatives of their class,
together with the [torch.Tester](https://github.com/torch/torch7/blob/master/doc/tester.md) class. The sources
of `nn` package contains sufficiently many examples of such tests.


## nn.Jacobian ##


<a name="nn.Jacobian.testJacobian"></a>
### testJacobian(module, input, minval, maxval, perturbation) ###

Test the jacobian of a module w.r.t. to its input. 

`module` takes as its input a random tensor shaped the same as `input`.  
`minval` and `maxval` specify the range of the random tensor ([-2, 2] by default).  
`perturbation` is used as finite difference (1e-6 by default).

Returns the L-inf distance between the jacobian computed by backpropagation and by finite difference.


<a name="nn.Jacobian.testJacobianParameters"></a>
### testJacobianParameters(module, input, param, dparam, minval, maxval, perturbation) ###

Test the jacobian of a module w.r.t. its parameters (instead of its input).

The input and parameters of `module` are random tensors shaped the same as `input` and `param`.  
`minval` and `maxval` specify the range of the random tensors ([-2, 2] by default).  
`dparam` points to the gradient w.r.t. parameters.  
`perturbation` is used as finite difference (1e-6 by default).

Returns the L-inf distance between the jacobian computed by backpropagation and by finite difference.


<a name="nn.Jacobian.testJacobianUpdateParameters"></a>
### testJacobianUpdateParameters(module, input, param, minval, maxval, perturbation) ###

Test the amount of update of a module to its parameters.

The input and parameters of `module` are random tensors shaped the same as `input` and `param`.  
`minval` and `maxval` specify the range of the random tensors ([-2, 2] by default).  
`perturbation` is used as finite difference (1e-6 by default).

Returns the L-inf distance between the update computed by backpropagation and by finite difference.


<a name="nn.Jacobian.forward"></a>
### forward(module, input, param, perturbation) ###

Compute the jacobian by finite difference.

`module` has parameters `param` and input `input`.  
If provided, `param` is regarded as independent variables, otherwise `input` is the independent variables.  
`perturbation` is used as finite difference (1e-6 by default).

Returns the jacobian computed by finite difference.


<a name="nn.Jacobian.backward"></a>
### backward(module, input, param, dparam) ###

Compute the jacobian by backpropagation.

`module` has parameters `param` and input `input`.  
If provided, `param` is regarded as independent variables, otherwise `input` is the independent variables.  
`dparam` is the gradient w.r.t. parameters, it must present as long as `param` is present.  

Returns the jacobian computed by backpropagation.