JAGS could do this with an array to store intermediate
values:
Q[1] <- original_Q %*% original_Q;
for (n in 2:N)
Q[n] <- original_Q %*% Q[n-1];
Then you'd get your result in Q[N] = original_Q^N.
And a whole lot of intermediate outputs you would not want
to monitor.
We spend a fair bit of time suggesting that people don't
literally translate JAGS code like the above to Stan but
to use reassignment.
We could certainly add a matrix power operator. I added
a feature request, but did not assign it to anyone or make
it an immediate priority:
https://github.com/stan-dev/stan/issues/1073
I would suggest putting the loop in a function for the time
being.
functions {
matrix matrix_pow(matrix a, int n) {
if (n == 0)
return diag_matrix(rep_vector(0, rows(a)));
else if (n == 1)
return a;
else
return a * matrix_pow(a, n - 1);
}
}
- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.