Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MolDyn
lib4neuro
Commits
3c0ec38b
Commit
3c0ec38b
authored
Jun 11, 2018
by
Michal Kravcenko
Browse files
added a constant file and more neuron classes
parent
6d7ca604
Changes
11
Hide whitespace changes
Inline
Side-by-side
.idea/usage.statistics.xml
View file @
3c0ec38b
...
...
@@ -5,32 +5,32 @@
<usages-collector
id=
"statistics.file.extensions.open"
>
<counts>
<entry
key=
"Makefile"
value=
"1"
/>
<entry
key=
"cpp"
value=
"
8
"
/>
<entry
key=
"cpp"
value=
"
15
"
/>
<entry
key=
"f90"
value=
"1"
/>
<entry
key=
"h"
value=
"
5
"
/>
<entry
key=
"txt"
value=
"
2
"
/>
<entry
key=
"h"
value=
"
13
"
/>
<entry
key=
"txt"
value=
"
4
"
/>
</counts>
</usages-collector>
<usages-collector
id=
"statistics.file.types.open"
>
<counts>
<entry
key=
"CMakeLists.txt"
value=
"
2
"
/>
<entry
key=
"ObjectiveC"
value=
"
13
"
/>
<entry
key=
"CMakeLists.txt"
value=
"
4
"
/>
<entry
key=
"ObjectiveC"
value=
"
28
"
/>
<entry
key=
"PLAIN_TEXT"
value=
"2"
/>
</counts>
</usages-collector>
<usages-collector
id=
"statistics.file.extensions.edit"
>
<counts>
<entry
key=
"cpp"
value=
"
731
"
/>
<entry
key=
"h"
value=
"2
161
"
/>
<entry
key=
"txt"
value=
"20
8
"
/>
<entry
key=
"cpp"
value=
"
1455
"
/>
<entry
key=
"h"
value=
"2
890
"
/>
<entry
key=
"txt"
value=
"2
5
0"
/>
</counts>
</usages-collector>
<usages-collector
id=
"statistics.file.types.edit"
>
<counts>
<entry
key=
"CMakeLists.txt"
value=
"1
09
"
/>
<entry
key=
"Doxygen file"
value=
"3
1
"
/>
<entry
key=
"ObjectiveC"
value=
"
2861
"
/>
<entry
key=
"PLAIN_TEXT"
value=
"
99
"
/>
<entry
key=
"CMakeLists.txt"
value=
"1
12
"
/>
<entry
key=
"Doxygen file"
value=
"3
8
"
/>
<entry
key=
"ObjectiveC"
value=
"
4307
"
/>
<entry
key=
"PLAIN_TEXT"
value=
"
138
"
/>
</counts>
</usages-collector>
</session>
...
...
CMakeLists.txt
View file @
3c0ec38b
cmake_minimum_required
(
VERSION 3.0
)
project
(
NeuronLib
)
set
(
NeuronLib_VERSION_MAJOR 0
)
set
(
NeuronLib_VERSION_MINOR 1
)
message
(
"Before enable language"
)
enable_language
(
Fortran
)
if
(
WIN32
)
message
(
"cmake for "
${
CMAKE_Fortran_COMPILER
}
)
set
(
CMAKE_FORTRAN_COMPILER
${
CMAKE_Fortran_COMPILER
}
)
project
(
4Neuro
FORTRAN
)
project
(
4Neuro
)
else
()
project
(
4Neuro
)
endif
()
...
...
src/CMakeLists.txt
View file @
3c0ec38b
add_library
(
neuron SHARED Neuron/neuron.cpp Neuron/neuron.h Neuron/NeuronBinary.cpp Neuron/NeuronBinary.h Neuron/NeuronLinear.cpp Neuron/NeuronLinear.h Neuron/NeuronLogistic.cpp Neuron/NeuronLogistic.h Neuron/NeuronTanh.cpp Neuron/NeuronTanh.h
)
add_library
(
neuron SHARED Neuron/neuron.cpp Neuron/neuron.h Neuron/NeuronBinary.cpp Neuron/NeuronBinary.h Neuron/NeuronLinear.cpp Neuron/NeuronLinear.h Neuron/NeuronLogistic.cpp Neuron/NeuronLogistic.h Neuron/NeuronTanh.cpp Neuron/NeuronTanh.h
constants.h
)
src/Neuron/NeuronBinary.cpp
View file @
3c0ec38b
...
...
@@ -17,6 +17,5 @@ void NeuronBinary::activate() {
else
{
this
->
state
=
0.0
;
}
}
src/Neuron/NeuronBinary.h
View file @
3c0ec38b
...
...
@@ -20,7 +20,7 @@ public:
* @param threshold Denotes when the neuron is activated
* When neuron potential exceeds 'threshold' value it becomes excited
*/
explicit
NeuronBinary
(
double
threshold
);
explicit
NeuronBinary
(
double
threshold
=
0.0
);
/**
* Performs the activation function and stores the result into the 'state' property
...
...
src/Neuron/NeuronLinear.cpp
View file @
3c0ec38b
...
...
@@ -3,3 +3,32 @@
//
#include "NeuronLinear.h"
NeuronLinear
::
NeuronLinear
(
double
a
,
double
b
)
{
this
->
activation_function_parameters
=
new
double
[
2
];
this
->
activation_function_parameters
[
0
]
=
a
;
this
->
activation_function_parameters
[
1
]
=
b
;
}
void
NeuronLinear
::
activate
()
{
this
->
state
=
this
->
activation_function_parameters
[
0
]
*
this
->
potential
+
this
->
activation_function_parameters
[
1
];
}
double
NeuronLinear
::
activation_function_get_partial_derivative
(
int
param_idx
)
{
if
(
param_idx
==
0
){
return
this
->
potential
;
}
else
{
return
1.0
;
}
}
double
NeuronLinear
::
activation_function_get_derivative
()
{
return
this
->
activation_function_parameters
[
0
];
}
\ No newline at end of file
src/Neuron/NeuronLinear.h
View file @
3c0ec38b
...
...
@@ -5,9 +5,43 @@
#ifndef INC_4NEURO_NEURONLINEAR_H
#define INC_4NEURO_NEURONLINEAR_H
#include "neuron.h"
class
NeuronLinear
{
/**
* Linear neuron class - uses activation function in the form f(x)=a*x + b,
* 'x' being the neuron's potential
*/
class
NeuronLinear
:
Neuron
{
public:
/**
* Constructs the object of the Linear neuron with activation function
* f(x) = a * x + b
* @param a First coefficient, stored in activation_function_parameters[0]
* @param b Second coefficient, stored in activation_function_parameters[1]
*/
explicit
NeuronLinear
(
double
a
=
0.0
,
double
b
=
0.0
);
/**
* Evaluates 'a*x + b' and stores the result into the 'state' property
*/
void
activate
()
override
;
/**
* Calculates the partial derivative of the activation function
* f(x) = a*x + b
* @param param_idx Index of the parameter to calculate derivative of
* @return Partial derivative of the activation function according to the
* 'param_idx'-th parameter. For 'param_idx'=0 returns 'x', otherwise
* returns 1
*/
double
activation_function_get_partial_derivative
(
int
param_idx
)
override
;
/**
* Calculates d/dx of (a*x + b)
* @return a
*/
double
activation_function_get_derivative
()
override
;
};
...
...
src/Neuron/NeuronLogistic.cpp
View file @
3c0ec38b
...
...
@@ -2,4 +2,59 @@
// Created by fluffymoo on 11.6.18.
//
#include "NeuronLogistic.h"
NeuronLogistic
::
NeuronLogistic
(
double
a
,
double
b
)
{
this
->
activation_function_parameters
=
new
double
[
2
];
this
->
activation_function_parameters
[
0
]
=
a
;
this
->
activation_function_parameters
[
1
]
=
b
;
}
void
NeuronLogistic
::
activate
()
{
double
a
=
this
->
activation_function_parameters
[
0
];
double
b
=
this
->
activation_function_parameters
[
1
];
double
x
=
this
->
potential
;
double
ex
=
std
::
pow
(
E
,
b
-
x
);
this
->
state
=
std
::
pow
(
1.0
+
ex
,
-
a
);
}
double
NeuronLogistic
::
activation_function_get_partial_derivative
(
int
param_idx
)
{
double
a
=
this
->
activation_function_parameters
[
0
];
double
b
=
this
->
activation_function_parameters
[
1
];
double
x
=
this
->
potential
;
if
(
param_idx
==
0
){
double
ex
=
std
::
pow
(
E
,
b
-
x
);
double
exa
=
-
std
::
pow
(
ex
+
1.0
,
-
a
);
return
exa
*
std
::
log
(
ex
+
1.0
);
}
else
{
double
ex
=
std
::
pow
(
E
,
b
-
x
);
double
ex2
=
std
::
pow
(
ex
+
1.0
,
-
a
-
1.0
);
return
-
a
*
ex
*
ex2
;
}
}
double
NeuronLogistic
::
activation_function_get_derivative
()
{
double
a
=
this
->
activation_function_parameters
[
0
];
double
b
=
this
->
activation_function_parameters
[
1
];
double
x
=
this
->
potential
;
double
ex
=
std
::
pow
(
E
,
b
-
x
);
double
ex2
=
std
::
pow
(
ex
+
1.0
,
-
a
-
1.0
);
return
a
*
ex
*
ex2
;
}
\ No newline at end of file
src/Neuron/NeuronLogistic.h
View file @
3c0ec38b
...
...
@@ -5,9 +5,38 @@
#ifndef INC_4NEURO_NEURONLOGISTIC_H
#define INC_4NEURO_NEURONLOGISTIC_H
#include <cmath>
#include "neuron.h"
#include "../constants.h"
class
NeuronLogistic
{
class
NeuronLogistic
:
Neuron
{
/**
* Constructs the object of the Logistic neuron with activation function
* f(x) = (1 + e^(-x + b))^(-a)
* @param a First coefficient, stored in activation_function_parameters[0]
* @param b Second coefficient, stored in activation_function_parameters[1]
*/
explicit
NeuronLogistic
(
double
a
=
0.0
,
double
b
=
0.0
);
/**
* Evaluates '(1 + e^(-x + b))^(-a)' and stores the result into the 'state' property
*/
void
activate
()
override
;
/**
* Calculates the partial derivative of the activation function
* f(x) = (1 + e^(-x + b))^(-a)
* @param param_idx Index of the parameter to calculate derivative of
* @return Partial derivative of the activation function according to the
* 'param_idx'-th parameter.
*/
double
activation_function_get_partial_derivative
(
int
param_idx
)
override
;
/**
* Calculates d/dx of (1 + e^(-x + b))^(-a)
* @return a * e^(b - x) * [e^(b - x) + 1]^(-a)
*/
double
activation_function_get_derivative
()
override
;
};
...
...
src/Neuron/neuron.h
View file @
3c0ec38b
...
...
@@ -96,6 +96,12 @@ public:
*/
virtual
double
activation_function_get_partial_derivative
(
int
param_idx
)
=
0
;
/**
* Calculates the derivative with respect to the argument, ie the 'potential'
* @return f'(x), where 'f(x)' is the activation function and 'x' = 'potential'
*/
virtual
double
activation_function_get_derivative
(
)
=
0
;
/**
* Adjusts the parameter with index 'param_idx' of the activation function
* by the value prescribed by 'value'
...
...
src/constants.h
0 → 100644
View file @
3c0ec38b
//
// Created by fluffymoo on 11.6.18.
//
#ifndef INC_4NEURO_CONSTANTS_H
#define INC_4NEURO_CONSTANTS_H
#define E 2.7182818284590
#define PI 3.14159265358979323846
#endif //INC_4NEURO_CONSTANTS_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment