for(i in 1:I){
for (j in 1:J){
X[i]<- sum(Y[i,j]);
}
}
Hi All,I'm looking for a way to sum the rows of a column in STAN.
On Feb 12, 2015, at 3:22 PM, Allan Debertin <alland...@gmail.com> wrote:
Hi All,I'm looking for a way to sum the rows of a column in STAN.For example in JAGS this command is valid:for(i in 1:I){
for (j in 1:J){
X[i]<- sum(Y[i,j]);
}
}
What would be the equivalent in STAN?Many thanks,Allan
--
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.
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/wMEK0DuAZDs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
I'm looking for a way to sum the rows of a column in STAN.
vector col_sums(matrix X) { vector[cols(X)] s ; for (j in 1:cols(X)) s[j] <- sum(col(X, j)) ; return s ; }
vector row_sums(matrix X) { vector[rows(X)] s ; for (i in 1:rows(X)) s[i] <- sum(row(X, i)) ; return s ; } row_vector col_sums(matrix X) { row_vector[cols(X)] s ; s <- rep_row_vector(1, rows(X)) * X ; return s ; }
vector row_sums(matrix X) { vector[rows(X)] s ; s <- X * rep_vector(1, cols(X)) ; return s ; }We should allow users to have their own function libraries.
row_vector[J] x[I];
vector[I] y;
for(i in 1:I){
y[i] <- sum(x[i]);
}Thanks Andrew,I got this code to work to allow me to sum rows across a matrix:row_vector[J] x[I];
vector[I] y;
for(i in 1:I){
y[i] <- sum(x[i]);
}
To sum columns of matrix, I think the functions that Jonah and Ben pointed out would be easier. Would it be possible to implement a column_vector in STAN?
Do you have the R chops to implement it?Or, I guess it makes more sense to implement within Stan itself, because it’s the Stan programs that will have to get parsed for dependencies.