Skip to content

Commit

Permalink
check normalization for sampling the latent sources
Browse files Browse the repository at this point in the history
  • Loading branch information
chung@molgen.mpg.de committed Jan 20, 2016
1 parent b8e6cf8 commit 793b720
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/rmn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,21 @@ void sampleU(
arma::uword i;
arma::uword L = s.size();
arma::vec p = arma::zeros(w + 1);

double norm;
for (i = 0; i < (w - 1) && i < L; i++){
if (t(i) > 0){
p(w) = empty(i) * mu(w, s(i));
p(arma::span(w - 1 - i, w - 1)) = z(arma::span(0, i)) % mu(arma::span(w - 1 - i, w - 1), s(i));
p /= arma::sum(p);
gsl_ran_multinomial(r, p.size(), t(i), p.begin(), u.colptr(i));
meanU.col(i) = p * t(i);
norm = arma::sum(p);
if (norm > 0){
p /= arma::sum(p);

gsl_ran_multinomial(r, p.size(), t(i), p.begin(), u.colptr(i));
meanU.col(i) = p * t(i);
}
else{
std::cout << "norm p = 0::" << p << std::endl;
}
}
else{
u.col(i).zeros();
Expand All @@ -166,9 +173,16 @@ void sampleU(
if (t(i) > 0){
p(w) = empty(i) * mu(w, s(i));
p(arma::span(0, w - 1)) = z(arma::span(i - w + 1, i)) % mu(arma::span(0, w - 1), s(i));
p /= arma::sum(p);
gsl_ran_multinomial(r, p.size(), t(i), p.begin(), u.colptr(i));
meanU.col(i) = p * t(i);
norm = arma::sum(p);
if (norm > 0){
p /= arma::sum(p);

gsl_ran_multinomial(r, p.size(), t(i), p.begin(), u.colptr(i));
meanU.col(i) = p * t(i);
}
else{
std::cout << "norm p = 0::" << p << std::endl;
}
}
else{
u.col(i).zeros();
Expand Down

0 comments on commit 793b720

Please sign in to comment.