@@ -15,35 +15,24 @@ Compute the symbolic output of `nn` and differentiate it with respect to the par
15
15
16
16
# Examples
17
17
18
- ```jldoctest
18
+ ```julia
19
19
using SymbolicNeuralNetworks: SymbolicNeuralNetwork, Gradient, derivative
20
20
using AbstractNeuralNetworks
21
21
using Latexify: latexify
22
22
23
23
c = Chain(Dense(2, 1, tanh))
24
24
nn = SymbolicNeuralNetwork(c)
25
- (Gradient(nn) |> derivative)[1].L1.b |> latexify
26
-
27
- # output
28
-
29
- L"\b egin{equation}
30
- \l eft[
31
- \b egin{array}{c}
32
- 1 - \t anh^{2}\l eft( \m athtt{b\_ 1}_{1} + \m athtt{W\_ 1}_{1,1} \m athtt{sinput}_{1} + \m athtt{W\_ 1}_{1,2} \m athtt{sinput}_{2} \r ight) \\
33
- \e nd{array}
34
- \r ight]
35
- \e nd{equation}
36
- "
25
+ (Gradient(nn) |> derivative)[1].L1.b
37
26
```
38
27
39
28
# Implementation
40
29
41
30
Internally the constructors are using [`symbolic_pullback`](@ref).
42
31
"""
43
- struct Gradient{ST, OT, SDT} <: Derivative{ST, OT, SDT}
44
- nn:: ST
32
+ struct Gradient{OT, SDT, ST} <: Derivative{OT, SDT, ST}
45
33
output:: OT
46
34
∇:: SDT
35
+ nn:: ST
47
36
end
48
37
49
38
"""
@@ -71,7 +60,7 @@ derivative(g::Gradient) = g.∇
71
60
72
61
function Gradient (output:: EqT , nn:: SymbolicNeuralNetwork )
73
62
typeof (output) <: AbstractArray ? nothing : (@warn " You should only use `Gradient` together with array expressions! Maybe you wanted to use `SymbolicPullback`." )
74
- Gradient (nn, output, symbolic_pullback (output, nn))
63
+ Gradient (output, symbolic_pullback (output, nn), nn )
75
64
end
76
65
77
66
function Gradient (nn:: SymbolicNeuralNetwork )
@@ -87,7 +76,7 @@ This is used by [`Gradient`](@ref) and [`SymbolicPullback`](@ref).
87
76
88
77
# Examples
89
78
90
- ```jldoctest
79
+ ```julia
91
80
using SymbolicNeuralNetworks: SymbolicNeuralNetwork, symbolic_pullback
92
81
using AbstractNeuralNetworks
93
82
using LinearAlgebra: norm
@@ -98,18 +87,7 @@ nn = SymbolicNeuralNetwork(c)
98
87
output = c(nn.input, nn.params)
99
88
spb = symbolic_pullback(output, nn)
100
89
101
- spb[1].L1.b |> latexify
102
-
103
- # output
104
-
105
- L"\b egin{equation}
106
- \l eft[
107
- \b egin{array}{c}
108
- 1 - \t anh^{2}\l eft( \m athtt{b\_ 1}_{1} + \m athtt{W\_ 1}_{1,1} \m athtt{sinput}_{1} + \m athtt{W\_ 1}_{1,2} \m athtt{sinput}_{2} \r ight) \\
109
- \e nd{array}
110
- \r ight]
111
- \e nd{equation}
112
- "
90
+ spb[1].L1.b
113
91
```
114
92
"""
115
93
function symbolic_pullback (soutput:: EqT , nn:: AbstractSymbolicNeuralNetwork ):: Union{AbstractArray{<:Union{NamedTuple, NeuralNetworkParameters}}, Union{NamedTuple, NeuralNetworkParameters}}
0 commit comments