-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossover.cpp
50 lines (42 loc) · 1002 Bytes
/
Crossover.cpp
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
#include "stdafx.h"
#include "Crossover.h"
// y = (exp(x*a)-1)/(exp(th * a) - 1)
// y' = a * (exp(x*a)) / (exp(th * a) - 1)
Crossover::Crossover(double _a, double _th)
{
a = abs(_a);
th = abs(_th);
// y' = 1
// a * (exp(x*a)) / (exp(th * a) - 1) = 1
// a * (exp(x*a)) = (exp(th * a) - 1)
// exp(x*a) = (exp(th * a) - 1) / a
// x * a = ln ((exp(th * a) - 1) / a)
// x = ln ((exp(th * a) - 1) / a) / a
double temp = log((exp(th * a) - 1) / a) / a; // logº¯Êýµ×Ϊe
if (temp < 0.0) {
theta_b = theta = 0.0;
}
else {
theta = temp;
theta_b = (exp(temp * a) - 1) / (exp(th * a) - 1) - temp;
}
}
Crossover::~Crossover()
{
}
double Crossover::GetSample(double input)
{
double ret;
uint64 sign = *((uint64*)(&input)) & 0x8000000000000000ULL;
double absinput = abs(input);
if (absinput < theta) {
ret = (exp(absinput * a) - 1) / (exp(th * a) - 1);
*((uint64*)(&ret)) |= sign;
return ret;
}
else {
ret = absinput + theta_b;
*((uint64*)(&ret)) |= sign;
return ret;
}
}