fixed Sigmoid function and modifications
This commit is contained in:
@@ -14,12 +14,21 @@ namespace ActivationFunction {
|
||||
|
||||
virtual ~ActivationFunction() {}
|
||||
|
||||
/**
|
||||
* @brief Returns derivation of output, it is slower than version with output as it needs to compute output
|
||||
* @param input is input of function
|
||||
*/
|
||||
inline float derivatedOutput(const float &input) {
|
||||
return derivatedOutput(input,operator()(input));
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Returns derivation of output
|
||||
* @param input is input of function
|
||||
* @param output is output of function
|
||||
* @see derivatedOutput
|
||||
*/
|
||||
virtual float derivatedOutput(const float &input,const float &output)=0;
|
||||
virtual float derivatedOutput(const float &input, const float &output) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns value of output
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace ActivationFunction {
|
||||
class Heaviside: public ActivationFunction {
|
||||
public:
|
||||
Heaviside(const float &lambdaP=1.0): lambda(lambdaP) {}
|
||||
|
||||
inline virtual float derivatedOutput(const float &,const float &) override { return 1.0; }
|
||||
inline virtual float operator()(const float &x) override { return x>lambda ? 1.0f : 0.0f; };
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace ActivationFunction {
|
||||
class HyperbolicTangent: public ActivationFunction {
|
||||
public:
|
||||
HyperbolicTangent(const float& lam=1):lambda(lam) {}
|
||||
inline virtual float derivatedOutput(const float&,const float &output) override { return lambda*(1-output*output); }
|
||||
|
||||
inline virtual float derivatedOutput(const float &,const float &output) override { return lambda*(1-output*output); }
|
||||
|
||||
inline virtual float operator()(const float &x) override { return tanh(lambda*x); };
|
||||
virtual ActivationFunction* clone() const override {
|
||||
return new HyperbolicTangent(lambda);
|
||||
|
||||
@@ -8,7 +8,9 @@ namespace ActivationFunction {
|
||||
class Linear: public ActivationFunction {
|
||||
public:
|
||||
Linear(const float &lambdaP=1.0): lambda(lambdaP) {}
|
||||
|
||||
inline virtual float derivatedOutput(const float &,const float &) override { return lambda; }
|
||||
|
||||
inline virtual float operator()(const float &x) override { return x*lambda; };
|
||||
|
||||
virtual ActivationFunction* clone() const override {
|
||||
|
||||
@@ -15,12 +15,15 @@ namespace ActivationFunction {
|
||||
class Sigmoid: public StreamingActivationFunction {
|
||||
public:
|
||||
Sigmoid(const float lambdaP = -0.5): lambda(lambdaP) {}
|
||||
inline virtual float derivatedOutput(const float&,const float &output) override { return lambda*output*(1.0f-output); }
|
||||
|
||||
inline virtual float derivatedOutput(const float &, const float &output) override { return -lambda*output*(1.0f-output); }
|
||||
|
||||
inline virtual float operator()(const float &x) override { return 1.0f / (1.0f +exp(lambda*x) ); };
|
||||
inline virtual __m128 operator()(const __m128 &x) override {
|
||||
// exp_ps is extremly slow!
|
||||
return _mm_div_ps(_mm_set1_ps(1.0),_mm_add_ps(exp_ps(_mm_mul_ps(_mm_set1_ps(lambda),x)),_mm_set1_ps(1.0)));
|
||||
}
|
||||
|
||||
virtual ActivationFunction* clone() const override {
|
||||
return new Sigmoid(lambda);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ActivationFunction {
|
||||
*/
|
||||
class StreamingActivationFunction : public ActivationFunction {
|
||||
public:
|
||||
virtual float derivatedOutput(const float &input,const float &output)=0;
|
||||
|
||||
virtual float operator()(const float &x)=0;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user