IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 67eefe7e authored by Antonio Augusto Alves Junior's avatar Antonio Augusto Alves Junior
Browse files

...

parents aca7ed5b 766a73e6
No related branches found
No related tags found
No related merge requests found
......@@ -104,3 +104,14 @@ project(tests)
target_link_libraries( distribution_sampling )
add_dependencies(tests distribution_sampling )
#----------------------------
message(STATUS "Adding target to tests. Executable file name: plot_stream.cpp")
add_executable( plot_stream plot_stream.cpp)
target_link_libraries( plot_stream PUBLIC matplot -lpthread -lm )
add_dependencies(tests plot_stream )
......@@ -27,27 +27,53 @@
*/
#include <random_iterator/Stream.hpp>
#include <cstdio>
#include <cstdint>
//
#include <random_iterator/Stream.hpp>
#include <random>
#include <cmath>
#include <vector>
#include <matplot/matplot.h>
//set a global seed
static const uint64_t default_seed= 0x548c9decbce65295 ;
#define NSAMPLES 1024
#define NSAMPLES 10000
using namespace matplot;
template<typename Generator>
void plot_normal(char* name, uint64_t seed);
template<typename Generator>
void plot_exponential(char* name, uint64_t seed);
int main(int argv, char** argc)
{
random_iterator::philox RNG(seed);
plot_normal<random_iterator::philox>("philox", default_seed);
plot_normal<random_iterator::squares3_64>("squares3_{64}", default_seed);
plot_normal<random_iterator::squares4_64>("squares4_{64}", default_seed);
plot_normal<random_iterator::squares3_128>("squares3_{128}", default_seed);
plot_normal<random_iterator::squares4_128>("squares4_{128}", default_seed);
plot_normal<random_iterator::ars>("ars", default_seed);
plot_normal<random_iterator::threefry>("threefry", default_seed);
//show();
plot_exponential<random_iterator::philox>("philox", default_seed);
plot_exponential<random_iterator::squares3_64>("squares3_{64}", default_seed);
plot_exponential<random_iterator::squares4_64>("squares4_{64}", default_seed);
plot_exponential<random_iterator::squares3_128>("squares3_{128}", default_seed);
plot_exponential<random_iterator::squares4_128>("squares4_{128}", default_seed);
plot_exponential<random_iterator::ars>("ars", default_seed);
plot_exponential<random_iterator::threefry>("threefry", default_seed);
show();
/*
std::uniform_real_distribution<double> udist(0.0, 1.0);
std::normal_distribution<double> ndist(0.0, 1.0);
std::exponential_distribution<double> edist(1.0);
......@@ -66,18 +92,86 @@ int main(int argv, char** argc)
data_normal_distribution.push_back(nrng_stream[i]);
data_uniform_distribution.push_back(urng_stream[i]);
data_exponential_distribution.push_back(erng_stream[i]);
}
subplot(1, 3, 0);
auto data_normal_distribution = hist(data_normal_distribution);
auto data_normal_histogram = hist(data_normal_distribution, histogram::normalization::probability);
subplot(1, 3, 1);
auto data_uniform_distribution = hist(data_uniform_distribution);
auto data_uniform_histogram = hist(data_uniform_distribution, histogram::normalization::probability);
subplot(1, 3, 2);
auto data_exponential_histogram = hist(data_exponential_distribution, histogram::normalization::probability);
show();
*/
return 0;
}
template<typename Generator>
void plot_normal(char* name, uint64_t seed){
auto f = figure(false);
auto tile = f->nexttile();
Generator RNG(default_seed);
std::normal_distribution<double> ndist(0.0, 1.0);
auto nrng_stream = random_iterator::make_stream( ndist, RNG, 1);
std::vector<double> data_normal_distribution;
for(size_t i =0; i<NSAMPLES; ++i){
data_normal_distribution.push_back(nrng_stream[i]);
}
auto data_normal_histogram = hist(data_normal_distribution, histogram::normalization::pdf);
title(name);
hold(on);
double mean = 0.0;
double sigma = 1.0;
auto fnormal = [&](double y) {
return exp(-pow((y - mean), 2.) / (2. * pow(sigma, 2.))) /
(sigma * sqrt(2. * pi));
};
fplot(fnormal, std::array<double, 2>{-5, 15})->line_width(2.0);
f->draw();
}
template<typename Generator>
void plot_exponential(char* name, uint64_t seed){
auto f = figure(false);
auto tile = f->nexttile();
Generator RNG(default_seed);
std::exponential_distribution<double> ndist(1.0);
auto nrng_stream = random_iterator::make_stream( ndist, RNG, 1);
std::vector<double> data_exponential_distribution;
for(size_t i =0; i<NSAMPLES; ++i){
data_exponential_distribution.push_back(nrng_stream[i]);
}
auto data_exponential_histogram = hist(data_exponential_distribution, histogram::normalization::pdf);
title(name);
hold(on);
double tau = 1.0;
auto fexponential = [&](double y) {
return tau*exp(-tau*y);
};
fplot(fexponential, std::array<double, 2>{0, 15})->line_width(2.0);
f->draw();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment