-
Notifications
You must be signed in to change notification settings - Fork 19
/
densityTransitionSoftmax.R
74 lines (66 loc) · 1.91 KB
/
densityTransitionSoftmax.R
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
67
68
69
70
71
72
73
74
#' Softmax transition density
#'
#' @inherit Density
#' @param uBeta Either a fixed value or a prior density for the parameter of the softmax regression.
#' @param P An integer with the number of covariates in the transition model.
#' @family Density
#' @examples
#' TransitionSoftmax(
#' uBeta = Gaussian(0, 10),
#' P = 3
#' )
TransitionSoftmax <- function(uBeta = NULL, P = NULL, ordered = NULL, equal = NULL, bounds = list(NULL, NULL),
trunc = list(NULL, NULL), k = NULL, r = NULL, param = NULL) {
LinkDensity("TransitionSoftmax", ordered, equal, bounds, trunc, k, r, param, uBeta = uBeta, P = P)
}
#' @keywords internal
#' @inherit explain_density
explain_density.TransitionSoftmax <- function(x, print = TRUE) {
collapse(
"Time-varying probabilities driven by covariates via softmax mapping.",
NextMethod()
)
}
#' @keywords internal
#' @inherit freeParameters
freeParameters.TransitionSoftmax <- function(x) {
uBetaStr <-
if (is.Density(x$uBeta)) {
uBetaBoundsStr <- make_bounds(x, "uBeta")
sprintf(
"
matrix%s[K, P] uBeta[K]; // transition model regressors
// uBeta[to, from, p-th regressor]
",
uBetaBoundsStr
)
} else {
""
}
uBetaStr
}
#' @keywords internal
#' @inherit fixedParameters
fixedParameters.TransitionSoftmax <- function(x) {
# warning("fixedParameters.Softmax: TO BE IMPLEMENTED.")
""
}
#' @keywords internal
#' @inherit getParameterNames
getParameterNames.TransitionSoftmax <- function(x) {
"uBeta"
}
#' @keywords internal
#' @inherit is.TVTransition
is.TVTransition.TransitionSoftmax <- function(x) { TRUE }
#' @keywords internal
#' @inherit link
link.TransitionSoftmax <- function(x) {
sprintf(
"A[t, i] = softmax((u[t] * uBeta%s[i]')');",
x$k
)
}
#' @keywords internal
#' @inherit prior
prior.TransitionSoftmax <- function(x) { "" }