Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lib4neuro
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
MolDyn
lib4neuro
Commits
f3d69ba6
Commit
f3d69ba6
authored
6 years ago
by
Michal Kravcenko
Browse files
Options
Downloads
Patches
Plain Diff
MOD: placed the random generator to the body of the class for more robust rng
parent
b62a844d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/DataSet/DataSet.cpp
+10
-6
10 additions, 6 deletions
src/DataSet/DataSet.cpp
src/DataSet/DataSet.h
+5
-0
5 additions, 0 deletions
src/DataSet/DataSet.h
with
15 additions
and
6 deletions
src/DataSet/DataSet.cpp
+
10
−
6
View file @
f3d69ba6
...
...
@@ -17,10 +17,13 @@ namespace lib4neuro {
this
->
n_elements
=
0
;
this
->
input_dim
=
0
;
this
->
output_dim
=
0
;
this
->
gen
=
boost
::
random
::
mt19937
(
std
::
time
(
0
));
}
DataSet
::
DataSet
(
std
::
string
file_path
)
{
std
::
ifstream
ifs
(
file_path
);
this
->
gen
=
boost
::
random
::
mt19937
(
std
::
time
(
0
));
if
(
ifs
.
is_open
())
{
try
{
boost
::
archive
::
text_iarchive
ia
(
ifs
);
...
...
@@ -42,6 +45,7 @@ namespace lib4neuro {
this
->
data
=
*
data_ptr
;
this
->
input_dim
=
this
->
data
[
0
].
first
.
size
();
this
->
output_dim
=
this
->
data
[
0
].
second
.
size
();
this
->
gen
=
boost
::
random
::
mt19937
(
std
::
time
(
0
));
if
(
ns
)
{
this
->
normalization_strategy
=
ns
;
...
...
@@ -62,6 +66,7 @@ namespace lib4neuro {
this
->
n_elements
=
0
;
this
->
input_dim
=
1
;
this
->
output_dim
=
1
;
this
->
gen
=
boost
::
random
::
mt19937
(
std
::
time
(
0
));
if
(
ns
)
{
this
->
normalization_strategy
=
ns
;
...
...
@@ -82,6 +87,7 @@ namespace lib4neuro {
this
->
input_dim
=
bounds
.
size
()
/
2
;
this
->
output_dim
=
output_dim
;
this
->
n_elements
=
0
;
this
->
gen
=
boost
::
random
::
mt19937
(
std
::
time
(
0
));
if
(
ns
)
{
this
->
normalization_strategy
=
ns
;
...
...
@@ -400,19 +406,17 @@ namespace lib4neuro {
* Method returning random amount of data pairs between 1-max
*/
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
DataSet
::
get_random_data_batch
(
size_t
max
)
{
if
(
max
<=
0
)
{
if
(
max
<=
0
||
max
>=
this
->
data
.
size
()
)
{
return
this
->
data
;
}
else
{
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
newData
;
srand
(
time
(
NULL
));
//TODO use Mersen
t
w
is
ter from Boost
boost
::
random
::
uniform_int_distribution
<>
dist
(
0
,
t
h
is
->
data
.
size
()
-
1
);
size_t
n_chosen
=
rand
()
%
std
::
min
(
max
,
this
->
data
.
size
())
+
1
;
n_chosen
=
max
;
std
::
vector
<
size_t
>
chosens
;
size_t
chosen
;
for
(
int
i
=
0
;
i
<
n_chosen
;
i
++
)
{
chosen
=
rand
()
%
this
->
data
.
size
(
);
for
(
int
i
=
0
;
i
<
max
;
i
++
)
{
chosen
=
dist
(
gen
);
auto
it
=
std
::
find
(
chosens
.
begin
(),
chosens
.
end
(),
chosen
);
if
(
it
!=
chosens
.
end
())
{
...
...
This diff is collapsed.
Click to expand it.
src/DataSet/DataSet.h
+
5
−
0
View file @
f3d69ba6
...
...
@@ -12,6 +12,9 @@
#include
<string>
#include
<functional>
#include
<limits>
#include
<boost/random/mersenne_twister.hpp>
#include
<boost/random/uniform_int_distribution.hpp>
#include
<ctime>
#include
"../settings.h"
#include
"../NormalizationStrategy/NormalizationStrategy.h"
...
...
@@ -26,6 +29,8 @@ namespace lib4neuro {
private:
boost
::
random
::
mt19937
gen
;
/**
* Number of elements in the data set
*/
...
...
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