As per the answer to this question I have attempted to change the parameter of a distribution in <random>
by using .param()
. Below is a toy example where I'm trying to do this.
For both a chi-squared and a normal distribution I have a function that generates two values, the second where the parameter has been changed by .param()
. I run both functions multiple times and print out the mean outcome for both. As expected the normal function produces mean outcomes of 0 and 10. Unexpectedly the chi-squared function produces mean outcomes of 4 and 4, instead of my expectation of 4 and 3. Why are my expectations off for the chi-squared distribution?
#include <iostream>
#include <random>
#include <vector>
using namespace std;
vector<double> chisqtest(mt19937_64 &gen)
{
vector<double> res(2);
chi_squared_distribution<double> chisq_dist(4);
res[0] = chisq_dist(gen);
chisq_dist.param(std::chi_squared_distribution<double>::param_type (3));
res[1] = chisq_dist(gen);
return res;
}
vector<double> normtest(mt19937_64 &gen)
{
vector<double> res(2);
normal_distribution<double> norm_dist(0,1);
res[0] = norm_dist(gen);
norm_dist.param(std::normal_distribution<double>::param_type (10,1));
res[1] = norm_dist(gen);
return res;
}
int main() {
unsigned int n = 100000;
mt19937_64 gen(1);
vector<double> totals = {0,0}, res(2);
for(unsigned int i = 0; i < n; i++){
res = chisqtest(gen);
totals[0] += res[0];
totals[1] += res[1];
}
cout << totals[0]/n << " " << totals[1]/n << "\n";
vector<double> totals2 = {0,0}, res2;
for(unsigned int i = 0; i < n; i++){
res2 = normtest(gen);
totals2[0] += res2[0];
totals2[1] += res2[1];
}
cout << totals2[0]/n << " " << totals2[1]/n << "\n";
}