-
Notifications
You must be signed in to change notification settings - Fork 4
/
multiple-parameters.cc
44 lines (38 loc) · 1.53 KB
/
multiple-parameters.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "../../viltrum.h"
#include <iostream>
#include <iomanip>
using namespace viltrum;
int main() {
const std::size_t bins = 24;
const unsigned long samples = 1000000;
auto f =[] (float x, float y) -> double {
if ((x+y)<1) return 1.0;
else return 0.0;
};
//With floats, due to numerica stability, for a very large number of samples, monte_carlo fails to converge?
{
LoggerProgress logger("Simple");
std::cout<<integrate(monte_carlo(samples*bins),f,range_primary<2>(),logger)<<std::endl;
}
{
LoggerProgress logger("Monte-Carlo");
std::vector<float> sol(bins,0.0f);
integrate(monte_carlo(bins*samples),sol,f,range_primary<2>(),logger);
for (float v : sol) std::cout<<std::fixed<<std::setprecision(2)<<std::setw(4)<<v<<" ";
std::cout<<std::endl;
}
{
LoggerProgress logger("Per bin");
std::vector<float> sol(bins,0.0f);
integrate(integrator_per_bin(monte_carlo(samples)),sol,f,range_primary<2>(),logger);
for (float v : sol) std::cout<<std::fixed<<std::setprecision(2)<<std::setw(4)<<v<<" ";
std::cout<<std::endl;
}
{
LoggerProgress logger("Parallel"); //I'm suprised this works with a RNG shared among threads
std::vector<float> sol(bins,0.0f);
integrate(integrator_per_bin_parallel(monte_carlo(samples)),sol,f,range_primary<2>(),logger);
for (float v : sol) std::cout<<std::fixed<<std::setprecision(2)<<std::setw(4)<<v<<" ";
std::cout<<std::endl;
}
}