Created
June 17, 2025 11:38
-
-
Save abikoushi/c36cb19fdcdbf9a7acdc2a0179de3ec6 to your computer and use it in GitHub Desktop.
Probabilistic principan component analysis using Stan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data { | |
int<lower=0> N; | |
int<lower=0> D; | |
int<lower=0> R; | |
matrix[N,D] Y; | |
} | |
parameters { | |
row_vector[D] mu; | |
matrix[D,R] W; | |
real<lower=0> sig2; | |
} | |
model { | |
for(i in 1:N){ | |
Y[i,:] ~ multi_normal(mu, add_diag(W*W', sig2)); | |
} | |
to_vector(W) ~ normal(0, 1); | |
sig2 ~ student_t(3, 0, 1); | |
} | |
generated quantities { | |
matrix[R,N] Z; | |
matrix[R,R] M = inverse(add_diag(W'*W, sig2)); | |
for(i in 1:N){ | |
Z[:,i] = multi_normal_rng((Y[i,:]-mu)*W*M, sig2*M); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment