-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtransforms.cc
71 lines (61 loc) · 1.54 KB
/
transforms.cc
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "transforms.h"
DistParams Transform::ToModel(DistParams params) const
{
double mean = ToModel(params.mean());
double var = ToModelVar(params.var());
return DistParams(mean, var);
}
DistParams Transform::ToFabber(DistParams params) const
{
double mean = ToFabber(params.mean());
double var = ToFabberVar(params.var());
return DistParams(mean, var);
}
double Transform::ToModelVar(double val) const
{
return pow(ToModel(sqrt(val)) - ToModel(0), 2);
}
double Transform::ToFabberVar(double val) const
{
return pow(ToFabber(ToModel(0) + sqrt(val)), 2);
}
const Transform *TRANSFORM_IDENTITY()
{
static IdentityTransform t;
return &t;
}
const Transform *TRANSFORM_LOG()
{
static LogTransform t;
return &t;
}
const Transform *TRANSFORM_SOFTPLUS()
{
static SoftPlusTransform t;
return &t;
}
const Transform *TRANSFORM_FRACTIONAL()
{
static FractionalTransform t;
return &t;
}
const Transform *TRANSFORM_ABS()
{
static AbsTransform t;
return &t;
}
const Transform *GetTransform(std::string id)
{
if (id == TRANSFORM_CODE_IDENTITY)
return TRANSFORM_IDENTITY();
else if (id == TRANSFORM_CODE_LOG)
return TRANSFORM_LOG();
else if (id == TRANSFORM_CODE_SOFTPLUS)
return TRANSFORM_SOFTPLUS();
else if (id == TRANSFORM_CODE_FRACTIONAL)
return TRANSFORM_FRACTIONAL();
else if (id == TRANSFORM_CODE_ABS)
return TRANSFORM_ABS();
else
throw InvalidOptionValue("PSP_byname<n>_transform", id, "Supported transforms: I, L, S, F");
}