blob: 0efe7ea8c0546810dd7375b0e40f04699ae5d1ba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#pragma once
#include "accel-lookup.hpp"
#include <math.h>
namespace rawaccel {
struct sigmoid {
double accel;
double motivity;
double midpoint;
double constant;
sigmoid(const accel_args& args) :
accel(exp(args.growth_rate)),
motivity(2 * log(args.motivity)),
midpoint(log(args.midpoint)),
constant(-motivity / 2) {}
double operator()(double x) const
{
double denom = exp(accel * (midpoint - log(x))) + 1;
return exp(motivity / denom + constant);
}
};
/// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
struct motivity : binlog_lut {
using binlog_lut::operator();
motivity(const accel_args& args) :
binlog_lut(args)
{
double sum = 0;
double a = 0;
auto sigmoid_sum = [&, sig = sigmoid(args)](double b) mutable {
double interval = (b - a) / args.spaced_args.partitions;
for (int i = 1; i <= args.spaced_args.partitions; i++) {
sum += sig(a + i * interval) * interval;
}
a = b;
return sum;
};
fill([&](double x) {
double y = sigmoid_sum(x);
if (!this->transfer) y /= x;
return y;
});
}
};
}
|