Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
UnitStepFunction.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SINGLE_STEP_FUNCTION_H
4 #define GRAIL_SINGLE_STEP_FUNCTION_H
5 
6 #include "Curve.hh"
7 
8 namespace grail
9 {
10 namespace evaluator
11 {
12  template <typename ContextType>
17  class UnitStepFunction final : public Curve<ContextType>
18  {
19  public:
27  UnitStepFunction(std::shared_ptr<Evaluator<ContextType>> childEvaluator,
28  float threshold,
29  float beforeThresholdValue,
30  float afterThresholdValue)
31  : Curve<ContextType>{childEvaluator},
32  threshold{threshold},
33  beforeThresholdValue{beforeThresholdValue},
34  afterThresholdValue{afterThresholdValue}
35  {
36  }
37 
38  virtual float Sample(float argument) const override final
39  {
40  return argument > threshold ? afterThresholdValue : beforeThresholdValue;
41  }
42 
47  float GetThreshold() const { return threshold; }
52  float GetBeforeThresholdValue() const { return beforeThresholdValue; }
57  float GetAfterThresholdValue() const { return afterThresholdValue; }
58 
59  virtual data::EvaluatorType GetEvaluatorType() const override final { return data::EvaluatorType::CURVE_UNIT_STEP; }
60 
61  private:
62  float threshold = 0.0f;
63  float beforeThresholdValue = 0.0f;
64  float afterThresholdValue = 0.0f;
65  };
66 }
67 }
68 
69 #endif // GRAIL_SINGLE_STEP_FUNCTION_H
grail::evaluator::UnitStepFunction::UnitStepFunction
UnitStepFunction(std::shared_ptr< Evaluator< ContextType >> childEvaluator, float threshold, float beforeThresholdValue, float afterThresholdValue)
UnitStepFunction - Constructor.
Definition: UnitStepFunction.hh:27
grail::evaluator::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:22
grail::evaluator::UnitStepFunction::Sample
virtual float Sample(float argument) const override final
Sample - Transforms argument into output value depending on the type of Curve.
Definition: UnitStepFunction.hh:38
grail::evaluator::UnitStepFunction::GetAfterThresholdValue
float GetAfterThresholdValue() const
GetAfterThresholdValue.
Definition: UnitStepFunction.hh:57
grail::evaluator::UnitStepFunction::GetThreshold
float GetThreshold() const
GetThreshold.
Definition: UnitStepFunction.hh:47
grail::evaluator::UnitStepFunction::GetBeforeThresholdValue
float GetBeforeThresholdValue() const
GetBeforeThresholdValue.
Definition: UnitStepFunction.hh:52
grail::evaluator::UnitStepFunction
The UnitStepFunction class - Unit Step Function.
Definition: UnitStepFunction.hh:17
grail::evaluator::Curve
The Curve class - Defines objects transforming one value into the other.
Definition: Curve.hh:21