/
reparameterizations.jl
66 lines (51 loc) · 1.93 KB
/
reparameterizations.jl
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
#===============================================================================
Cloning
This is quite inefficient, but has a nice syntax
===============================================================================#
"""
clone(P::T, θ::AbstractDict) where T <: DiffusionProcess
Simplified cloning of diffusion law `P`. Substitute relevant parameters with
new values. `θ` must be a dict corresponding to parameters returned after a call
to `var_parameters`.
"""
function clone(P::T, θ::AbstractDict) where T <: DiffusionProcess
cp = const_parameters(P)
remove_curly(T)(;cp..., θ...)
end
#===============================================================================
in-place parameter setting
Efficient way of re-parameterizing the diffusion law
===============================================================================#
"""
set_parameters!(P::DiffusionProcess, θ, entries)
Set parameters of a diffusion law `P` in-place. `entries` should be a collection
of pairs Pair{Int64,Symbol} that list the relevant entries in `θ` for
reparameterization, together with the corresponding parameter names.
"""
function set_parameters!(P::DiffusionProcess, θ, entries)
for (i,s) in entries
setfield!(P, s, θ[i])
end
end
function set_parameters!(P::DiffusionProcess, P°::DiffusionProcess, entries)
for e in entries
setfield!(P°, e, getfield(P, e))
end
end
function set_parameters!(P::T, θ::Dict) where T <: DiffusionProcess
for k in keys(θ)
hasfield(T, k) && setfield!(P, k, θ[k])
end
end
function same_entries(P::DiffusionProcess, P°::DiffusionProcess, entries)
for e in entries
getfield(P, e) == getfield(P°, e) || return false
end
true
end
function has_any(P::T, entries) where T <: DiffusionProcess
for (i,s) in entries
hasfield(T, s) && return true
end
false
end