modified SSE code building
This commit is contained in:
@@ -18,7 +18,7 @@ namespace 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) {
|
||||
inline float derivatedOutput(const float &input) const {
|
||||
return derivatedOutput(input,operator()(input));
|
||||
};
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace ActivationFunction {
|
||||
* @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) const=0;
|
||||
|
||||
/**
|
||||
* @brief Returns value of output
|
||||
* @param x is input of function
|
||||
*/
|
||||
virtual float operator()(const float &x)=0;
|
||||
virtual float operator()(const float &x) const=0;
|
||||
|
||||
/**
|
||||
* @brief Function returns clone of object
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace 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; };
|
||||
inline virtual float derivatedOutput(const float &,const float &) const override { return 1.0; }
|
||||
inline virtual float operator()(const float &x) const override { return x>lambda ? 1.0f : 0.0f; };
|
||||
|
||||
virtual ActivationFunction* clone() const override {
|
||||
return new Heaviside(lambda);
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace 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) const override { return lambda*(1-output*output); }
|
||||
|
||||
inline virtual float operator()(const float &x) override { return tanh(lambda*x); };
|
||||
inline virtual float operator()(const float &x) const override { return tanh(lambda*x); };
|
||||
virtual ActivationFunction* clone() const override {
|
||||
return new HyperbolicTangent(lambda);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace ActivationFunction {
|
||||
public:
|
||||
Linear(const float &lambdaP=1.0): lambda(lambdaP) {}
|
||||
|
||||
inline virtual float derivatedOutput(const float &,const float &) override { return lambda; }
|
||||
inline virtual float derivatedOutput(const float &,const float &) const override { return lambda; }
|
||||
|
||||
inline virtual float operator()(const float &x) override { return x*lambda; };
|
||||
inline virtual float operator()(const float &x) const override { return x*lambda; };
|
||||
|
||||
virtual ActivationFunction* clone() const override {
|
||||
return new Linear(lambda);
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace ActivationFunction {
|
||||
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) const 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 {
|
||||
inline virtual float operator()(const float &x) const override { return 1.0f / (1.0f +exp(lambda*x) ); };
|
||||
|
||||
inline virtual __m128 operator()(const __m128 &x) const 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)));
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ namespace ActivationFunction {
|
||||
class StreamingActivationFunction : public ActivationFunction {
|
||||
public:
|
||||
|
||||
virtual float operator()(const float &x)=0;
|
||||
virtual float operator()(const float &x) const=0;
|
||||
|
||||
/**
|
||||
* @brief Returns value of four outputs
|
||||
* @param x is float[4], in every array value can be stored
|
||||
*/
|
||||
virtual __m128 operator()(const __m128 &x)=0;
|
||||
virtual __m128 operator()(const __m128 &x) const=0;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user