probml / pmtk3

Probabilistic Modeling Toolkit for Matlab/Octave.
MIT License
1.55k stars 797 forks source link

Ars fix #94

Closed evelinag closed 9 years ago

evelinag commented 9 years ago

There are two fixed bugs:

  1. The first fix relates to bug https://github.com/probml/pmtk3/issues/61. The code is treating hull values as probabilities but they are computed in log space. This lead to higher acceptance rate. For example, with normal distribution:
function ys = funcNormal(xs)
       sigma = 1.0;
       ys = -(xs.*xs) / sigma;
end

samples = ars(@funcNormal, -1.0, 1.0, [-inf,inf], 10000);
hist(samples,30);
qqplot(samples);

screen shot 2015-01-19 at 12 02 34 QQ plot shows that the resulting samples are not from the standard normal distribution. screen shot 2015-01-19 at 12 02 08

With fix https://github.com/evelinag/pmtk3/commit/4f881a5132718281742e346d0bc2f09480e6cd45, the result looks as follows: screen shot 2015-01-19 at 12 03 40 screen shot 2015-01-19 at 12 03 55

  1. The second bug was in the way how bounded distributions were treated. If the domain where a distribution is defined is not infinite, the area between initial points and boundaries of the interval was ignored. For example for Beta distribution which is defined on [0,1]:
function ys = funcBeta(xs)
    a = 2; b = 5; 
    ys = (a - 1) .* log(xs) + (b - 1) .* log(1 - xs);
end

samples = ars(@funcBeta, 0.1, 0.8, [0, 1], 10000);
hist(samples,30);

screen shot 2015-01-19 at 12 19 35

With fix https://github.com/evelinag/pmtk3/commit/a0e800f58429dac8fd8d9ec5e194ca7fe722661e, ars samples from the full interval. screen shot 2015-01-19 at 12 20 22