1
1
"""
2
2
NeuralSplineCoupling(dim, hdims, K, B, mask_idx, paramtype)
3
- NeuralSplineCoupling(dim, K, n_dims_transferred , B, nn, mask)
3
+ NeuralSplineCoupling(dim, K, n_dims_transformed , B, nn, mask)
4
4
5
5
Neural Rational Quadratic Spline (RQS) coupling bijector [^DBMP2019].
6
6
@@ -19,7 +19,7 @@ Keyword Arguments
19
19
- `paramtype::Type{<:AbstractFloat}`: parameter element type.
20
20
21
21
Fields
22
- - `nn::Flux.Chain`: conditioner that outputs all spline params for all transformed dims .
22
+ - `nn::Flux.Chain`: conditioner that outputs all spline params for all transformed dim .
23
23
- `mask::Bijectors.PartitionMask`: partition specification.
24
24
25
25
Notes
@@ -35,9 +35,9 @@ and log-determinant computations.
35
35
struct NeuralSplineCoupling{T,A<: Flux.Chain } <: Bijectors.Bijector
36
36
dim:: Int # dimension of input
37
37
K:: Int # number of knots
38
- n_dims_transferred :: Int # number of dimensions that are transformed
38
+ n_dims_transformed :: Int # number of dimensions that are transformed
39
39
B:: T # bound of the knots
40
- nn:: A # networks that parmaterize the knots and derivatives
40
+ nn:: A # networks that parameterize the knots and derivatives
41
41
mask:: Bijectors.PartitionMask
42
42
end
43
43
@@ -46,13 +46,12 @@ function NeuralSplineCoupling(
46
46
hdims:: AbstractVector{T1} , # dimension of hidden units for s and t
47
47
K:: T1 , # number of knots
48
48
B:: T2 , # bound of the knots
49
- mask_idx:: AbstractVector{T1} , # index of dimensione that one wants to apply transformations on
49
+ mask_idx:: AbstractVector{T1} , # indices of the transformed dimensions
50
50
paramtype:: Type{T2} , # type of the parameters, e.g., Float64 or Float32
51
51
) where {T1<: Int ,T2<: AbstractFloat }
52
52
num_of_transformed_dims = length (mask_idx)
53
53
input_dims = dim - num_of_transformed_dims
54
54
55
- # output dim of the NN
56
55
output_dims = (3 K - 1 )* num_of_transformed_dims
57
56
# one big mlp that outputs all the knots and derivatives for all the transformed dimensions
58
57
nn = fnn (input_dims, hdims, output_dims; output_activation= nothing , paramtype= paramtype)
66
65
function get_nsc_params (nsc:: NeuralSplineCoupling , x:: AbstractVecOrMat )
67
66
nnoutput = nsc. nn (x)
68
67
px, py, dydx = MonotonicSplines. rqs_params_from_nn (
69
- nnoutput, nsc. n_dims_transferred , nsc. B
68
+ nnoutput, nsc. n_dims_transformed , nsc. B
70
69
)
71
70
return px, py, dydx
72
71
end
@@ -146,13 +145,13 @@ end
146
145
147
146
148
147
"""
149
- NSF_layer(dims , hdims, K, B; paramtype = Float64)
148
+ NSF_layer(dim , hdims, K, B; paramtype = Float64)
150
149
151
150
Build a single Neural Spline Flow (NSF) layer by composing two
152
151
`NeuralSplineCoupling` bijectors with complementary odd–even masks.
153
152
154
153
Arguments
155
- - `dims ::Int`: dimensionality of the problem.
154
+ - `dim ::Int`: dimensionality of the problem.
156
155
- `hdims::AbstractVector{Int}`: hidden sizes of the conditioner network.
157
156
- `K::Int`: number of spline knots.
158
157
- `B::AbstractFloat`: spline boundary.
@@ -168,19 +167,19 @@ Example
168
167
- `y = layer(randn(4, 32))`
169
168
"""
170
169
function NSF_layer (
171
- dims :: T1 , # dimension of problem
170
+ dim :: T1 , # dimension of problem
172
171
hdims:: AbstractVector{T1} , # dimension of hidden units for nn
173
172
K:: T1 , # number of knots
174
173
B:: T2 ; # bound of the knots
175
174
paramtype:: Type{T2} = Float64, # type of the parameters
176
175
) where {T1<: Int ,T2<: AbstractFloat }
177
176
178
- mask_idx1 = 1 : 2 : dims
179
- mask_idx2 = 2 : 2 : dims
177
+ mask_idx1 = 1 : 2 : dim
178
+ mask_idx2 = 2 : 2 : dim
180
179
181
180
# by default use the odd-even masking strategy
182
- nsf1 = NeuralSplineCoupling (dims , hdims, K, B, mask_idx1, paramtype)
183
- nsf2 = NeuralSplineCoupling (dims , hdims, K, B, mask_idx2, paramtype)
181
+ nsf1 = NeuralSplineCoupling (dim , hdims, K, B, mask_idx1, paramtype)
182
+ nsf2 = NeuralSplineCoupling (dim , hdims, K, B, mask_idx2, paramtype)
184
183
return reduce (∘ , (nsf1, nsf2))
185
184
end
186
185
@@ -205,11 +204,11 @@ Keyword Arguments
205
204
Returns
206
205
- `Bijectors.TransformedDistribution` representing the NSF flow.
207
206
208
- Notes:
209
- - Under the hood, `nsf` relies on the rational quadratic spline function implememented in
210
- `MonotonicSplines.jl` for performance reasons. `MonotonicSplines.jl` uses
211
- `KernelAbstractions.jl` to support batched operations.
212
- Because of this, so far `nsf` only supports `Zygote` as the AD type.
207
+ !!! note
208
+ Under the hood, `nsf` relies on the rational quadratic spline function implememented in
209
+ `MonotonicSplines.jl` for performance reasons. `MonotonicSplines.jl` uses
210
+ `KernelAbstractions.jl` to support batched operations.
211
+ Because of this, so far `nsf` only supports `Zygote` as the AD type.
213
212
214
213
215
214
Example
@@ -225,8 +224,8 @@ function nsf(
225
224
paramtype:: Type{T} = Float64, # type of the parameters
226
225
) where {T<: AbstractFloat }
227
226
228
- dims = length (q0) # dimension of the reference distribution == dim of the problem
229
- Ls = [NSF_layer (dims , hdims, K, B; paramtype= paramtype) for _ in 1 : nlayers]
227
+ dim = length (q0) # dimension of the reference distribution == dim of the problem
228
+ Ls = [NSF_layer (dim , hdims, K, B; paramtype= paramtype) for _ in 1 : nlayers]
230
229
create_flow (Ls, q0)
231
230
end
232
231
0 commit comments