Something went wrong on our end
-
Michal Kravcenko authored
# Conflicts: # .gitlab-ci.yml # CMakeLists.txt # FindBoost.cmake # build.sh # build_scripts/windows/win_VS_build_x64_debug.bat # include/4neuro.h # src/CMakeLists.txt # src/DataSet/DataSet.h # src/General/ExprtkWrapper.h # src/LearningMethods/ParticleSwarm.h # src/NetConnection/ConnectionFunctionGeneral.h # src/NetConnection/ConnectionFunctionIdentity.h # src/Network/NeuralNetwork.h # src/Network/NeuralNetworkSum.h # src/Neuron/Neuron.h # src/Neuron/NeuronBinary.h # src/Neuron/NeuronConstant.h # src/Neuron/NeuronLinear.h # src/Neuron/NeuronLogistic.h # src/examples/CMakeLists.txt # src/message.h # src/tests/CMakeLists.txt
Michal Kravcenko authored# Conflicts: # .gitlab-ci.yml # CMakeLists.txt # FindBoost.cmake # build.sh # build_scripts/windows/win_VS_build_x64_debug.bat # include/4neuro.h # src/CMakeLists.txt # src/DataSet/DataSet.h # src/General/ExprtkWrapper.h # src/LearningMethods/ParticleSwarm.h # src/NetConnection/ConnectionFunctionGeneral.h # src/NetConnection/ConnectionFunctionIdentity.h # src/Network/NeuralNetwork.h # src/Network/NeuralNetworkSum.h # src/Neuron/Neuron.h # src/Neuron/NeuronBinary.h # src/Neuron/NeuronConstant.h # src/Neuron/NeuronLinear.h # src/Neuron/NeuronLogistic.h # src/examples/CMakeLists.txt # src/message.h # src/tests/CMakeLists.txt
ErrorFunctions.h 2.62 KiB
//
// Created by martin on 7/15/18.
//
#ifndef INC_4NEURO_ERRORFUNCTION_H
#define INC_4NEURO_ERRORFUNCTION_H
#include "../Network/NeuralNetwork.h"
#include "../DataSet/DataSet.h"
enum ErrorFunctionType{
ErrorFuncMSE
};
class ErrorFunction {
public:
/**
*
* @param weights
* @return
*/
virtual double eval(std::vector<double>* weights = nullptr) = 0;
/**
*
* @return
*/
virtual size_t get_dimension();
/**
*
* @param params
* @param grad
*/
virtual void calculate_error_gradient(std::vector<double> ¶ms, std::vector<double> &grad, double alpha = 1.0 ) = 0;
/**
*
* @return
*/
virtual std::vector<double>* get_parameters( ) = 0;
/**
* //TODO delete after gradient learning is debugged
* @return
*/
virtual DataSet* get_dataset() = 0;
protected:
/**
*
*/
size_t dimension = 0;
/**
*
*/
NeuralNetwork* net = nullptr;
};
class MSE : public ErrorFunction {
public:
/**
* Constructor for single neural network
* @param net
* @param ds
*/
MSE(NeuralNetwork* net, DataSet* ds);
/**
*
* @param weights
* @return
*/
double eval(std::vector<double>* weights = nullptr) override;
/**
*
* @param params
* @param grad
*/
void calculate_error_gradient(std::vector<double> ¶ms, std::vector<double> &grad, double alpha = 1.0 ) override;
/**
*
* @return
*/
std::vector<double>* get_parameters( ) override;
DataSet* get_dataset() override {
return this->ds;
};
private:
DataSet* ds;
};
class ErrorSum : public ErrorFunction{
public:
/**
*
*/
ErrorSum();
/**
*
*/
~ErrorSum();
/**
*
* @param weights
* @return
*/
double eval(std::vector<double>* weights = nullptr) override;
/**
*
* @param F
*/
void add_error_function( ErrorFunction *F, double alpha = 1.0 );
/**
*
* @return
*/
size_t get_dimension( ) override;
/**
*
* @param params
* @param grad
*/
void calculate_error_gradient( std::vector<double> ¶ms, std::vector<double> &grad, double alpha = 1.0 ) override;
/**
*
* @return
*/
std::vector<double>* get_parameters( ) override;
DataSet* get_dataset() override {
return this->summand->at( 0 )->get_dataset();
};
private:
std::vector<ErrorFunction*>* summand;
std::vector<double> *summand_coefficient;
};
#endif //INC_4NEURO_ERRORFUNCTION_H