ActivationFunction.h 2.0 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once
#include <string>
17
#include <vector>
18
#include "paddle/utils/Status.h"
Z
zhangjinchao01 已提交
19 20

namespace paddle {
Q
qijun 已提交
21

Z
zhangjinchao01 已提交
22
struct Argument;
Q
qijun 已提交
23 24 25 26 27 28 29 30 31 32
/**
 * @brief Activation function is a function that transforms a set of input
 * signals into an output signals. The purpose of the activation function
 * is to introduce non-liearilty into the network.
 *
 * @note Common activation function are provieded, including linear,
 * sigmoid, softmax, sequence_max, relu, brelu, tanh, stanh,
 * softrelu, abs, square, exponential.
 *
 */
Z
zhangjinchao01 已提交
33 34 35
class ActivationFunction {
public:
  static ActivationFunction* create(const std::string& type);
36
  static std::vector<std::string> getAllRegisteredTypes();
Z
zhangjinchao01 已提交
37 38 39 40 41

  ActivationFunction() {}

  virtual ~ActivationFunction() {}

Q
qijun 已提交
42 43 44 45 46 47 48 49 50 51
  /**
   * @brief Foward propagation
   *
   * act.value <- f(act.value),
   * where f is the activation function.
   * Suppose that before calling forward(), act.value is x and
   * after forward() is called, act.value is y, then y = f(x).
   *
   * Usually, act is Layer::output_
   */
52
  virtual Status __must_check forward(Argument& act) = 0;
Z
zhangjinchao01 已提交
53

Q
qijun 已提交
54 55 56 57 58 59 60
  /**
   * @brief Backward propagaion
   *
   * x and y are defined in the above comment for forward().
   * - Before calling backward(), act.grad = dE / dy, where E is the error/cost
   * - After backward() returns, act.grad = dE / dx = (dE/dy) * (dy/dx)
   */
61
  virtual Status __must_check backward(Argument& act) = 0;
Z
zhangjinchao01 已提交
62 63 64 65 66

  virtual const std::string& getName() const = 0;
};

}  // namespace paddle