Skip to content

Commit 3bf06b2

Browse files
committed
Merge branch 'devel'
2 parents a7c184e + 59e8446 commit 3bf06b2

4 files changed

Lines changed: 54 additions & 57 deletions

File tree

.idea/workspace.xml

Lines changed: 29 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GridCalEngine/Simulations/PowerFlow/Formulations/pf_generalized_formulation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,16 +2513,16 @@ def compute_f(self, x: Vec) -> Vec:
25132513
]
25142514

25152515
# Print index blocks of f
2516-
print('Lengths: ')
2517-
print(len(self.i_k_p), len(self.i_k_q), len(loss_vsc), len(loss_hvdc), len(inj_hvdc),
2518-
len(Pf_cbr), len(Pt_cbr), len(Qf_cbr), len(Qt_cbr))
2519-
2520-
print('Pf set: ', self.cbr_pf_set)
2521-
print('f errors: ')
2522-
# Get indices of troublesome values
2523-
for i, ff in enumerate(_f):
2524-
if abs(ff) > 0.5:
2525-
print(i, ff)
2516+
# print('Lengths: ')
2517+
# print(len(self.i_k_p), len(self.i_k_q), len(loss_vsc), len(loss_hvdc), len(inj_hvdc),
2518+
# len(Pf_cbr), len(Pt_cbr), len(Qf_cbr), len(Qt_cbr))
2519+
#
2520+
# print('Pf set: ', self.cbr_pf_set)
2521+
# print('f errors: ')
2522+
# # Get indices of troublesome values
2523+
# for i, ff in enumerate(_f):
2524+
# if abs(ff) > 0.5:
2525+
# print(i, ff)
25262526

25272527
return _f
25282528

src/GridCalEngine/basic_structures.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ def expectation(self) -> float | complex:
141141
Returns the CDF expected value (AKA the mean)
142142
:return: expectation
143143
"""
144-
if self.iscomplex:
145-
return np.sum(self.arr * self.prob)
146-
else:
147-
return np.sum(self.arr * self.prob)
144+
n = len(self.arr)
145+
return np.sum(self.arr) * (1 / n)
148146

149147
def plot(self, plt, LINEWIDTH: int, ax=None):
150148
"""

src/tests/test_CDF.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
from numpy import random
3+
import GridCalEngine as gce
4+
5+
def test_CDF_expectation():
6+
7+
x = random.normal(4, 1, size=20)
8+
9+
assert np.allclose(x.mean(), gce.CDF(x).expectation(), atol=1e-5)
10+
11+
x = random.rand(200)
12+
13+
assert np.allclose(x.mean(), gce.CDF(x).expectation(), atol=1e-5)

0 commit comments

Comments
 (0)