73
73
"""
74
74
ParamsInit(
75
75
params::Union{AbstractDict{<:VarName},NamedTuple},
76
- default ::Union{AbstractInitStrategy,Nothing}=PriorInit()
76
+ fallback ::Union{AbstractInitStrategy,Nothing}=PriorInit()
77
77
)
78
78
79
79
Obtain new values by extracting them from the given dictionary or NamedTuple.
80
80
81
- The parameter `default ` specifies how new values are to be obtained if they
82
- cannot be found in `params`, or they are specified as `missing`. `default `
81
+ The parameter `fallback ` specifies how new values are to be obtained if they
82
+ cannot be found in `params`, or they are specified as `missing`. `fallback `
83
83
can either be an initialisation strategy itself, in which case it will be
84
84
used to obtain new values, or it can be `nothing`, in which case an error
85
- will be thrown. The default for `default ` is `PriorInit()`.
85
+ will be thrown. The default for `fallback ` is `PriorInit()`.
86
86
87
87
!!! note
88
88
The values in `params` must be provided in the space of the untransformed
89
89
distribution.
90
90
"""
91
91
struct ParamsInit{P,S<: Union{AbstractInitStrategy,Nothing} } <: AbstractInitStrategy
92
92
params:: P
93
- default :: S
93
+ fallback :: S
94
94
function ParamsInit (
95
- params:: AbstractDict{<:VarName} , default :: Union{AbstractInitStrategy,Nothing}
95
+ params:: AbstractDict{<:VarName} , fallback :: Union{AbstractInitStrategy,Nothing}
96
96
)
97
- return new {typeof(params),typeof(default )} (params, default )
97
+ return new {typeof(params),typeof(fallback )} (params, fallback )
98
98
end
99
99
ParamsInit (params:: AbstractDict{<:VarName} ) = ParamsInit (params, PriorInit ())
100
100
function ParamsInit (
101
- params:: NamedTuple , default :: Union{AbstractInitStrategy,Nothing} = PriorInit ()
101
+ params:: NamedTuple , fallback :: Union{AbstractInitStrategy,Nothing} = PriorInit ()
102
102
)
103
- return ParamsInit (to_varname_dict (params), default )
103
+ return ParamsInit (to_varname_dict (params), fallback )
104
104
end
105
105
end
106
106
function init (rng:: Random.AbstractRNG , vn:: VarName , dist:: Distribution , p:: ParamsInit )
@@ -111,17 +111,17 @@ function init(rng::Random.AbstractRNG, vn::VarName, dist::Distribution, p::Param
111
111
return if hasvalue (p. params, vn, dist)
112
112
x = getvalue (p. params, vn, dist)
113
113
if x === missing
114
- p. default === nothing &&
114
+ p. fallback === nothing &&
115
115
error (" A `missing` value was provided for the variable `$(vn) `." )
116
- init (rng, vn, dist, p. default )
116
+ init (rng, vn, dist, p. fallback )
117
117
else
118
118
# TODO (penelopeysm): Since x is user-supplied, maybe we could also
119
119
# check here that the type / size of x matches the dist?
120
120
x
121
121
end
122
122
else
123
- p. default === nothing && error (" No value was provided for the variable `$(vn) `." )
124
- init (rng, vn, dist, p. default )
123
+ p. fallback === nothing && error (" No value was provided for the variable `$(vn) `." )
124
+ init (rng, vn, dist, p. fallback )
125
125
end
126
126
end
127
127
0 commit comments