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
da3e9b55
Commit
da3e9b55
authored
6 years ago
by
Martin Beseda
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Added FileNotFoundException handling.
parent
02016236
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/examples/simulator.cpp
+67
-62
67 additions, 62 deletions
src/examples/simulator.cpp
with
67 additions
and
62 deletions
src/examples/simulator.cpp
+
67
−
62
View file @
da3e9b55
...
@@ -36,29 +36,29 @@ double get_rel_error(std::vector<double> &d1, std::vector<double> &d2){
...
@@ -36,29 +36,29 @@ double get_rel_error(std::vector<double> &d1, std::vector<double> &d2){
int
main
(
int
argc
,
char
**
argv
){
int
main
(
int
argc
,
char
**
argv
){
/* Read data from the file */
try
{
l4n
::
CSVReader
reader
(
"/home/martin/Desktop/ANN_DATA_1_SET.txt"
,
"
\t
"
,
true
);
reader
.
read
();
/* Create data set for both the training and testing of the neural network */
/* Read data from the file */
std
::
vector
<
unsigned
int
>
inputs
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
26
,
27
,
28
};
l4n
::
CSVReader
reader
(
"/home/martin/5Desktop/ANN_DATA_1_SET.txt"
,
"
\t
"
,
true
);
std
::
vector
<
unsigned
int
>
outputs
=
{
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
};
reader
.
read
();
l4n
::
DataSet
ds
=
reader
.
get_data_set
(
&
inputs
,
&
outputs
);
/* Normalize data in the set for easier training of the network */
/* Create data set for both the training and testing of the neural network */
ds
.
normalize
();
std
::
vector
<
unsigned
int
>
inputs
=
{
2
,
3
,
4
,
5
,
6
,
7
,
8
,
26
,
27
,
28
};
std
::
vector
<
unsigned
int
>
outputs
=
{
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
};
/* Neural network construction */
l4n
::
DataSet
ds
=
reader
.
get_data_set
(
&
inputs
,
&
outputs
);
std
::
vector
<
unsigned
int
>
neuron_numbers_in_layers
=
{
10
,
10
,
10
,
9
};
l4n
::
FullyConnectedFFN
nn
(
&
neuron_numbers_in_layers
,
l4n
::
NEURON_TYPE
::
LOGISTIC
);
/* Error function */
/* Neural network construction */
l4n
::
MSE
mse
(
&
nn
,
&
ds
);
std
::
vector
<
unsigned
int
>
neuron_numbers_in_layers
=
{
10
,
10
,
10
,
9
};
l4n
::
FullyConnectedFFN
nn
(
&
neuron_numbers_in_layers
,
l4n
::
NEURON_TYPE
::
LOGISTIC
);
/*
Domai
n */
/*
Error functio
n */
std
::
vector
<
double
>
domain_bounds
(
2
*
(
nn
.
get_n_weights
()
+
nn
.
get_n_biases
())
);
l4n
::
MSE
mse
(
&
nn
,
&
ds
);
/* Training method */
/* Domain */
std
::
vector
<
double
>
domain_bounds
(
2
*
(
nn
.
get_n_weights
()
+
nn
.
get_n_biases
()));
/* Training method */
// for(size_t i = 0; i < domain_bounds.size() / 2; ++i){
// for(size_t i = 0; i < domain_bounds.size() / 2; ++i){
// domain_bounds[2 * i] = -10;
// domain_bounds[2 * i] = -10;
// domain_bounds[2 * i + 1] = 10;
// domain_bounds[2 * i + 1] = 10;
...
@@ -72,50 +72,55 @@ int main(int argc, char** argv){
...
@@ -72,50 +72,55 @@ int main(int argc, char** argv){
// 0.7,
// 0.7,
// 600,
// 600,
// 1000);
// 1000);
l4n
::
GradientDescent
gs
(
1e-3
,
100
,
100000
);
l4n
::
GradientDescent
gs
(
1e-3
,
100
,
100000
);
nn
.
randomize_weights
();
nn
.
randomize_weights
();
/* Cross - validation */
/* Cross - validation */
l4n
::
CrossValidator
cv
(
&
gs
,
&
mse
);
l4n
::
CrossValidator
cv
(
&
gs
,
&
mse
);
cv
.
run_k_fold_test
(
10
,
1
);
cv
.
run_k_fold_test
(
10
,
1
);
/* Save network to the file */
/* Save network to the file */
nn
.
save_text
(
"test_net.4n"
);
nn
.
save_text
(
"test_net.4n"
);
/* Check of the saved network */
/* Check of the saved network */
std
::
cout
<<
std
::
endl
<<
"The original network info:"
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"The original network info:"
<<
std
::
endl
;
nn
.
print_stats
();
nn
.
print_stats
();
nn
.
print_weights
();
nn
.
print_weights
();
l4n
::
NeuralNetwork
nn_loaded
(
"test_net.4n"
);
l4n
::
NeuralNetwork
nn_loaded
(
"test_net.4n"
);
std
::
cout
<<
std
::
endl
<<
"The loaded network info:"
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"The loaded network info:"
<<
std
::
endl
;
nn_loaded
.
print_stats
();
nn_loaded
.
print_stats
();
nn_loaded
.
print_weights
();
nn_loaded
.
print_weights
();
/* Example of evaluation of a single input, normalized input, de-normalized output */
/* Example of evaluation of a single input, normalized input, de-normalized output */
std
::
vector
<
double
>
input_norm
(
ds
.
get_input_dim
()),
std
::
vector
<
double
>
input_norm
(
ds
.
get_input_dim
()),
input
(
ds
.
get_input_dim
()),
input
(
ds
.
get_input_dim
()),
output_norm
(
ds
.
get_output_dim
()),
output_norm
(
ds
.
get_output_dim
()),
expected_output_norm
(
ds
.
get_output_dim
()),
expected_output_norm
(
ds
.
get_output_dim
()),
output
(
ds
.
get_output_dim
());
output
(
ds
.
get_output_dim
());
size_t
data_idx
=
0
;
size_t
data_idx
=
0
;
ds
.
get_input
(
input_norm
,
data_idx
);
ds
.
get_input
(
input_norm
,
data_idx
);
ds
.
get_output
(
expected_output_norm
,
data_idx
);
ds
.
get_output
(
expected_output_norm
,
data_idx
);
nn_loaded
.
eval_single
(
input_norm
,
output_norm
);
nn_loaded
.
eval_single
(
input_norm
,
output_norm
);
ds
.
de_normalize_single
(
output_norm
,
output
);
ds
.
de_normalize_single
(
output_norm
,
output
);
ds
.
de_normalize_single
(
input_norm
,
input
);
ds
.
de_normalize_single
(
input_norm
,
input
);
std
::
cout
<<
std
::
endl
<<
"input: "
;
std
::
cout
<<
std
::
endl
<<
"input: "
;
for
(
auto
el
:
input_norm
){
std
::
cout
<<
el
<<
", "
;}
for
(
auto
el
:
input_norm
)
{
std
::
cout
<<
el
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"output: "
;
std
::
cout
<<
"output: "
;
for
(
auto
el
:
output
){
std
::
cout
<<
el
<<
", "
;}
for
(
auto
el
:
output
)
{
std
::
cout
<<
el
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"error of the "
<<
data_idx
<<
"-th element: "
std
::
cout
<<
"error of the "
<<
data_idx
<<
"-th element: "
<<
get_rel_error
(
output_norm
,
expected_output_norm
)
<<
std
::
endl
;
<<
get_rel_error
(
output_norm
,
expected_output_norm
)
<<
std
::
endl
;
}
catch
(
const
lib4neuro
::
FileNotFoundException
&
e
)
{
std
::
cout
<<
e
.
what
();
}
return
0
;
return
0
;
}
}
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