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
467e9819
Commit
467e9819
authored
6 years ago
by
Martin Beseda
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev_cpp' of code.it4i.cz:voj0085/4Neuro into dev_cpp
parents
0e00e98c
a1ef1ef6
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/CMakeLists.txt
+3
-0
3 additions, 0 deletions
src/CMakeLists.txt
src/tests/ErrorFunctions_test.cpp
+184
-0
184 additions, 0 deletions
src/tests/ErrorFunctions_test.cpp
src/tests/NeuralNetwork_test.cpp
+131
-0
131 additions, 0 deletions
src/tests/NeuralNetwork_test.cpp
with
318 additions
and
0 deletions
src/CMakeLists.txt
+
3
−
0
View file @
467e9819
...
...
@@ -75,6 +75,9 @@ target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro)
add_executable
(
dataset_test tests/DataSet_test.cpp
)
target_link_libraries
(
dataset_test boost_unit_test 4neuro
)
add_executable
(
errorfunction_test tests/ErrorFunctions_test.cpp
)
target_link_libraries
(
errorfunction_test boost_unit_test 4neuro
)
add_executable
(
particle_swarm_test tests/ParticleSwarm_test.cpp
)
target_link_libraries
(
particle_swarm_test boost_unit_test 4neuro
)
...
...
This diff is collapsed.
Click to expand it.
src/tests/ErrorFunctions_test.cpp
0 → 100644
+
184
−
0
View file @
467e9819
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
#define BOOST_TEST_NO_MAIN
#include
<boost/test/unit_test.hpp>
#include
"../ErrorFunction/ErrorFunctions.h"
#include
"../Neuron/NeuronLinear.h"
/**
* Boost testing suite for testing ErrorFunction.h
* doesn't test inherited methods
*/
BOOST_AUTO_TEST_SUITE
(
ErrorFunctions_test
)
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_Construction_Test
)
{
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
DataSet
dataSet
(
&
data_vec
);
BOOST_CHECK_NO_THROW
(
MSE
mse
(
&
network
,
&
dataSet
));
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_Eval_Test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
network
.
randomize_weights
();
std
::
vector
<
size_t
>
net_input_neurons_indices
(
1
);
std
::
vector
<
size_t
>
net_output_neurons_indices
(
1
);
net_input_neurons_indices
[
0
]
=
0
;
net_output_neurons_indices
[
0
]
=
1
;
network
.
specify_input_neurons
(
net_input_neurons_indices
);
network
.
specify_output_neurons
(
net_output_neurons_indices
);
DataSet
dataSet
(
&
data_vec
);
double
weights
[
1
]
=
{
0
};
MSE
mse
(
&
network
,
&
dataSet
);
BOOST_CHECK_EQUAL
(
4
,
mse
.
eval
(
&
weights
[
0
]));
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_Get_dimension_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
network
.
randomize_weights
();
std
::
vector
<
size_t
>
net_input_neurons_indices
(
1
);
std
::
vector
<
size_t
>
net_output_neurons_indices
(
1
);
net_input_neurons_indices
[
0
]
=
0
;
net_output_neurons_indices
[
0
]
=
1
;
network
.
specify_input_neurons
(
net_input_neurons_indices
);
network
.
specify_output_neurons
(
net_output_neurons_indices
);
DataSet
dataSet
(
&
data_vec
);
MSE
mse
(
&
network
,
&
dataSet
);
BOOST_CHECK_EQUAL
(
1
,
mse
.
get_dimension
());
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_SUM_Construction_Test
)
{
BOOST_CHECK_NO_THROW
(
MSE_SUM
mse_sum
);
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_SUM_Add_Error_Function_Test
)
{
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
DataSet
dataSet
(
&
data_vec
);
ErrorFunction
*
f
=
new
MSE
(
&
network
,
&
dataSet
);
MSE_SUM
mse_sum
;
BOOST_CHECK_NO_THROW
(
mse_sum
.
add_error_function
(
f
));
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_SUM_Eval_Test
)
{
MSE_SUM
mse_sum
;
double
weights
[
1
]
=
{
0
};
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
network
.
randomize_weights
();
std
::
vector
<
size_t
>
net_input_neurons_indices
(
1
);
std
::
vector
<
size_t
>
net_output_neurons_indices
(
1
);
net_input_neurons_indices
[
0
]
=
0
;
net_output_neurons_indices
[
0
]
=
1
;
network
.
specify_input_neurons
(
net_input_neurons_indices
);
network
.
specify_output_neurons
(
net_output_neurons_indices
);
DataSet
dataSet
(
&
data_vec
);
ErrorFunction
*
f
=
new
MSE
(
&
network
,
&
dataSet
);
mse_sum
.
add_error_function
(
f
);
BOOST_CHECK_EQUAL
(
4
,
mse_sum
.
eval
(
&
weights
[
0
]));
}
BOOST_AUTO_TEST_CASE
(
ErrorFunction_MSE_SUM_Get_Dimension_test
)
{
MSE_SUM
mse_sum
;
BOOST_CHECK_EQUAL
(
0
,
mse_sum
.
get_dimension
());
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
std
::
vector
<
std
::
pair
<
std
::
vector
<
double
>
,
std
::
vector
<
double
>>>
data_vec
;
std
::
vector
<
double
>
inp
,
out
;
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
inp
.
push_back
(
i
);
out
.
push_back
(
i
+
4
);
}
data_vec
.
emplace_back
(
std
::
make_pair
(
inp
,
out
));
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
network
.
randomize_weights
();
std
::
vector
<
size_t
>
net_input_neurons_indices
(
1
);
std
::
vector
<
size_t
>
net_output_neurons_indices
(
1
);
net_input_neurons_indices
[
0
]
=
0
;
net_output_neurons_indices
[
0
]
=
1
;
network
.
specify_input_neurons
(
net_input_neurons_indices
);
network
.
specify_output_neurons
(
net_output_neurons_indices
);
DataSet
dataSet
(
&
data_vec
);
ErrorFunction
*
f
=
new
MSE
(
&
network
,
&
dataSet
);
mse_sum
.
add_error_function
(
f
);
BOOST_CHECK_EQUAL
(
1
,
mse_sum
.
get_dimension
());
}
BOOST_AUTO_TEST_SUITE_END
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tests/NeuralNetwork_test.cpp
+
131
−
0
View file @
467e9819
...
...
@@ -82,4 +82,135 @@ BOOST_AUTO_TEST_SUITE(NeuralNetwork_test)
BOOST_CHECK_THROW
(
network
.
add_connection_general
(
0
,
2
,
&
f
,
para
,
w_array
,
5
),
std
::
out_of_range
);
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_get_subnet_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
Neuron
*
n3
=
new
NeuronLinear
(
3
,
3
);
Neuron
*
n4
=
new
NeuronLinear
(
4
,
4
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_neuron
(
n3
);
network
.
add_neuron
(
n4
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
network
.
add_connection_simple
(
0
,
3
,
0
,
2.5
);
network
.
add_connection_simple
(
2
,
1
,
0
,
2.5
);
network
.
add_connection_simple
(
2
,
3
,
0
,
2.5
);
std
::
vector
<
size_t
>
input_neuron_indices
(
1
);
input_neuron_indices
.
push_back
(
0
);
std
::
vector
<
size_t
>
output_neuron_indices
(
1
);
output_neuron_indices
.
push_back
(
1
);
NeuralNetwork
*
network2
=
network
.
get_subnet
(
input_neuron_indices
,
output_neuron_indices
);
BOOST_CHECK_EQUAL
(
2
,
network2
->
add_neuron
(
n1
));
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_specify_input_neurons_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
BOOST_CHECK_EQUAL
(
0
,
network
.
get_n_inputs
());
std
::
vector
<
size_t
>
input_neuron_indices
(
1
);
input_neuron_indices
[
0
]
=
(
size_t
)
0
;
network
.
specify_input_neurons
(
input_neuron_indices
);
BOOST_CHECK_EQUAL
(
1
,
network
.
get_n_inputs
());
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_specify_output_neurons_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
BOOST_CHECK_EQUAL
(
0
,
network
.
get_n_outputs
());
std
::
vector
<
size_t
>
output_neuron_indices
(
1
);
output_neuron_indices
[
0
]
=
(
size_t
)
1
;
network
.
specify_output_neurons
(
output_neuron_indices
);
BOOST_CHECK_EQUAL
(
1
,
network
.
get_n_outputs
());
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_get_weights_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
0
,
2.5
);
BOOST_CHECK_EQUAL
(
1
,
network
.
get_n_weights
());
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_eval_single_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
-
1
,
2.5
);
std
::
vector
<
size_t
>
output_neuron_indices
(
1
);
output_neuron_indices
[
0
]
=
(
size_t
)
1
;
network
.
specify_output_neurons
(
output_neuron_indices
);
std
::
vector
<
size_t
>
input_neuron_indices
(
1
);
input_neuron_indices
[
0
]
=
(
size_t
)
0
;
network
.
specify_input_neurons
(
input_neuron_indices
);
std
::
vector
<
double
>
input
;
input
.
push_back
(
1
);
std
::
vector
<
double
>
output
;
output
.
push_back
(
1
);
network
.
eval_single
(
input
,
output
);
BOOST_CHECK_EQUAL
(
12
,
output
.
at
(
0
));
}
BOOST_AUTO_TEST_CASE
(
NeuralNetwork_eval_single_weights_test
)
{
Neuron
*
n1
=
new
NeuronLinear
(
1
,
1
);
Neuron
*
n2
=
new
NeuronLinear
(
2
,
2
);
NeuralNetwork
network
;
network
.
add_neuron
(
n1
);
network
.
add_neuron
(
n2
);
network
.
add_connection_simple
(
0
,
1
,
-
1
,
2.5
);
std
::
vector
<
size_t
>
output_neuron_indices
(
1
);
output_neuron_indices
[
0
]
=
(
size_t
)
1
;
network
.
specify_output_neurons
(
output_neuron_indices
);
std
::
vector
<
size_t
>
input_neuron_indices
(
1
);
input_neuron_indices
[
0
]
=
(
size_t
)
0
;
network
.
specify_input_neurons
(
input_neuron_indices
);
std
::
vector
<
double
>
input
;
input
.
push_back
(
1
);
std
::
vector
<
double
>
output
;
output
.
push_back
(
1
);
double
weights
=
5
;
network
.
get_n_weights
();
network
.
eval_single
(
input
,
output
,
&
weights
);
BOOST_CHECK_EQUAL
(
22
,
output
.
at
(
0
));
}
BOOST_AUTO_TEST_SUITE_END
()
\ No newline at end of file
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