我在F#(.Net)和C++中開發了相同的算法(Baum-Welch用於估計隱馬爾可夫模型的參數)。在這兩種情況下,我開發了相同的測試,生成具有已知分佈的隨機測試數據,然後使用該算法估計參數,並確保它收斂到已知的正確答案。Boost與.Net隨機數生成器
問題是測試在F#的情況下工作正常,但未能收斂在C++實現中。我將這兩種算法與一些真實世界的數據進行了比較,他們給出了相同的結果,所以我的猜測是在C++的情況下,測試數據的生成被打破了。因此我的問題是:什麼是.Net 4隨機數生成器(我認爲這是VS2010的默認版本)?
在F#中我使用:
let random = new Random()
let randomNormal() = //for a standard normal random variable
let u1 = random.NextDouble()
let u2 = random.NextDouble()
let r = sqrt (-2. * (log u1))
let theta = 2. * System.Math.PI * u2
r * (sin theta)
//random.NextDouble() for uniform random variable on [0-1]
在C++中我使用了標準升壓類:
class HmmGenerator
{
public:
HmmGenerator() :
rng(37), //the seed does change the result, but it doesn't make it work
normalGenerator(rng, boost::normal_distribution<>(0.0, 1.0)),
uniformGenerator(rng, boost::uniform_01<>()) {}//other stuff here as well
private:
boost::mt19937 rng;
boost::variate_generator<boost::mt19937&,
boost::normal_distribution<> > normalGenerator;
boost::variate_generator<boost::mt19937&,
boost::uniform_01<> > uniformGenerator;
};
我應該期待使用產生隨機數的這兩種方式不同的結果?
編輯:另外,是在.Net中使用的生成器在Boost(理想情況下具有相同的參數),所以我可以運行它在C++和比較結果?
(+1)有趣的問題。很少的問題 - 1.你的意思是由C++實現什麼不收斂(到什麼)? 2.您爲實驗繪製了多少個樣本? – Nishanth 2013-04-25 16:00:12