Skip to content
Snippets Groups Projects
Commit b3593161 authored by Van Dung NGUYEN's avatar Van Dung NGUYEN
Browse files

add tanh ANN layer

parent d5e1e3b6
No related branches found
No related tags found
No related merge requests found
......@@ -133,6 +133,25 @@ DenseLayer* ReluDenseLayer::clone() const
}
TanhDenseLayer::TanhDenseLayer(int numIn, int numOut): DenseLayer(numIn,numOut)
{
if (activationFunc!=NULL) delete activationFunc;
activationFunc = new TanhActivationFunction();
}
TanhDenseLayer::~TanhDenseLayer()
{
};
void TanhDenseLayer::print_infos() const
{
printf("tanh dense layer: nbInput = %d, nbOutput=%d\n",numInput,numOutput);
}
DenseLayer* TanhDenseLayer::clone() const
{
return new TanhDenseLayer(*this);
}
LeakyReluDenseLayer::LeakyReluDenseLayer(int numIn, int numOut, double a): DenseLayer(numIn,numOut)
{
if (activationFunc!=NULL) delete activationFunc;
......
......@@ -11,11 +11,12 @@
#define ANNUTILS_H_
#ifndef SWIG
#include "fullMatrix.h"
#include <math.h>
class activationFunction
{
public:
enum functionType{undef=0, linear=1,leakyRelu=2,relu=3};
enum functionType{undef=0, linear=1,leakyRelu=2,relu=3,tanHyperbolic=4};
public:
activationFunction(){}
activationFunction(const activationFunction& src){}
......@@ -38,6 +39,18 @@ class LinearActivationFunction: public activationFunction
virtual activationFunction* clone() const {return new LinearActivationFunction(*this);};
};
class TanhActivationFunction: public activationFunction
{
public:
TanhActivationFunction(){}
TanhActivationFunction(const TanhActivationFunction& src): activationFunction(src){}
virtual ~TanhActivationFunction(){}
virtual activationFunction::functionType getType() const {return activationFunction::tanHyperbolic;};
virtual double getVal(double x) const {return tanh(x);};
virtual double getDiff(double x) const {return 1.-x*x;};
virtual activationFunction* clone() const {return new TanhActivationFunction(*this);};
};
class LeakyReluActivationFunction : public activationFunction
{
protected:
......@@ -104,7 +117,17 @@ class ReluDenseLayer : public DenseLayer
#endif //SWIG
};
class TanhDenseLayer : public DenseLayer
{
public:
TanhDenseLayer(int numIn, int numOut);
virtual void print_infos() const;
#ifndef SWIG
TanhDenseLayer(const TanhDenseLayer& src):DenseLayer(src){}
virtual ~TanhDenseLayer();
virtual DenseLayer* clone() const;
#endif //SWIG
};
class LeakyReluDenseLayer : public DenseLayer
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment