Curve

A curve is a type of Evaluator representing a mathematical function transforming one value into another. Grail’s curves operate on floating point numbers (R→R).

Each curve has to be informed which Context may be passed through it during evaluation. Contexts can take form of any built-in or user-defined data type.

A user can inherit from Curve class to create their own custom curves or they can make use of Grail’s built-in curve types.

Basic Curves

Let’s assume that x means input value.

Constant Function

Parameters
  • value

This function returns value disregarding its input.

Constant Function

Step Function

Parameters
  • threshold

  • beforeThresholdValue

  • afterThresholdValue

This function returns afterThresholdValue if x is greater than threshold. Otherwise returns beforeThresholdValue.

Step Function

Linear Function

Parameters
  • slope

  • intercept

This functions returns result of operation slope * x + intercept.

Linear Function

Power Function

Parameters
  • exponent

  • slope

  • intercept

This function takes a linear function and raises it to a power determined by exponent The result of the linear function slope * x + intercept is lower bounded by 0.

Power Function

Exponential Function

Parameters
  • base

This function raises base to the power x.

Exponential Function

Sigmoid Function

Parameters
  • range

  • slope

  • threshold

  • displacement

The sigmoid function, also known as the logistic function, is a mathematical function that has a characteristic "S-shaped" curve. It is commonly used as an activation function in neural networks.

We use the following formula:

Our sigmoid function formula
Sigmoid Function

Linearly Interpolated Curve

Simple linear interpolation applied to a set of points (from R2).

Linearly Interpolated Curve

Bezier Spline

This is a bezier spline created based on a set of waypoints and velocities coming in and out of them.

Bezier Spline

Staircase Function

Piecewise constant function with finite amount of pieces.

Staircase Function

Bounded Curves

Lowerbound

Lowerbound curves cannot return a result lesser than their lowerValue.

Lowerbound Power Function
  • C++

  • C#

auto linearCurve = std::make_shared<grail::evaluator::LinearFunction<ContextType>(someConsideration, 1, 0);
auto lowerbound = std::make_shared<grail::evaluator::LowerBound<ContextType>>(linearCurve, 0); // linearCurve bounded to range <0;inf>
var linearCurve = new LinearFunction<ContextType>(someConsideration, 1, 0);
var lowerbound = new LowerBound<ContextType>(linearCurve, 0); // linearCurve bounded to range <0;inf>

Upperbound

Upperbound curves cannot return a result greater than their upperValue.

Upperbound Power Function
  • C++

  • C#

auto someConsideration = std::make_shared<SomeConsideration>();
auto upperbound = std::make_shared<grail::evaluator::UpperBound<ContextType>>(someConsideration, 1); // someConsideration bounded to range <-inf;1>
var someConsideration = new SomeConsideration();
var upperbound = new UpperBound(someConsideration, 1); // someConsideration bounded to range <-inf;1>

Double-Sided Bound

Double-Sided Bound curves cannot return results less than lowerValue and greater than upperValue.

Double-Bounded Power Function
  • C++

  • C#

auto doubleBounded = std::make_shared<grail::evaluator::DoubleSidedBound<ContextType>>(aggregator, 0, 1); // aggregator bound to range <0;1>
var doubleBounded = new DoubleSidedBound<ContextType>(aggregator, 0, 1); //aggregator bound to range <0;1>