Last active
August 29, 2015 14:21
-
-
Save ahmadyan/32d3d4b0d2ee275f9bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mc(double r, double** samples){ | |
cout << "Monte Carlo simulation" << endl ; | |
using namespace boost::math; | |
double sample_inside=0; | |
cout << "sizeof(sample_count)=" << sizeof(samples) << endl ; | |
for(int i=0;i<sample_count;i++){ | |
double x = samples[i][0]; | |
double y = samples[i][1]; | |
if(check(x,y,r)){ | |
sample_inside++; | |
mc_stream << "set obj "<< 10+i<< " circle at " << x << " ," << y << " size .001 fc rgb \"blue\" \n" << endl ; | |
}else{ | |
mc_stream << "set obj "<< 10+i<< " circle at " << x << " ," << y << " size .001 fc rgb \"red\" \n" << endl ; | |
} | |
} | |
cout << " samples=" << sample_inside << " " << sample_count << endl ; | |
//computing the confidence interval | |
double area = (double)sample_inside / (double)sample_count ; | |
double deviation = sqrt( area * (1-area)); | |
double alpha = 0.05; | |
//students_t dist(deviation-1); | |
//double T = quantile( complement( dist, alpha/ 2)); | |
double T = 1.96; //corresponds with 95% confidence interval | |
cout << "T=" << T << endl ; | |
double w = T * sqrt(deviation / (double)sample_count) ; | |
//double w = T*deviation / sqrt(double(deviation)); | |
cout << "w=" << w << endl ; | |
cout << "confidence interval= [" << area - w << " , " << area + w << " ] " << endl ; | |
cout << "estimated area = " << area << endl ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment