Skip to content

Commit

Permalink
Fix NaN issue in box-muller tranform
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Stadnicki committed Apr 9, 2019
1 parent 6ef7676 commit 2db9a64
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vowpalwabbit/OjaNewton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ struct OjaNewton
{
float r1 = merand48(all->random_state);
float r2 = merand48(all->random_state);

//in the box-muller tranform, r1 should be strictly positive: https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
//redraw until r1 > 0
while (r1 == 0.0f)
{
r1 = merand48(all->random_state);
r2 = merand48(all->random_state);
}

(&w)[j] = sqrt(-2.f * log(r1)) * (float)cos(PI2 * r2);
}
}
Expand Down

0 comments on commit 2db9a64

Please sign in to comment.