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>
Z
zhangjinchao01 已提交
18 19

namespace paddle {
Q
qijun 已提交
20

Z
zhangjinchao01 已提交
21
struct Argument;
Q
qijun 已提交
22 23 24 25 26 27 28 29 30 31
/**
 * @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 已提交
32 33 34
class ActivationFunction {
public:
  static ActivationFunction* create(const std::string& type);
35
  static std::vector<std::string> getAllRegisteredTypes();
Z
zhangjinchao01 已提交
36 37 38 39 40

  ActivationFunction() {}

  virtual ~ActivationFunction() {}

Q
qijun 已提交
41 42 43 44 45 46 47 48 49 50
  /**
   * @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_
   */
Z
zhangjinchao01 已提交
51 52
  virtual void forward(Argument& act) = 0;

Q
qijun 已提交
53 54 55 56 57 58 59
  /**
   * @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)
   */
Z
zhangjinchao01 已提交
60 61 62 63 64 65
  virtual void backward(Argument& act) = 0;

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

}  // namespace paddle