Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
SanPen committed Jan 8, 2025
2 parents a7c184e + 59e8446 commit 3bf06b2
Showing 4 changed files with 54 additions and 57 deletions.
72 changes: 29 additions & 43 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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

6 changes: 2 additions & 4 deletions src/GridCalEngine/basic_structures.py
Original file line number Diff line number Diff line change
@@ -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):
"""
13 changes: 13 additions & 0 deletions src/tests/test_CDF.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3bf06b2

Please sign in to comment.