IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
RandomIterator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Augusto Alves Junior
RandomIterator
Commits
67eefe7e
Commit
67eefe7e
authored
2 years ago
by
Antonio Augusto Alves Junior
Browse files
Options
Downloads
Plain Diff
...
parents
aca7ed5b
766a73e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/CMakeLists.txt
+11
-0
11 additions, 0 deletions
tests/CMakeLists.txt
tests/plot_stream.cpp
+105
-11
105 additions, 11 deletions
tests/plot_stream.cpp
with
116 additions
and
11 deletions
tests/CMakeLists.txt
+
11
−
0
View file @
67eefe7e
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
tests/plot_stream.cpp
+
105
−
11
View file @
67eefe7e
...
...
@@ -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_
d
ist
ribution
=
hist
(
data_normal_distribution
);
auto data_normal_
h
ist
ogram
= hist(data_normal_distribution
, histogram::normalization::probability
);
subplot(1, 3, 1);
auto
data_uniform_
d
ist
ribution
=
hist
(
data_uniform_distribution
);
auto data_uniform_
h
ist
ogram
= 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
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment