-
Notifications
You must be signed in to change notification settings - Fork 47
/
C.py
318 lines (252 loc) · 8.93 KB
/
C.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
"""
Constants
=========
Package-wide consistent constant definitions.
"""
from enum import Enum
from typing import Callable, Literal, Tuple, Union
###############################################################################
# ENSEMBLE
PREDICTOR = 'predictor'
PREDICTION_ID = 'prediction_id'
PREDICTION_RESULTS = 'prediction_results'
PREDICTION_ARRAYS = 'prediction_arrays'
PREDICTION_SUMMARY = 'prediction_summary'
HISTORY = 'history'
OPTIMIZE = 'optimize'
SAMPLE = 'sample'
MEAN = 'mean'
MEDIAN = 'median'
STANDARD_DEVIATION = 'std'
PERCENTILE = 'percentile'
SUMMARY = 'summary'
WEIGHTED_SIGMA = 'weighted_sigma'
X_NAMES = 'x_names'
NX = 'n_x'
X_VECTOR = 'x_vectors'
NVECTORS = 'n_vectors'
VECTOR_TAGS = 'vector_tags'
ENSEMBLE_TYPE = 'ensemble_type'
PREDICTIONS = 'predictions'
LOWER_BOUND = 'lower_bound'
UPPER_BOUND = 'upper_bound'
PREEQUILIBRATION_CONDITION_ID = 'preequilibrationConditionId'
SIMULATION_CONDITION_ID = 'simulationConditionId'
COLOR_HIT_BOTH_BOUNDS = [0.6, 0.0, 0.0, 0.9]
COLOR_HIT_ONE_BOUND = [0.95, 0.6, 0.0, 0.9]
COLOR_HIT_NO_BOUNDS = [0.0, 0.8, 0.0, 0.9]
class EnsembleType(Enum):
"""Specifies different ensemble types."""
ensemble = 1
sample = 2
unprocessed_chain = 3
###############################################################################
# OBJECTIVE
MODE_FUN = 'mode_fun' # mode for function values
MODE_RES = 'mode_res' # mode for residuals
ModeType = Literal['mode_fun', 'mode_res'] # type for `mode` argument
FVAL = 'fval' # function value
FVAL0 = 'fval0' # function value at start
GRAD = 'grad' # gradient
HESS = 'hess' # Hessian
HESSP = 'hessp' # Hessian vector product
RES = 'res' # residual
SRES = 'sres' # residual sensitivities
RDATAS = 'rdatas' # returned simulated data sets
TIME = 'time' # time
N_FVAL = 'n_fval' # number of function evaluations
N_GRAD = 'n_grad' # number of gradient evaluations
N_HESS = 'n_hess' # number of Hessian evaluations
N_RES = 'n_res' # number of residual evaluations
N_SRES = 'n_sres' # number of residual sensitivity evaluations
START_TIME = 'start_time' # start time
X = 'x'
X0 = 'x0'
ID = 'id'
###############################################################################
# HIERARCHICAL
INNER_PARAMETERS = 'inner_parameters'
INNER_RDATAS = 'inner_rdatas'
PARAMETER_TYPE = 'parameterType'
X_INNER_OPT = 'x_inner_opt'
class InnerParameterType(str, Enum):
"""Specifies different inner parameter types."""
OFFSET = 'offset'
SCALING = 'scaling'
SIGMA = 'sigma'
OPTIMAL_SCALING = 'optimal_scaling'
SPLINE = 'spline'
DUMMY_INNER_VALUE = {
InnerParameterType.OFFSET: 0.0,
InnerParameterType.SCALING: 1.0,
InnerParameterType.SIGMA: 1.0,
InnerParameterType.OPTIMAL_SCALING: 0.0,
InnerParameterType.SPLINE: 0.0,
}
INNER_PARAMETER_BOUNDS = {
InnerParameterType.OFFSET: {
LOWER_BOUND: -float('inf'),
UPPER_BOUND: float('inf'),
},
InnerParameterType.SCALING: {
LOWER_BOUND: -float('inf'),
UPPER_BOUND: float('inf'),
},
InnerParameterType.SIGMA: {
LOWER_BOUND: 0,
UPPER_BOUND: float('inf'),
},
InnerParameterType.OPTIMAL_SCALING: {
LOWER_BOUND: -float('inf'),
UPPER_BOUND: float('inf'),
},
InnerParameterType.SPLINE: {
LOWER_BOUND: -float('inf'),
UPPER_BOUND: float('inf'),
},
}
###############################################################################
# OPTIMAL SCALING
# Should go to PEtab constants at some point
MEASUREMENT_CATEGORY = 'measurementCategory'
MEASUREMENT_TYPE = 'measurementType'
CENSORING_BOUNDS = 'censoringBounds'
ORDINAL = 'ordinal'
CENSORED = 'censored'
LEFT_CENSORED = 'left-censored'
RIGHT_CENSORED = 'right-censored'
INTERVAL_CENSORED = 'interval-censored'
CENSORING_TYPES = [LEFT_CENSORED, RIGHT_CENSORED, INTERVAL_CENSORED]
REDUCED = 'reduced'
STANDARD = 'standard'
MAXMIN = 'max-min'
MAX = 'max'
METHOD = 'method'
REPARAMETERIZED = 'reparameterized'
INTERVAL_CONSTRAINTS = 'interval_constraints'
MIN_GAP = 'min_gap'
OPTIMAL_SCALING_OPTIONS = [
METHOD,
REPARAMETERIZED,
INTERVAL_CONSTRAINTS,
MIN_GAP,
]
CAT_LB = 'cat_lb'
CAT_UB = 'cat_ub'
NUM_CATEGORIES = 'num_categories'
NUM_DATAPOINTS = 'num_datapoints'
SURROGATE_DATA = 'surrogate_data'
NUM_INNER_PARAMS = 'num_inner_params'
LB_INDICES = 'lb_indices'
UB_INDICES = 'ub_indices'
QUANTITATIVE_IXS = 'quantitative_ixs'
QUANTITATIVE_DATA = 'quantitative_data'
NUM_CONSTR_FULL = 'num_constr_full'
C_MATRIX = 'C_matrix'
W_MATRIX = 'W_matrix'
W_DOT_MATRIX = 'W_dot_matrix'
SCIPY_SUCCESS = 'success'
SCIPY_FUN = 'fun'
SCIPY_X = 'x'
###############################################################################
# SPLINE APPROXIMATION
MEASUREMENT_TYPE = 'measurementType'
NONLINEAR_MONOTONE = 'nonlinear_monotone'
SPLINE_RATIO = 'spline_ratio'
MIN_DIFF_FACTOR = 'min_diff_factor'
SPLINE_APPROXIMATION_OPTIONS = [SPLINE_RATIO, MIN_DIFF_FACTOR]
MIN_SIM_RANGE = 1e-16
###############################################################################
# HISTORY
HISTORY = "history"
TRACE = "trace"
N_ITERATIONS = "n_iterations"
MESSAGES = "messages"
MESSAGE = "message"
EXITFLAG = "exitflag"
TRACE_SAVE_ITER = "trace_save_iter"
SUFFIXES_CSV = ["csv"]
SUFFIXES_HDF5 = ["hdf5", "h5"]
SUFFIXES = SUFFIXES_CSV + SUFFIXES_HDF5
SPLINE_PAR_TYPE = 'spline'
N_SPLINE_PARS = 'n_spline_pars'
DATAPOINTS = 'datapoints'
MIN_DATAPOINT = 'min_datapoint'
MAX_DATAPOINT = 'max_datapoint'
EXPDATA_MASK = 'expdata_mask'
CURRENT_SIMULATION = 'current_simulation'
NOISE_PARAMETERS = 'noise_parameters'
###############################################################################
# PRIOR
LIN = 'lin' # linear
LOG = 'log' # logarithmic to basis e
LOG10 = 'log10' # logarithmic to basis 10
UNIFORM = 'uniform'
PARAMETER_SCALE_UNIFORM = 'parameterScaleUniform'
NORMAL = 'normal'
PARAMETER_SCALE_NORMAL = 'parameterScaleNormal'
LAPLACE = 'laplace'
PARAMETER_SCALE_LAPLACE = 'parameterScaleLaplace'
LOG_UNIFORM = 'logUniform'
LOG_NORMAL = 'logNormal'
LOG_LAPLACE = 'logLaplace'
###############################################################################
# PREDICT
OUTPUT_IDS = 'output_ids' # data member in PredictionConditionResult
PARAMETER_IDS = 'x_names' # data member in PredictionConditionResult
TIMEPOINTS = 'timepoints' # data member in PredictionConditionResult
OUTPUT = 'output' # field in the return dict of AmiciPredictor
OUTPUT_SENSI = 'output_sensi' # field in the return dict of AmiciPredictor
OUTPUT_WEIGHT = 'output_weight' # field in the return dict of AmiciPredictor
OUTPUT_SIGMAY = 'output_sigmay' # field in the return dict of AmiciPredictor
# separator in the conditions_ids between preequilibration and simulation
# condition
CONDITION_SEP = '::'
AMICI_T = 't' # return field in amici simulation result
AMICI_X = 'x' # return field in amici simulation result
AMICI_SX = 'sx' # return field in amici simulation result
AMICI_Y = 'y' # return field in amici simulation result
AMICI_SY = 'sy' # return field in amici simulation result
AMICI_LLH = 'llh' # return field in amici simulation result
AMICI_STATUS = 'status' # return field in amici simulation result
AMICI_SIGMAY = 'sigmay' # return field in amici simulation result
AMICI_SSIGMAY = 'ssigmay' # return field in amici simulation result
AMICI_SSIGMAZ = 'ssigmaz' # return field in amici simulation result
CONDITION = 'condition'
CONDITION_IDS = 'condition_ids'
CSV = 'csv' # return file format
H5 = 'h5' # return file format
###############################################################################
# SELECT
TYPE_POSTPROCESSOR = Callable[["ModelProblem"], None] # noqa: F821
###############################################################################
# VISUALIZE
LEN_RGB = 3 # number of elements in an RGB color
LEN_RGBA = 4 # number of elements in an RGBA color
RGB = Tuple[(float,) * LEN_RGB] # typing of an RGB color
RGBA = Tuple[(float,) * LEN_RGBA] # typing of an RGBA color
RGB_RGBA = Union[RGB, RGBA] # typing of an RGB or RGBA color
RGBA_MIN = 0 # min value for an RGBA element
RGBA_MAX = 1 # max value for an RGBA element
RGBA_ALPHA = 3 # zero-indexed fourth element in RGBA
RGBA_WHITE = (RGBA_MAX, RGBA_MAX, RGBA_MAX, RGBA_MAX) # white as an RGBA color
RGBA_BLACK = (RGBA_MIN, RGBA_MIN, RGBA_MIN, RGBA_MAX) # black as an RGBA color
# optimizer history
TRACE_X_TIME = 'time'
TRACE_X_STEPS = 'steps'
# supported values to plot on x-axis
TRACE_X = (TRACE_X_TIME, TRACE_X_STEPS)
TRACE_Y_FVAL = 'fval'
TRACE_Y_GRADNORM = 'gradnorm'
# supported values to plot on y-axis
TRACE_Y = (TRACE_Y_FVAL, TRACE_Y_GRADNORM)
# parameter indices
FREE_ONLY = 'free_only' # only estimated parameters
ALL = 'all' # all parameters, also for start indices
# start indices
ALL_CLUSTERED = 'all_clustered' # best + all that are in a cluster of size > 1
FIRST_CLUSTER = 'first_cluster' # all starts that belong to the first cluster
###############################################################################
# ENVIRONMENT VARIABLES
PYPESTO_MAX_N_STARTS: str = "PYPESTO_MAX_N_STARTS"
PYPESTO_MAX_N_SAMPLES: str = "PYPESTO_MAX_N_SAMPLES"