Skip to content

Commit

Permalink
more fixes for sparse matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodri committed Mar 16, 2022
1 parent 51973d6 commit 22d6053
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/stan_files/bernoulli.stan
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ data {
// stuff for the sparse case
int<lower=0> nnz_X0; // number of non-zero elements in the implicit X0 matrix
vector[nnz_X0] w_X0; // non-zero elements in the implicit X0 matrix
int<lower=0, upper = K - 1> v_X0[nnz_X0]; // column indices for w_X0
int<lower=1, upper = K> v_X0[nnz_X0]; // column indices for w_X0
// where the non-zeros start in each row of X0
int<lower=0, upper = rows(w_X0) + 1> u_X0[dense_X ? 0 : N[1] + 1];
int<lower=1, upper = rows(w_X0) + 1> u_X0[dense_X ? 0 : N[1] + 1];
int<lower=0> nnz_X1; // number of non-zero elements in the implicit X1 matrix
vector[nnz_X1] w_X1; // non-zero elements in the implicit X1 matrix
int<lower=0, upper = K - 1> v_X1[nnz_X1]; // column indices for w_X1
int<lower=1, upper = K> v_X1[nnz_X1]; // column indices for w_X1
// where the non-zeros start in each row of X1
int<lower=0, upper = rows(w_X1) + 1> u_X1[dense_X ? 0 : N[2] + 1];
int<lower=1, upper = rows(w_X1) + 1> u_X1[dense_X ? 0 : N[2] + 1];
// declares prior_PD, has_intercept, link, prior_dist, prior_dist_for_intercept
#include /data/data_glm.stan

Expand Down Expand Up @@ -59,12 +59,12 @@ data {
int<lower=0> num_non_zero[2]; // number of non-zero elements in the Z matrices
vector[num_non_zero[1]] w0; // non-zero elements in the implicit Z0 matrix
vector[num_non_zero[2]] w1; // non-zero elements in the implicit Z1 matrix
int<lower=0, upper = q - 1> v0[num_non_zero[1]]; // column indices for w0
int<lower=0, upper = q - 1> v1[num_non_zero[2]]; // column indices for w1
int<lower=1, upper = q> v0[num_non_zero[1]]; // column indices for w0
int<lower=1, upper = q> v1[num_non_zero[2]]; // column indices for w1
// where the non-zeros start in each row of Z0
int<lower=0, upper = rows(w0) + 1> u0[t > 0 ? N[1] + 1 : 0];
int<lower=1, upper = rows(w0) + 1> u0[t > 0 ? N[1] + 1 : 0];
// where the non-zeros start in each row of Z1
int<lower=0, upper = rows(w1) + 1> u1[t > 0 ? N[2] + 1 : 0];
int<lower=1, upper = rows(w1) + 1> u1[t > 0 ? N[2] + 1 : 0];
int<lower=0, upper=1> special_case; // whether we only have to deal with (1|group)
}
transformed data {
Expand Down
4 changes: 2 additions & 2 deletions src/stan_files/data/NKX.stan
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// stuff for the sparse case
int<lower=0> nnz_X; // number of non-zero elements in the implicit X matrix
vector[nnz_X] w_X; // non-zero elements in the implicit X matrix
int<lower=0, upper = K - 1> v_X[nnz_X]; // column indices for w_X
int<lower=1, upper = K> v_X[nnz_X]; // column indices for w_X
// where the non-zeros start in each row of X
int<lower=0, upper = rows(w_X) + 1> u_X[dense_X ? 0 : N + 1];
int<lower=1, upper = rows(w_X) + 1> u_X[dense_X ? 0 : N + 1];

// smooths
int<lower=0> K_smooth;
Expand Down
2 changes: 1 addition & 1 deletion src/stan_files/functions/common_functions.stan
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
int V[t,N];
int pos = 1;
if (t > 0) for (j in 1:N) for (i in 1:t) {
V[i,j] = v[pos] + 1;
V[i,j] = v[pos]; // + 1
pos += 1;
}
return V;
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_stan_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ if (require(lme4) && require(HSAUR3)) test_that("the Stan equivalent of lme4's Z
})) ) {
V <- matrix(parts$v, nrow = sum(p), ncol = nrow(Z))
expect_true(all(V ==
t(as.matrix(as.data.frame(make_V(nrow(Z), nrow(V), parts$v - 1L))))))
t(as.matrix(as.data.frame(make_V(nrow(Z), nrow(V), parts$v))))))
expect_equal(Zb@x, apply(V, 2, FUN = function(v) sum(b[v])))
}
}
Expand Down

0 comments on commit 22d6053

Please sign in to comment.