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
6a3c464d
Commit
6a3c464d
authored
6 years ago
by
Martin Beseda
Browse files
Options
Downloads
Patches
Plain Diff
ENH: DataSet has a new method for saving data to text files.
parent
b601c67b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/DataSet/DataSet.cpp
+53
-27
53 additions, 27 deletions
src/DataSet/DataSet.cpp
src/DataSet/DataSet.h
+9
-1
9 additions, 1 deletion
src/DataSet/DataSet.h
src/exceptions.h
+0
-0
0 additions, 0 deletions
src/exceptions.h
with
62 additions
and
28 deletions
src/DataSet/DataSet.cpp
+
53
−
27
View file @
6a3c464d
...
@@ -3,10 +3,11 @@
...
@@ -3,10 +3,11 @@
//
//
#include
<algorithm>
#include
<algorithm>
#include
<filesystem>
#include
<boost/serialization/export.hpp>
#include
<boost/serialization/export.hpp>
#include
"DataSetSerialization.h"
#include
"DataSetSerialization.h"
#include
"
../
exceptions.h"
#include
"exceptions.h"
BOOST_CLASS_EXPORT_IMPLEMENT
(
lib4neuro
::
DataSet
);
BOOST_CLASS_EXPORT_IMPLEMENT
(
lib4neuro
::
DataSet
);
...
@@ -25,7 +26,7 @@ namespace lib4neuro {
...
@@ -25,7 +26,7 @@ namespace lib4neuro {
ia
>>
*
this
;
ia
>>
*
this
;
ifs
.
close
();
ifs
.
close
();
}
else
{
}
else
{
THROW_RUNTIME_ERROR
(
"File couldn't be open!"
);
THROW_RUNTIME_ERROR
(
"File
"
+
file_path
+
"
couldn't be open!"
);
}
}
}
}
...
@@ -182,12 +183,38 @@ namespace lib4neuro {
...
@@ -182,12 +183,38 @@ namespace lib4neuro {
}
}
}
}
void
DataSet
::
store_text
(
std
::
string
&
file_path
)
{
void
DataSet
::
store_text
(
std
::
string
file_path
)
{
//TODO check if stream was successfully opened
std
::
ofstream
ofs
(
file_path
);
std
::
ofstream
ofs
(
file_path
);
boost
::
archive
::
text_oarchive
oa
(
ofs
);
oa
<<
*
this
;
if
(
!
ofs
.
is_open
())
{
ofs
.
close
();
THROW_RUNTIME_ERROR
(
"File "
+
file_path
+
" couldn't be open!"
);
}
else
{
boost
::
archive
::
text_oarchive
oa
(
ofs
);
oa
<<
*
this
;
ofs
.
close
();
}
}
void
DataSet
::
store_data_text
(
std
::
string
file_path
)
{
std
::
ofstream
ofs
(
file_path
);
if
(
!
ofs
.
is_open
())
{
THROW_RUNTIME_ERROR
(
"File "
+
file_path
+
" couldn't be open!"
);
}
else
{
for
(
auto
e
:
this
->
data
)
{
/* First part of the pair */
for
(
unsigned
int
i
=
0
;
i
<
e
.
first
.
size
()
-
1
;
i
++
)
{
ofs
<<
e
.
first
.
at
(
i
)
<<
","
;
}
ofs
<<
e
.
first
.
back
()
<<
" "
;
/* Second part of the pair */
for
(
unsigned
int
i
=
0
;
i
<
e
.
second
.
size
()
-
1
;
i
++
)
{
ofs
<<
e
.
second
.
at
(
i
)
<<
","
;
}
ofs
<<
e
.
second
.
back
()
<<
std
::
endl
;
}
}
}
}
template
<
class
T
>
template
<
class
T
>
...
@@ -316,27 +343,26 @@ namespace lib4neuro {
...
@@ -316,27 +343,26 @@ namespace lib4neuro {
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
DataSet
::
get_random_data_batch
(
size_t
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
)
{
return
this
->
data
;
return
this
->
data
;
}
else
{
}
else
{
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
newData
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
newData
;
srand
(
time
(
NULL
));
//TODO use Mersen twister from Boost
srand
(
time
(
NULL
));
//TODO use Mersen twister from Boost
size_t
n_chosen
=
rand
()
%
std
::
min
(
max
,
this
->
data
.
size
())
+
1
;
size_t
n_chosen
=
rand
()
%
std
::
min
(
max
,
this
->
data
.
size
())
+
1
;
std
::
vector
<
size_t
>
chosens
;
std
::
vector
<
size_t
>
chosens
;
size_t
chosen
;
size_t
chosen
;
for
(
int
i
=
0
;
i
<
n_chosen
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n_chosen
;
i
++
)
{
chosen
=
rand
()
%
this
->
data
.
size
();
chosen
=
rand
()
%
this
->
data
.
size
();
auto
it
=
std
::
find
(
chosens
.
begin
(),
chosens
.
end
(),
chosen
);
auto
it
=
std
::
find
(
chosens
.
begin
(),
chosens
.
end
(),
chosen
);
if
(
it
!=
chosens
.
end
())
{
if
(
it
!=
chosens
.
end
())
{
i
--
;
i
--
;
}
else
{
}
else
{
newData
.
push_back
(
this
->
data
.
at
(
chosen
));
newData
.
push_back
(
this
->
data
.
at
(
chosen
));
}
}
}
}
return
newData
;
}
}
return
newData
;
}
}
}
}
This diff is collapsed.
Click to expand it.
src/DataSet/DataSet.h
+
9
−
1
View file @
6a3c464d
...
@@ -211,8 +211,16 @@ namespace lib4neuro {
...
@@ -211,8 +211,16 @@ namespace lib4neuro {
/**
/**
* Stores the DataSet object to the binary file
* Stores the DataSet object to the binary file
*
*/
LIB4NEURO_API
void
store_text
(
std
::
string
file_path
);
/**
* Stores the data to the text file in a human readable format
*
* @param file_path
*/
*/
LIB4NEURO_API
void
store_text
(
std
::
string
&
file_path
);
LIB4NEURO_API
void
store_
data_
text
(
std
::
string
file_path
);
/**
/**
* Normalizes the data set
* Normalizes the data set
...
...
This diff is collapsed.
Click to expand it.
exceptions.h
→
src/
exceptions.h
+
0
−
0
View file @
6a3c464d
File moved
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