epyt-flow 0.6.0__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- epyt_flow/VERSION +1 -1
- epyt_flow/data/benchmarks/leakdb.py +1 -0
- epyt_flow/metrics.py +66 -4
- epyt_flow/serialization.py +33 -0
- epyt_flow/simulation/scada/scada_data.py +715 -16
- epyt_flow/simulation/scada/scada_data_export.py +5 -1
- epyt_flow/simulation/scenario_simulator.py +306 -99
- epyt_flow/simulation/sensor_config.py +49 -2
- epyt_flow/topology.py +3 -3
- epyt_flow/uncertainty/model_uncertainty.py +11 -5
- epyt_flow/uncertainty/uncertainties.py +8 -0
- epyt_flow/utils.py +69 -2
- {epyt_flow-0.6.0.dist-info → epyt_flow-0.7.1.dist-info}/METADATA +50 -7
- {epyt_flow-0.6.0.dist-info → epyt_flow-0.7.1.dist-info}/RECORD +17 -17
- {epyt_flow-0.6.0.dist-info → epyt_flow-0.7.1.dist-info}/WHEEL +1 -1
- {epyt_flow-0.6.0.dist-info → epyt_flow-0.7.1.dist-info}/LICENSE +0 -0
- {epyt_flow-0.6.0.dist-info → epyt_flow-0.7.1.dist-info}/top_level.txt +0 -0
epyt_flow/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.7.1
|
|
@@ -509,6 +509,7 @@ def load_scenarios(scenarios_id: list[int], use_net1: bool = True,
|
|
|
509
509
|
if not os.path.exists(f_inp_in):
|
|
510
510
|
with ScenarioSimulator(f_inp_in=network_config.f_inp_in) as wdn:
|
|
511
511
|
wdn.set_general_parameters(**general_params)
|
|
512
|
+
wdn.epanet_api.setTimePatternStep(hydraulic_time_step)
|
|
512
513
|
|
|
513
514
|
wdn.epanet_api.deletePatternsAll()
|
|
514
515
|
|
epyt_flow/metrics.py
CHANGED
|
@@ -3,12 +3,74 @@ This module provides different metrics for evaluation.
|
|
|
3
3
|
"""
|
|
4
4
|
import numpy as np
|
|
5
5
|
from sklearn.metrics import roc_auc_score as skelarn_roc_auc_score, f1_score as skelarn_f1_scpre, \
|
|
6
|
-
mean_absolute_error
|
|
6
|
+
mean_absolute_error, root_mean_squared_error, r2_score as sklearn_r2_score
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def r2_score(y_pred: np.ndarray, y: np.ndarray) -> float:
|
|
10
10
|
"""
|
|
11
|
-
Computes the
|
|
11
|
+
Computes the R^2 score (also called the coefficient of determination).
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
y_pred : `numpy.ndarray`
|
|
16
|
+
Predicted outputs.
|
|
17
|
+
y : `numpy.ndarray`
|
|
18
|
+
Ground truth outputs.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
`float`
|
|
23
|
+
R^2 score.
|
|
24
|
+
"""
|
|
25
|
+
return sklearn_r2_score(y, y_pred)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def running_r2_score(y_pred: np.ndarray, y: np.ndarray) -> list[float]:
|
|
29
|
+
"""
|
|
30
|
+
Computes and returns the running R^2 score -- i.e. the R^2 score for every point in time.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
y_pred : `numpy.ndarray`
|
|
35
|
+
Predicted outputs.
|
|
36
|
+
y : `numpy.ndarray`
|
|
37
|
+
Ground truth outputs.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
`list[float]`
|
|
42
|
+
The running R^2 score.
|
|
43
|
+
"""
|
|
44
|
+
r = []
|
|
45
|
+
|
|
46
|
+
for t in range(2, len(y_pred)):
|
|
47
|
+
r.append(r2_score(y_pred[:t], y[:t]))
|
|
48
|
+
|
|
49
|
+
return r
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def mean_squared_error(y_pred: np.ndarray, y: np.ndarray) -> float:
|
|
53
|
+
"""
|
|
54
|
+
Computes the Mean Squared Error (MSE).
|
|
55
|
+
|
|
56
|
+
Parameters
|
|
57
|
+
----------
|
|
58
|
+
y_pred : `numpy.ndarray`
|
|
59
|
+
Predicted outputs.
|
|
60
|
+
y : `numpy.ndarray`
|
|
61
|
+
Ground truth outputs.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
`float`
|
|
66
|
+
MSE.
|
|
67
|
+
"""
|
|
68
|
+
return root_mean_squared_error(y, y_pred)**2
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def running_mse(y_pred: np.ndarray, y: np.ndarray) -> list[float]:
|
|
72
|
+
"""
|
|
73
|
+
Computes the running Mean Squared Error (MSE) -- i.e. the MSE for every point in time.
|
|
12
74
|
|
|
13
75
|
Parameters
|
|
14
76
|
----------
|
|
@@ -39,7 +101,7 @@ def running_mse(y_pred: np.ndarray, y: np.ndarray):
|
|
|
39
101
|
r_mse = list(esq for esq in e_sq)
|
|
40
102
|
|
|
41
103
|
for i in range(1, len(y)):
|
|
42
|
-
r_mse[i] = ((i * r_mse[i - 1]) / (i + 1)) + (r_mse[i] / (i + 1))
|
|
104
|
+
r_mse[i] = float((i * r_mse[i - 1]) / (i + 1)) + (r_mse[i] / (i + 1))
|
|
43
105
|
|
|
44
106
|
return r_mse
|
|
45
107
|
|
epyt_flow/serialization.py
CHANGED
|
@@ -309,6 +309,39 @@ class JsonSerializable(Serializable):
|
|
|
309
309
|
"""
|
|
310
310
|
return my_load_from_json(data)
|
|
311
311
|
|
|
312
|
+
@staticmethod
|
|
313
|
+
def load_from_json_file(f_in: str) -> Any:
|
|
314
|
+
"""
|
|
315
|
+
Deserializes an instance of this class from a JSON file.
|
|
316
|
+
|
|
317
|
+
Parameters
|
|
318
|
+
----------
|
|
319
|
+
f_in : `str`
|
|
320
|
+
Path to the JSON file from which to deserialize the object.
|
|
321
|
+
|
|
322
|
+
Returns
|
|
323
|
+
-------
|
|
324
|
+
`Any`
|
|
325
|
+
Deserialized object.
|
|
326
|
+
"""
|
|
327
|
+
with open(f_in, "r", encoding="utf-8") as f:
|
|
328
|
+
return my_load_from_json(f.read())
|
|
329
|
+
|
|
330
|
+
def save_to_json_file(self, f_out: str) -> None:
|
|
331
|
+
"""
|
|
332
|
+
Serializes this instance and stores it in a JSON file.
|
|
333
|
+
|
|
334
|
+
Parameters
|
|
335
|
+
----------
|
|
336
|
+
f_in : `str`
|
|
337
|
+
Path to the JSON file where this serialized object will be stored.
|
|
338
|
+
"""
|
|
339
|
+
if not f_out.endswith(self.file_ext()):
|
|
340
|
+
f_out += self.file_ext()
|
|
341
|
+
|
|
342
|
+
with open(f_out, "w", encoding="utf-8") as f:
|
|
343
|
+
f.write(self.to_json())
|
|
344
|
+
|
|
312
345
|
|
|
313
346
|
def load(data: Union[bytes, BufferedIOBase]) -> Any:
|
|
314
347
|
"""
|