(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
SigmoidFunction.hh
1 #ifndef GRAIL_SIGMOID_FUNCTION_H
2 #define GRAIL_SIGMOID_FUNCTION_H
3 
4 #include "Curve.hh"
5 #include <cmath>
6 
7 namespace grail
8 {
9  namespace curves
10  {
11  template <typename ContextType>
16  class SigmoidFunction final : public Curve<ContextType>
17  {
18  public:
27  SigmoidFunction(std::shared_ptr<utility::Evaluator<ContextType>> childEvaluator,
28  float range, float slope, float threshold, float displacement)
29  : Curve<ContextType>{childEvaluator},
30  range(range), slope(slope), threshold(threshold), displacement(displacement)
31  {
32  }
33 
34  virtual float Sample(float argument) const override final
35  {
36  float x = slope * (argument - threshold);
37  if (x < 0)
38  {
39  float exp_x = std::exp(x);
40  return ((range * exp_x) / (1 + exp_x)) + displacement;
41  }
42  else
43  {
44  return (range / (1 + std::exp(-x))) + displacement;
45  }
46  }
47 
52  float GetRange() const { return range; }
57  float GetSlope() const { return slope; }
62  float GetThreshold() const { return threshold; }
67  float GetDisplacement() const { return displacement; }
68 
69  EvaluatorType GetEvaluatorType() const override final { return EvaluatorType::CURVE_SIGMOID; }
70 
71  private:
72  float range = 0.0f;
73  float slope = 0.0f;
74  float threshold = 0.0f;
75  float displacement = 0.0f;
76  };
77  }
78 }
79 
80 #endif // GRAIL_SIGMOID_FUNCTION_H
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21
The SigmoidFunction class - Sigmoid function.
Definition: SigmoidFunction.hh:17
float GetDisplacement() const
GetDisplacement.
Definition: SigmoidFunction.hh:67
float GetRange() const
GetRange.
Definition: SigmoidFunction.hh:52
float GetThreshold() const
GetThreshold.
Definition: SigmoidFunction.hh:62
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: SigmoidFunction.hh:34
float GetSlope() const
GetSlope.
Definition: SigmoidFunction.hh:57
SigmoidFunction(std::shared_ptr< utility::Evaluator< ContextType >> childEvaluator, float range, float slope, float threshold, float displacement)
SigmoidFunction - Constructor.
Definition: SigmoidFunction.hh:27
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21