-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparametertransform.py
149 lines (117 loc) · 3.95 KB
/
parametertransform.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
import numpy as np
class ComposeTransformation(object):
"""Combine two transformations as one."""
def __init__(self, transform1, transform2, splitat):
"""
transform1: first transformation.
transform2: second transformation.
splitat: input parameter before ``splitat`` uses ``transform1``,
and second half uses ``transform2``.
"""
self.transform1 = transform1
self.transform2 = transform2
self.splitat = splitat
def __call__(self, param):
# Apply compose transformation
p1 = param[:self.splitat]
p2 = param[self.splitat:]
tp1 = self.transform1(p1)
tp2 = self.transform2(p2)
return np.append(tp1, tp2)
def log_transform_from_model_param(param):
# Apply natural log transformation to selected parameters
out = np.copy(param)
out = np.append(
log_transform_from_ikr(out[:9]),
log_transform_from_vc(out[9:])
)
return out
def log_transform_to_model_param(param):
# Inverse of log_transform_from_model_param()
# Apply natural exp transformation to all parameters
out = np.copy(param)
out = np.append(
log_transform_to_ikr(out[:9]),
log_transform_to_vc(out[9:])
)
return out
def log_transform_from_vc(param):
# Apply natural log transformation to selected parameters
out = np.copy(param)
out[:-1] = np.log(out[:-1])
return out
def log_transform_to_vc(param):
# Inverse of log_transform_from_model_param()
# Apply natural exp transformation to selected parameters
out = np.copy(param)
out[:-1] = np.exp(out[:-1])
return out
def logit_transform_from_vc(param):
# Apply logit transformation to selected parameters
# Note: logit transformation does not have the properties of log-transform,
# i.e. if the bound span several order of magnitude, it does not re-
# scale it to log-like scale.
#TODO: maybe turn it into a class?
lower = np.array([
0.1e-3, # Rseries [GOhm]
-15.0, # Voffset [mV]
])
upper = np.array([
50e-3, # Rseries [GOhm]
15.0, # Voffset [mV]
])
out = np.copy(param)
out = np.log((out - lower) / (upper - out))
return out
def logit_transform_to_vc(param):
# Inverse of logit_transform_from_model_param()
# Apply logitic transformation to selected parameters
#TODO: maybe turn it into a class?
lower = np.array([
0.1e-3, # Rseries [GOhm]
-15.0, # Voffset [mV]
])
upper = np.array([
50e-3, # Rseries [GOhm]
15.0, # Voffset [mV]
])
out = np.copy(param)
out = (lower + upper * np.exp(out)) / (1. + np.exp(out))
return out
def log_transform_from_linleak(param):
# Apply natural log transformation to selected parameters
out = np.copy(param)
out = np.log(out)
return out
def log_transform_to_linleak(param):
# Inverse of log_transform_from_linleak()
# Apply natural exp transformation to selected parameters
out = np.copy(param)
out = np.exp(out)
return out
def log_transform_from_leak(param):
# Apply natural log transformation to selected parameters
out = np.copy(param)
out[:-1] = np.log(out[:-1])
return out
def log_transform_to_leak(param):
# Inverse of log_transform_from_model_param()
# Apply natural exp transformation to selected parameters
out = np.copy(param)
out[:-1] = np.exp(out[:-1])
return out
def log_transform_from_ikr(param):
# Apply natural log transformation to all parameters
out = np.copy(param)
out = np.log(out)
return out
def log_transform_to_ikr(param):
# Inverse of log_transform_from_model_param()
# Apply natural exp transformation to all parameters
out = np.copy(param)
out = np.exp(out)
return out
def donothing(param):
out = np.copy(param)
return out