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

get new layers

parent 4c8ab939
Branches
Tags
No related merge requests found
...@@ -113,6 +113,26 @@ void DenseLayer::predict(const fullMatrix<double>& y0, fullMatrix<double>& y1, b ...@@ -113,6 +113,26 @@ void DenseLayer::predict(const fullMatrix<double>& y0, fullMatrix<double>& y1, b
} }
}; };
ReluDenseLayer::ReluDenseLayer(int numIn, int numOut): DenseLayer(numIn,numOut)
{
if (activationFunc!=NULL) delete activationFunc;
activationFunc = new ReluActivationFunction();
}
ReluDenseLayer::~ReluDenseLayer()
{
};
void ReluDenseLayer::print_infos() const
{
printf("relu dense layer: nbInput = %d, nbOutput=%d\n",numInput,numOutput);
}
DenseLayer* ReluDenseLayer::clone() const
{
return new ReluDenseLayer(*this);
}
LeakyReluDenseLayer::LeakyReluDenseLayer(int numIn, int numOut, double a): DenseLayer(numIn,numOut) LeakyReluDenseLayer::LeakyReluDenseLayer(int numIn, int numOut, double a): DenseLayer(numIn,numOut)
{ {
if (activationFunc!=NULL) delete activationFunc; if (activationFunc!=NULL) delete activationFunc;
...@@ -201,6 +221,8 @@ void ArtificialNN::addLayer(int index, const DenseLayer& layer) ...@@ -201,6 +221,8 @@ void ArtificialNN::addLayer(int index, const DenseLayer& layer)
{ {
// we add pointer to existing object instead of creating a new one // we add pointer to existing object instead of creating a new one
_allLayers[index] = layer.clone(); _allLayers[index] = layer.clone();
Msg::Info("add layer: %d",index);
_allLayers[index]->print_infos();
} }
}; };
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
class activationFunction class activationFunction
{ {
public: public:
enum functionType{undef=0, linear=1,leakyRelu=2}; enum functionType{undef=0, linear=1,leakyRelu=2,relu=3};
public: public:
activationFunction(){} activationFunction(){}
activationFunction(const activationFunction& src){} activationFunction(const activationFunction& src){}
...@@ -52,6 +52,19 @@ class LeakyReluActivationFunction : public activationFunction ...@@ -52,6 +52,19 @@ class LeakyReluActivationFunction : public activationFunction
virtual double getDiff(double x) const {if (x>=0) return 1; else return alpha;}; virtual double getDiff(double x) const {if (x>=0) return 1; else return alpha;};
virtual activationFunction* clone() const {return new LeakyReluActivationFunction(*this);}; virtual activationFunction* clone() const {return new LeakyReluActivationFunction(*this);};
}; };
class ReluActivationFunction : public activationFunction
{
public:
ReluActivationFunction(){}
ReluActivationFunction(const ReluActivationFunction& src): activationFunction(src){}
virtual ~ReluActivationFunction(){}
virtual activationFunction::functionType getType() const {return activationFunction::relu;};
virtual double getVal(double x) const {if (x>=0) return x; else return x;};
virtual double getDiff(double x) const {if (x>=0) return 1; else return 0;};
virtual activationFunction* clone() const {return new ReluActivationFunction(*this);};
};
#endif //SWIG #endif //SWIG
class DenseLayer class DenseLayer
...@@ -80,6 +93,20 @@ class DenseLayer ...@@ -80,6 +93,20 @@ class DenseLayer
#endif //SWIG #endif //SWIG
}; };
class ReluDenseLayer : public DenseLayer
{
public:
ReluDenseLayer(int numIn, int numOut);
void print_infos() const;
#ifndef SWIG
ReluDenseLayer(const ReluDenseLayer& src):DenseLayer(src){}
virtual ~ReluDenseLayer();
virtual DenseLayer* clone() const;
#endif //SWIG
};
class LeakyReluDenseLayer : public DenseLayer class LeakyReluDenseLayer : public DenseLayer
{ {
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment