Util
auto_adjust_model_params(model, results, weights=None, params=None)
Adjusts limits of model params. If params
is specified only those are adjusted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
GenericModel
|
Model to optimize. |
required |
results |
list[list[float]]
|
Results from running the model. |
required |
weights |
list[float]
|
Results weights. Defaults to None. |
None
|
params |
list[str]
|
Names of params to optimice. Defaults to None. |
None
|
Source code in compartmental/util.py
get_best_parameters(params, log_diff, save_percentage)
Retuns the best save_percentage
% params
of the simulations given their log_diff
with real data.
Source code in compartmental/util.py
get_model_sample_trajectory(model, *args, **kargs)
Executes the model with n_simulations = 1
and n_executions = 1
.
Returns all the intermediate states and the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
GenericModel
|
Model to execute. |
required |
Returns:
Type | Description |
---|---|
list[list[float]], list[list[float]]
|
Tuple of all states history and corresponding params. |
Source code in compartmental/util.py
get_model_sample_trajectory_with_diff_to_reference(model, reference, *args, **kargs)
Executes the model with n_simulations = 1
and n_executions = 1
.
Returns all the intermediate states and the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
GenericModel
|
Model to execute. |
required |
reference |
list
|
Reference to compare with. |
required |
Returns:
Type | Description |
---|---|
list[list[float]], list[list[float]], float
|
Tuple of all states history and corresponding params and the difference. |
Source code in compartmental/util.py
get_percentiles_from_results(model, results, p_minor=5, p_max=95, weights=None, *args, **kargs)
Returns an array of percentils p_minor=5
, median and p_max=95
of the given model and results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
GenericModel
|
Model used to generate the |
required |
results |
list[list[float]]
|
Result parameters of |
required |
p_minor |
int
|
Smaller percentile. Defaults to 5. |
5
|
p_max |
int
|
Bigger percentile. Defaults to 95. |
95
|
weights |
list[float] | None
|
Results weights. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list[int, int, list[float]]
|
First index represents the reference defined in |
Source code in compartmental/util.py
get_trajecty_selector(model, results, weights, reference=None, *args, show_only_reference=False)
Creates an interactive plot and histograms of results. When a histogram is clicked the value of that parameter changes to the selected value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
GenericModel
|
Model used for the trajectory. |
required |
results |
list[list[float]]
|
Results from running the model. |
required |
weights |
list[float]
|
Results weights. Defaults to None. |
required |
reference |
list[list[float]]
|
If give, is printed to the trajectory. Defaults to None. |
None
|
show_only_reference |
boolean
|
If |
False
|
Returns:
Type | Description |
---|---|
dict[str, float]
|
Dictionary with the manually selected params. |
Source code in compartmental/util.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
|
load_parameters(file)
Loads parameters from file with the same format as save_parameters
and save_parameters_no_diff
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
str
|
Filename or path to file. |
required |
Returns:
Type | Description |
---|---|
list[list[float]]
|
Parameters array. First index selects the column (parameter). |
Source code in compartmental/util.py
offset_array(array, offset)
Offsets an array by the given amount.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
list
|
array to be changed. |
required |
offset |
int
|
offset to apply to the given array. |
required |
Source code in compartmental/util.py
progress_bar(prefix, progress, total, *, sufix='', end='\r', len=10)
Prints a progress bar on standar output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
Prefix to the progress bar. |
required |
progress |
int | float
|
Progress value. |
required |
total |
int | float
|
Total progess posible. |
required |
sufix |
str
|
Sufix to the progess bar. Defaults to "". |
''
|
end |
str
|
End value, set to |
'\r'
|
len |
int
|
Length of progress bar. Defaults to 10. |
10
|
Source code in compartmental/util.py
save_parameters(file, params_names, params, log_diff, *, execution_number=0)
Saves the parameters with the given names including the diff column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
str
|
Filename or path to file. |
required |
params_names |
list[str]
|
Name of parameters. |
required |
params |
list[list[float]]
|
Parameters array. |
required |
log_diff |
list[float]
|
Diff array. |
required |
execution_number |
int
|
Number of the execution. If |
0
|
Source code in compartmental/util.py
save_parameters_no_diff(file, params_names, params, *, execution_number=0)
Saves the parameters with the given names without the diff column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
str
|
Filename or path to file. |
required |
params_names |
list[str]
|
Name of parameters. |
required |
params |
list[list[float]]
|
Parameters array. |
required |
execution_number |
int
|
Number of the execution. If |
0
|
Source code in compartmental/util.py
weighted_quantile(values, quantiles, sample_weight=None, values_sorted=False, old_style=False)
From: https://stackoverflow.com/a/29677616
Very close to numpy.percentile, but supports weights. NOTE: quantiles should be in [0, 100]!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
list[float]
|
Array with data. |
required |
quantiles |
list[float]
|
Array with many quantiles needed. |
required |
sample_weight |
list[float]
|
Array of the same length as |
None
|
values_sorted |
bool
|
If True, then will avoid sorting of initial array. |
False
|
old_style |
bool
|
If True, will correct output to be consistent with numpy.percentile. |
False
|
Returns:
Type | Description |
---|---|
list[float]
|
Array with computed quantiles. |