|
1 | 1 | ### Mutable states |
| 2 | +""" |
| 3 | +$(TYPEDEF) |
| 4 | +
|
| 5 | +Dual Averaging state |
| 6 | +
|
| 7 | +Mutable state for storing the current iteration of the dual averaging algorithm. |
2 | 8 |
|
| 9 | +# Fields |
| 10 | +
|
| 11 | +$(TYPEDFIELDS) |
| 12 | +""" |
3 | 13 | mutable struct DAState{T<:AbstractScalarOrVec{<:AbstractFloat}} |
| 14 | + "Adaptation iteration" |
4 | 15 | m::Int |
5 | 16 | ϵ::T |
| 17 | + "Asymptotic mean of parameter" |
6 | 18 | μ::T |
| 19 | + "Moving average parameter" |
7 | 20 | x_bar::T |
| 21 | + "Moving average statistic" |
8 | 22 | H_bar::T |
9 | 23 | end |
10 | 24 |
|
@@ -63,48 +77,66 @@ getϵ(ss::StepSizeAdaptor) = ss.state.ϵ |
63 | 77 | struct FixedStepSize{T<:AbstractScalarOrVec{<:AbstractFloat}} <: StepSizeAdaptor |
64 | 78 | ϵ::T |
65 | 79 | end |
66 | | -Base.show(io::IO, a::FixedStepSize) = print(io, "FixedStepSize(", a.ϵ, ")") |
| 80 | +function Base.show(io::IO, mime::MIME"text/plain", a::FixedStepSize) |
| 81 | + return print(io, "FixedStepSize adaptor with step size ", a.ϵ) |
| 82 | +end |
67 | 83 |
|
68 | 84 | getϵ(fss::FixedStepSize) = fss.ϵ |
69 | 85 |
|
70 | 86 | struct ManualSSAdaptor{T<:AbstractScalarOrVec{<:AbstractFloat}} <: StepSizeAdaptor |
71 | 87 | state::MSSState{T} |
72 | 88 | end |
73 | | -Base.show(io::IO, a::ManualSSAdaptor) = print(io, "ManualSSAdaptor()") |
| 89 | +function Base.show(io::IO, mime::MIME"text/plain", a::ManualSSAdaptor{T}) where {T} |
| 90 | + return print(io, "ManualSSAdaptor{$T} with step size of $(a.state.ϵ)") |
| 91 | +end |
74 | 92 |
|
75 | 93 | function ManualSSAdaptor(initϵ::T) where {T<:AbstractScalarOrVec{<:AbstractFloat}} |
76 | 94 | return ManualSSAdaptor{T}(MSSState(initϵ)) |
77 | 95 | end |
78 | 96 |
|
79 | 97 | """ |
| 98 | +$(TYPEDEF) |
| 99 | +
|
80 | 100 | An implementation of the Nesterov dual averaging algorithm to tune step size. |
81 | 101 |
|
82 | | -References |
| 102 | +# Fields |
| 103 | +
|
| 104 | +$(TYPEDFIELDS) |
| 105 | +
|
| 106 | +# References |
83 | 107 |
|
84 | 108 | Hoffman, M. D., & Gelman, A. (2014). The No-U-Turn Sampler: adaptively setting path lengths in Hamiltonian Monte Carlo. Journal of Machine Learning Research, 15(1), 1593-1623. |
85 | 109 | Nesterov, Y. (2009). Primal-dual subgradient methods for convex problems. Mathematical programming, 120(1), 221-259. |
86 | 110 | """ |
87 | 111 | struct NesterovDualAveraging{T<:AbstractFloat,S<:AbstractScalarOrVec{T}} <: StepSizeAdaptor |
| 112 | + "Adaption scaling" |
88 | 113 | γ::T |
| 114 | + "Effective starting iteration" |
89 | 115 | t_0::T |
| 116 | + "Adaption shrinkage" |
90 | 117 | κ::T |
| 118 | + "Target value of statistic" |
91 | 119 | δ::T |
92 | 120 | state::DAState{S} |
93 | 121 | end |
94 | | -function Base.show(io::IO, a::NesterovDualAveraging) |
| 122 | +function Base.show(io::IO, mime::MIME"text/plain", a::NesterovDualAveraging{T}) where {T} |
95 | 123 | return print( |
96 | 124 | io, |
97 | | - "NesterovDualAveraging(γ=", |
| 125 | + "NesterovDualAveraging{$T} with\n", |
| 126 | + "Scaling γ=", |
98 | 127 | a.γ, |
99 | | - ", t_0=", |
| 128 | + "\n", |
| 129 | + "Starting iter t_0=", |
100 | 130 | a.t_0, |
101 | | - ", κ=", |
| 131 | + "\n", |
| 132 | + "Shrinkage κ=", |
102 | 133 | a.κ, |
103 | | - ", δ=", |
| 134 | + "\n", |
| 135 | + "Target statistic δ=", |
104 | 136 | a.δ, |
105 | | - ", state.ϵ=", |
| 137 | + "\n", |
| 138 | + "Curret ϵ=", |
106 | 139 | getϵ(a), |
107 | | - ")", |
108 | 140 | ) |
109 | 141 | end |
110 | 142 |
|
|
0 commit comments