1
+ """
2
+ BetaLocationScale
3
+
4
+ * Parametrization \\ mu, \\ sigma, \\ alpha, \\ beta
5
+
6
+ * Score
7
+
8
+ * Fisher Information
9
+
10
+ * `time_varying_params` map.
11
+
12
+ * Default link
13
+ """
14
+ BetaLocationScale
15
+
16
+
17
+ # Remember for all the code that param[t, 2] is c - a
18
+ # and param[t, 1] is a so to get c one must make
19
+ # param[t, 2] + param[t, 1]
20
+ function score! (score_til:: Matrix{T} , y:: T , :: Type{BetaLocationScale} , param:: Matrix{T} , t:: Int ) where T
21
+ score_til[t, 1 ] = - (param[t, 3 ] - 1 )/ (y - param[t, 1 ]) + (param[t, 4 ] + param[t, 3 ] - 1 )/ (param[t, 2 ] - param[t, 1 ])
22
+ score_til[t, 2 ] = (param[t, 4 ] - 1 )/ (param[t, 2 ] - y) - (param[t, 4 ] + param[t, 3 ] - 1 )/ (param[t, 2 ] - param[t, 1 ])
23
+ score_til[t, 3 ] = log (y - param[t, 1 ]) - log (param[t, 2 ] - param[t, 1 ]) +
24
+ digamma (param[t, 3 ] + param[t, 4 ]) - digamma (param[t, 3 ])
25
+ score_til[t, 4 ] = log (param[t, 2 ] - y) - log (param[t, 2 ] - param[t, 1 ]) +
26
+ digamma (param[t, 3 ] + param[t, 4 ]) - digamma (param[t, 4 ])
27
+ return
28
+ end
29
+
30
+ function fisher_information! (aux:: AuxiliaryLinAlg{T} , :: Type{BetaLocationScale} , param:: Matrix{T} , t:: Int ) where T
31
+ return error (" Fisher information not implemented for BetaLocationScale distribution." )
32
+ end
33
+
34
+ function log_likelihood (:: Type{BetaLocationScale} , y:: Vector{T} , param:: Matrix{T} , n:: Int ) where T
35
+ loglik = 0.0
36
+ for t in 1 : n
37
+ loglik += (param[t, 3 ] - 1 )* log (y[t] - param[t, 1 ]) + (param[t, 4 ] - 1 ) * log (param[t, 2 ] - y[t]) -
38
+ (param[t, 3 ] + param[t, 4 ] - 1 ) * log (param[t, 2 ] - param[t, 1 ]) - logbeta (param[t, 3 ], param[t, 4 ])
39
+ end
40
+ return - loglik
41
+ end
42
+
43
+ # Links
44
+ function link! (param_tilde:: Matrix{T} , :: Type{BetaLocationScale} , param:: Matrix{T} , t:: Int ) where T
45
+ param_tilde[t, 1 ] = link (LogLink, param[t, 1 ], zero (T))
46
+ param_tilde[t, 2 ] = link (LogLink, param[t, 2 ], zero (T))
47
+ return
48
+ end
49
+ function unlink! (param:: Matrix{T} , :: Type{BetaLocationScale} , param_tilde:: Matrix{T} , t:: Int ) where T
50
+ param[t, 1 ] = unlink (LogLink, param_tilde[t, 1 ], zero (T))
51
+ param[t, 2 ] = unlink (LogLink, param_tilde[t, 2 ], zero (T))
52
+ return
53
+ end
54
+ function jacobian_link! (aux:: AuxiliaryLinAlg{T} , :: Type{BetaLocationScale} , param:: Matrix{T} , t:: Int ) where T
55
+ aux. jac[1 ] = jacobian_link (LogLink, param[t, 1 ], zero (T))
56
+ aux. jac[2 ] = jacobian_link (LogLink, param[t, 2 ], zero (T))
57
+ return
58
+ end
59
+
60
+ # utils
61
+ function update_dist (:: Type{BetaLocationScale} , param:: Matrix{T} , t:: Int ) where T
62
+ small_threshold! (param[:, 3 : 4 ], SMALL_NUM, t)
63
+ beta = Beta (param[t, 3 ], param[t, 4 ])
64
+ return LocationScale (param[t, 1 ], param[t, 2 ] - param[t, 1 ], beta)
65
+ end
66
+
67
+ function params_sdm (d:: BetaLocationScale )
68
+ return (d. μ, d. σ + d. μ, Distributions. params (d. ρ)... )
69
+ end
70
+
71
+ function num_params (:: Type{BetaLocationScale} )
72
+ return 4
73
+ end
0 commit comments