diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1cf911e21..ed83cb2d1 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -28,9 +28,9 @@
-
+
-
+
@@ -71,7 +71,7 @@
@@ -433,29 +433,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -645,6 +622,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -720,7 +715,7 @@
-
+
@@ -728,11 +723,11 @@
+
+
+
-
-
-
@@ -1488,8 +1483,6 @@
-
-
1656059954202
@@ -1834,7 +1827,7 @@
1698766404661
-
+
@@ -1862,13 +1855,6 @@
-
+
@@ -1911,8 +1898,7 @@
-
-
+
@@ -2681,7 +2667,7 @@
-
+
diff --git a/src/GridCalEngine/Simulations/PowerFlow/Formulations/pf_generalized_formulation.py b/src/GridCalEngine/Simulations/PowerFlow/Formulations/pf_generalized_formulation.py
index 3469c5efa..f83389e11 100644
--- a/src/GridCalEngine/Simulations/PowerFlow/Formulations/pf_generalized_formulation.py
+++ b/src/GridCalEngine/Simulations/PowerFlow/Formulations/pf_generalized_formulation.py
@@ -2513,16 +2513,16 @@ def compute_f(self, x: Vec) -> Vec:
]
# Print index blocks of f
- print('Lengths: ')
- print(len(self.i_k_p), len(self.i_k_q), len(loss_vsc), len(loss_hvdc), len(inj_hvdc),
- len(Pf_cbr), len(Pt_cbr), len(Qf_cbr), len(Qt_cbr))
-
- print('Pf set: ', self.cbr_pf_set)
- print('f errors: ')
- # Get indices of troublesome values
- for i, ff in enumerate(_f):
- if abs(ff) > 0.5:
- print(i, ff)
+ # print('Lengths: ')
+ # print(len(self.i_k_p), len(self.i_k_q), len(loss_vsc), len(loss_hvdc), len(inj_hvdc),
+ # len(Pf_cbr), len(Pt_cbr), len(Qf_cbr), len(Qt_cbr))
+ #
+ # print('Pf set: ', self.cbr_pf_set)
+ # print('f errors: ')
+ # # Get indices of troublesome values
+ # for i, ff in enumerate(_f):
+ # if abs(ff) > 0.5:
+ # print(i, ff)
return _f
diff --git a/src/GridCalEngine/basic_structures.py b/src/GridCalEngine/basic_structures.py
index c94784a1e..12459cc56 100644
--- a/src/GridCalEngine/basic_structures.py
+++ b/src/GridCalEngine/basic_structures.py
@@ -141,10 +141,8 @@ def expectation(self) -> float | complex:
Returns the CDF expected value (AKA the mean)
:return: expectation
"""
- if self.iscomplex:
- return np.sum(self.arr * self.prob)
- else:
- return np.sum(self.arr * self.prob)
+ n = len(self.arr)
+ return np.sum(self.arr) * (1 / n)
def plot(self, plt, LINEWIDTH: int, ax=None):
"""
diff --git a/src/tests/test_CDF.py b/src/tests/test_CDF.py
new file mode 100644
index 000000000..54f4e0fe4
--- /dev/null
+++ b/src/tests/test_CDF.py
@@ -0,0 +1,13 @@
+import numpy as np
+from numpy import random
+import GridCalEngine as gce
+
+def test_CDF_expectation():
+
+ x = random.normal(4, 1, size=20)
+
+ assert np.allclose(x.mean(), gce.CDF(x).expectation(), atol=1e-5)
+
+ x = random.rand(200)
+
+ assert np.allclose(x.mean(), gce.CDF(x).expectation(), atol=1e-5)