-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport_math_func.py
81 lines (62 loc) · 1.64 KB
/
support_math_func.py
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
72
73
74
75
76
77
78
79
80
81
import math
import numpy as np
"""
logit10(x)
Function transforming interval [0,1] to [-Inf, Inf] using logit transformation.
"""
def logit10(x):
return math.log(x / (1.0 - x), 10)
"""
logistic10(x::Float64)
Function transforming interval [-Inf, Inf] to [0,1] using logistic transformation.
Inverse function for [`logit10`](@ref).
"""
def logistic10(x):
10**(x) / (10**(x) + 1.0)
"""
scaling(x::Float64, scale::Symbol = :direct)
Transforms values from specific scale to range [-Inf, Inf] based on option.
## Return
Transformed value.
## Arguments
* `x`: input value.
* `scale`: transformation type: `:direct, :log, :logit`.
"""
def scaling(x, scale="direct"):
if x == np.inf * (-1):
return np.inf * (-1)
if scale == "direct":
return x
elif scale == "log":
return np.log10(x)
elif scale == "logit":
return np.logit10(x)
else:
raise ValueError(scale, "scale type is not supported")
"""
unscaling(x::Float64, scale::Symbol = :direct)
Transforms values from [-Inf, Inf] to specific scale based on option. Inverse function
for [`scaling`](@ref).
## Return
Transformed value.
## Arguments
* `x`: input value.
* `scale`: transformation type: `:direct, :log, :logit`.
"""
def unscaling(x, scale="direct"):
"""
print("---UNSCALING---")
print(x)
print(scale)
print("---UNSCALING---")
"""
if x is None:
return None
if scale == "direct":
return x
elif scale == "log":
return np.power(10, x)
elif scale == "logit":
return logistic10(x)
else:
raise BaseException("scale type is not supported") #DomainError