Skip to content
Snippets Groups Projects
Commit 02707da1 authored by Michal Kravcenko's avatar Michal Kravcenko
Browse files

preliminary work on connections, neural networks and neurons with neural...

preliminary work on connections, neural networks and neurons with neural networks as activation functions
parent c1de31dd
No related branches found
No related tags found
No related merge requests found
...@@ -5,32 +5,32 @@ ...@@ -5,32 +5,32 @@
<usages-collector id="statistics.file.extensions.open"> <usages-collector id="statistics.file.extensions.open">
<counts> <counts>
<entry key="Makefile" value="1" /> <entry key="Makefile" value="1" />
<entry key="cpp" value="29" /> <entry key="cpp" value="37" />
<entry key="f90" value="2" /> <entry key="f90" value="4" />
<entry key="h" value="27" /> <entry key="h" value="45" />
<entry key="txt" value="4" /> <entry key="txt" value="4" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.types.open"> <usages-collector id="statistics.file.types.open">
<counts> <counts>
<entry key="CMakeLists.txt" value="4" /> <entry key="CMakeLists.txt" value="4" />
<entry key="ObjectiveC" value="56" /> <entry key="ObjectiveC" value="82" />
<entry key="PLAIN_TEXT" value="3" /> <entry key="PLAIN_TEXT" value="5" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.extensions.edit"> <usages-collector id="statistics.file.extensions.edit">
<counts> <counts>
<entry key="cpp" value="2096" /> <entry key="cpp" value="2761" />
<entry key="h" value="3432" /> <entry key="h" value="5108" />
<entry key="txt" value="290" /> <entry key="txt" value="451" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.types.edit"> <usages-collector id="statistics.file.types.edit">
<counts> <counts>
<entry key="CMakeLists.txt" value="112" /> <entry key="CMakeLists.txt" value="112" />
<entry key="Doxygen file" value="39" /> <entry key="Doxygen file" value="70" />
<entry key="ObjectiveC" value="5489" /> <entry key="ObjectiveC" value="7799" />
<entry key="PLAIN_TEXT" value="178" /> <entry key="PLAIN_TEXT" value="339" />
</counts> </counts>
</usages-collector> </usages-collector>
</session> </session>
......
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) 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 NetConnection/Connection.cpp NetConnection/Connection.h Network/NeuralNetwork.cpp Network/NeuralNetwork.h Neuron/NeuronNeuralNet.cpp Neuron/NeuronNeuralNet.h)
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#include "Connection.h"
Connection::Connection(Neuron *n_in, Neuron *n_out, double edge_weight) {
this->neuron_in = n_in;
this->neuron_out = n_out;
this->weight = edge_weight;
}
//Connection::~Connection() {
//
//}
void Connection::adjust_weight(double value) {
this->weight += value;
}
Neuron* Connection::get_neuron_in() {
return this->neuron_in;
}
Neuron* Connection::get_neuron_out() {
return this->neuron_out;
}
double Connection::get_weight() {
return this->weight;
}
void Connection::pass_signal() {
this->neuron_out->adjust_potential(this->neuron_in->get_state() * this->weight);
}
void Connection::set_weight(double value) {
this->weight = value;
}
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#ifndef INC_4NEURO_CONNECTION_H
#define INC_4NEURO_CONNECTION_H
#include "../Neuron/Neuron.h"
class Neuron;
/**
*
*/
class Connection {
private:
/**
*
*/
Neuron *neuron_in = nullptr;
/**
*
*/
Neuron *neuron_out = nullptr;
/**
*
*/
double weight = 0.0;
//TODO pridat gradient
public:
/**
*
* @param[in] n_in
* @param[in] n_out
* @param[in] edge_weight
*/
Connection(Neuron *n_in, Neuron *n_out, double edge_weight = 1.0);
// Connection(Neuron *n_in, Neuron *n_out, Connection* ref_con);
/**
*
*/
~Connection()=default;
/**
*
* @param[in] value
*/
void adjust_weight(double value);
/**
*
* @param[in] value
*/
void set_weight(double value);
/**
*
* @return
*/
double get_weight();
/**
*
*/
void pass_signal();
/**
*
* @return
*/
Neuron* get_neuron_in();
/**
*
* @return
*/
Neuron* get_neuron_out();
};
#endif //INC_4NEURO_CONNECTION_H
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#include "NeuralNetwork.h"
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#ifndef INC_4NEURO_NEURALNETWORK_H
#define INC_4NEURO_NEURALNETWORK_H
enum NET_TYPE{GENERAL};
/**
*
*/
class NeuralNetwork {
private:
/**
*
*/
NET_TYPE network_type = GENERAL;
/**
*
*/
int n_neurons = 0;
public:
/**
*
* @param input
* @param expected_output
* @return
*/
//double get_error(DataSet &input, DataSet &expected_output);
};
#endif //INC_4NEURO_NEURALNETWORK_H
...@@ -6,6 +6,21 @@ Neuron::~Neuron() { ...@@ -6,6 +6,21 @@ Neuron::~Neuron() {
delete [] this->activation_function_parameters; delete [] this->activation_function_parameters;
this->activation_function_parameters = nullptr; this->activation_function_parameters = nullptr;
} }
if(this->edges_out){
for(auto& i: *this->edges_out){
delete i;
}
delete this->edges_out;
this->edges_out = nullptr;
}
if(this->edges_in){
delete this->edges_in;
this->edges_in = nullptr;
}
} }
void Neuron::adjust_potential(double input_signal) { void Neuron::adjust_potential(double input_signal) {
...@@ -43,3 +58,25 @@ void Neuron::activation_function_set_parameter(int param_idx, double value) { ...@@ -43,3 +58,25 @@ void Neuron::activation_function_set_parameter(int param_idx, double value) {
double Neuron::activation_function_get_parameter(int param_idx) { double Neuron::activation_function_get_parameter(int param_idx) {
return this->activation_function_parameters[param_idx]; return this->activation_function_parameters[param_idx];
} }
void Neuron::add_connection_in(Connection *con) {
if(!this->edges_in){
this->edges_in = new std::vector<Connection*>(0);
}
this->edges_in->push_back(con);
}
void Neuron::add_connection_out(Connection *con) {
if(!this->edges_out){
this->edges_out = new std::vector<Connection*>(0);
}
this->edges_out->push_back(con);
}
std::vector<Connection*>* Neuron::get_connections_in() {
return this->edges_in;
}
std::vector<Connection*>* Neuron::get_connections_out() {
return this->edges_out;
}
\ No newline at end of file
#ifndef NEURON_H_ /**
#define NEURON_H_ * DESCRIPTION OF THE CLASS
*
/** * @author Martin Beseda
* A file containing the mother classe representing neurons * @author Martin Mrovec
* in neural networks. * @author Michal Kravčenko
* * @date 2017 - 2018
* @author Martin Beseda */
* @author Martin Mrovec
* @author Michal Kravčenko
* @date 2017 - 2018 #ifndef NEURON_H_
*/ #define NEURON_H_
/** #include <vector>
#include "../NetConnection/Connection.h"
class Connection;
/**
* Abstract class representing a general neuron * Abstract class representing a general neuron
*/ */
class Neuron{ class Neuron{
...@@ -38,11 +42,22 @@ protected: ...@@ -38,11 +42,22 @@ protected:
*/ */
int n_activation_function_parameters = 0; int n_activation_function_parameters = 0;
/**
* A pointer to a vector containing pointers to incoming connections
*/
std::vector<Connection*> *edges_in = nullptr;
/**
* A pointer to a vector containing pointers to outgoing connections
*/
std::vector<Connection*> *edges_out = nullptr;
public: public:
/** /**
* Destructor of the Neuron object * Destructor of the Neuron object
* this level deallocates the array 'activation_function_parameters' * this level deallocates the array 'activation_function_parameters'
* also deallocates the OUTGOING connections
*/ */
virtual ~Neuron(); virtual ~Neuron();
...@@ -124,6 +139,30 @@ public: ...@@ -124,6 +139,30 @@ public:
*/ */
virtual double activation_function_get_parameter(int param_idx); virtual double activation_function_get_parameter(int param_idx);
/**
* Adds a new incoming connection with this neuron as its end-point
* @param[in] con Incoming connection
*/
virtual void add_connection_in(Connection *con) final;
/**
* Adds a new outgoing connection with this neuron as its source-point
* @param[in] con Outgoing connection
*/
virtual void add_connection_out(Connection *con) final;
/**
* Returns the pointer to the incoming connection vector
* @return
*/
virtual std::vector<Connection*>* get_connections_in( ) final;
/**
* Returns the pointer to the outgoing connection vector
* @return
*/
virtual std::vector<Connection*>* get_connections_out( ) final;
}; /* end of Neuron class */ }; /* end of Neuron class */
......
// /**
// Created by fluffymoo on 11.6.18. * DESCRIPTION OF THE CLASS
// *
* @author Martin Beseda
* @author Martin Mrovec
* @author Michal Kravčenko
* @date 2017 - 2018
*/
#ifndef INC_4NEURO_NEURONBINARY_H #ifndef INC_4NEURO_NEURONBINARY_H
#define INC_4NEURO_NEURONBINARY_H #define INC_4NEURO_NEURONBINARY_H
......
// /**
// Created by fluffymoo on 11.6.18. * DESCRIPTION OF THE CLASS
// *
* @author Martin Beseda
* @author Martin Mrovec
* @author Michal Kravčenko
* @date 2017 - 2018
*/
#ifndef INC_4NEURO_NEURONLINEAR_H #ifndef INC_4NEURO_NEURONLINEAR_H
#define INC_4NEURO_NEURONLINEAR_H #define INC_4NEURO_NEURONLINEAR_H
......
// /**
// Created by fluffymoo on 11.6.18. * DESCRIPTION OF THE CLASS
// *
* @author Martin Beseda
* @author Martin Mrovec
* @author Michal Kravčenko
* @date 2017 - 2018
*/
#ifndef INC_4NEURO_NEURONLOGISTIC_H #ifndef INC_4NEURO_NEURONLOGISTIC_H
#define INC_4NEURO_NEURONLOGISTIC_H #define INC_4NEURO_NEURONLOGISTIC_H
......
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#include "NeuronNeuralNet.h"
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 13.6.18 -
*/
#ifndef INC_4NEURO_NEURONNEURALNET_H
#define INC_4NEURO_NEURONNEURALNET_H
class NeuronNeuralNet {
};
#endif //INC_4NEURO_NEURONNEURALNET_H
// /**
// Created by fluffymoo on 11.6.18. * DESCRIPTION OF THE CLASS
// *
* @author Martin Beseda
* @author Martin Mrovec
* @author Michal Kravčenko
* @date 2017 - 2018
*/
#ifndef INC_4NEURO_NEURONTANH_H #ifndef INC_4NEURO_NEURONTANH_H
#define INC_4NEURO_NEURONTANH_H #define INC_4NEURO_NEURONTANH_H
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment