In accordance with the answer to this question, I tried to change the distribution parameter in <random> using .param() . Below is an example of toys where I am trying to do this.
For chi-squared and normal distribution, I have a function that generates two values, the second where the parameter has been changed to .param() . I run both functions several times and print out the average result for both. As expected, the normal function gives average results from 0 to 10. Suddenly, the chi-squared function gives average results of 4 and 4 instead of my expectations of 4 and 3. Why do my expectations give preference to the distribution of chi-squares?
#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"; }
source share