pt_hard_sigmoid_activation_layer.h 910 Bytes
Newer Older
Gustavo Valiente's avatar
Gustavo Valiente committed
1
/*
Gustavo Valiente's avatar
Gustavo Valiente committed
2
 * pocket-tensor (c) 2018 Gustavo Valiente gustavo.valiente.m@gmail.com
Gustavo Valiente's avatar
Gustavo Valiente committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 * Kerasify (c) 2016 Robert W. Rose
 *
 * MIT License, see LICENSE file.
 */

#ifndef PT_HARD_SIGMOID_ACTIVATION_LAYER_H
#define PT_HARD_SIGMOID_ACTIVATION_LAYER_H

#include "pt_tensor.h"
#include "pt_activation_layer.h"

namespace pt
{

class HardSigmoidActivationLayer : public ActivationLayer
{

public:
    using ActivationLayer::apply;

    HardSigmoidActivationLayer() = default;

    void apply(const Config&, Tensor& out) const final
    {
        for(FloatType& value : out)
        {
            if(value <= -FloatType(2.5))
            {
                value = 0;
            }
            else if(value >= FloatType(2.5))
            {
                value = 1;
            }
            else
            {
                value = (value * FloatType(0.2)) + FloatType(0.5);
            }
        }
    }
};

}

#endif