Skip to content

Commit 300d33d

Browse files
committed
updates
1 parent f85b7bf commit 300d33d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/JMbayes2_Funs.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,22 @@ field<mat> mat2field (const mat &b, const field<uvec> &ind_RE) {
158158
uword n = ind_RE.n_elem;
159159
field<mat> out(n);
160160
for (uword i = 0; i < n; i++) {
161-
out.at(i) = b.cols(ind_RE.at(i));
161+
uword first_col = ind_RE.at(i).front();
162+
uword last_col = ind_RE.at(i).back();
163+
out.at(i) = b.cols(first_col, last_col);
162164
}
163165
return out;
164166
}
165167

168+
inline void mat2field_inplace (field<mat> &out, const mat &b, const field<uvec> &ind_RE) {
169+
uword n = ind_RE.n_elem;
170+
for (uword i = 0; i < n; ++i) {
171+
uword first_col = ind_RE.at(i).front();
172+
uword last_col = ind_RE.at(i).back();
173+
out.at(i) = b.cols(first_col, last_col);
174+
}
175+
}
176+
166177
field<vec> vec2field (const vec &betas, const field<uvec> &ind_FE) {
167178
uword n = ind_FE.n_elem;
168179
field<vec> out(n);

src/JMbayes2_RE.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ void update_b (field<mat> &b, mat &b_mat, field<vec> &eta,
5050
double log_det_V_Sigma = -arma::sum(arma::log(L.diag())) - arma::sum(arma::log(sds));
5151
double other_terms = -(double)nRE / 2.0 * log2pi + log_det_V_Sigma;
5252
vec denominator_b = logLik_long + logLik_surv + logLik_re;
53+
field<mat> proposed_b(ind_RE.n_elem);
54+
for (uword i = 0; i < ind_RE.n_elem; ++i) {
55+
proposed_b.at(i).set_size(b_mat.n_rows, ind_RE.at(i).n_elem);
56+
}
5357
for (uword j = 0; j < nRE; ++j) {
5458
vec old_b_j = b_mat.col(j);
5559
b_mat.col(j) += scale_b.col(j) % arma::randn<arma::vec>(n);
56-
field<mat> proposed_b = mat2field(b_mat, ind_RE);
60+
//field<mat> proposed_b = mat2field(b_mat, ind_RE);
61+
mat2field_inplace(proposed_b, b_mat, ind_RE);
5762
field<vec> eta_proposed = linpred_mixed(X, betas, Z, proposed_b, idL);
5863
vec logLik_long_proposed = log_long(y, eta_proposed, sigmas, extra_parms,
5964
families, links, ids, unq_ids, n);

0 commit comments

Comments
 (0)