Skip to content

Commit 774bde8

Browse files
committed
added support for initial values
- function_signatures::add supports up to 7 arguments - stan::prob::propto supports up to 10 arguments - update dlm examples in src/models/misc/dlm/ Conflicts: src/models/misc/dlm/fx_equicorr.stan src/models/misc/dlm/fx_factor.stan
1 parent b7d6669 commit 774bde8

File tree

8 files changed

+2145
-31
lines changed

8 files changed

+2145
-31
lines changed

misc/dlm/create_fx_equicorr_data.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library(rstan)
2+
load("fxrates.rda")
3+
4+
standata <-
5+
within(list(), {
6+
y <- t(fxrates)
7+
r <- nrow(y)
8+
T <- ncol(y)
9+
m0 <- array(rep(0, r), r)
10+
C0 <- diag(3) * 1e7
11+
})
12+
13+
14+
stan_rdump(names(standata), file="fx_equicorr.data.R", envir=as.environment(standata))

misc/dlm/create_fx_factor_data.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library(rstan)
2+
load("fxrates.rda")
3+
4+
standata <-
5+
within(list(), {
6+
y <- t(fxrates)
7+
r <- nrow(y)
8+
T <- ncol(y)
9+
m0 <- array(0, 1)
10+
C0 <- matrix(1e7)
11+
})
12+
13+
14+
stan_rdump(names(standata), file="fx_factor.data.R", envir=as.environment(standata))

misc/dlm/fx.data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
n <- 3
1+
r <- 3
2+
n <- 1
23
T <- 2465
34
y <-
45
structure(c(-0.0156963885668762, -0.081740713395602, -0.0281008463968755,

misc/dlm/fx_equicorr.stan

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
data {
2-
int n;
2+
int r;
33
int T;
4-
matrix[n, T] y;
4+
matrix[r, T] y;
5+
vector[r] m0;
6+
cov_matrix[r] C0;
57
}
68
transformed data {
7-
vector[n] ones;
8-
matrix[n, n] G;
9-
matrix[n, n] F;
10-
for (i in 1:n) {
9+
vector[r] ones;
10+
matrix[r, r] G;
11+
matrix[r, r] F;
12+
for (i in 1:r) {
1113
ones[i] <- 1.0;
1214
}
1315
G <- diag_matrix(ones);
1416
F <- G;
1517
}
1618
parameters {
1719
real<lower=-1.0, upper=1.0> rho;
18-
vector<lower=0.0>[n] sigma;
19-
vector<lower=0.0>[n] W_diag;
20+
vector<lower=0.0>[r] sigma;
21+
vector<lower=0.0>[r] W_diag;
2022
}
2123
transformed parameters {
22-
cov_matrix[n] V;
23-
cov_matrix[n] W;
24+
cov_matrix[r] V;
25+
cov_matrix[r] W;
2426
W <- diag_matrix(W_diag);
25-
for (i in 1:n) {
27+
for (i in 1:r) {
2628
V[i, i] <- pow(sigma[i], 2);
2729
for (j in 1:(i - 1)) {
2830
V[i, j] <- sigma[i] * sigma[j] * rho;
@@ -31,5 +33,5 @@ transformed parameters {
3133
}
3234
}
3335
model {
34-
y ~ gaussian_dlm_log(F, G, V, W);
36+
y ~ gaussian_dlm_log(F, G, V, W, m0, C0);
3537
}

misc/dlm/fx_factor.data.R

Lines changed: 2098 additions & 0 deletions
Large diffs are not rendered by default.

misc/dlm/fx_factor.stan

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ data {
55
int r;
66
int T;
77
matrix[r, T] y;
8+
vector[1] m0;
9+
cov_matrix[1] C0;
810
}
911
transformed data {
1012
matrix[1, 1] G;
@@ -22,5 +24,5 @@ transformed parameters {
2224
}
2325
}
2426
model {
25-
y ~ gaussian_dlm(F, G, V, W);
27+
y ~ gaussian_dlm(F, G, V, W, m0, C0);
2628
}

misc/dlm/fxrates.rda

39.2 KB
Binary file not shown.

misc/dlm/nile.stan

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)