Skip to content

Commit

Permalink
cleaned code for AF-WLS
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopau committed Dec 18, 2024
1 parent 6f6c91d commit 97df1aa
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions pandapower/estimation/algorithm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def estimate(self, eppci: ExtendedPPCI, **kwargs):
r_inv = csr_matrix(np.diagflat(1 / eppci.r_cov ** 2))
E = eppci.E
while current_error > self.tolerance and cur_it < self.max_iterations:
self.logger.debug("Starting iteration {:d}".format(1 + cur_it))
# self.logger.debug("Starting iteration {:d}".format(1 + cur_it))
try:
# residual r
r = csr_matrix(sem.create_rx(E)).T
Expand Down Expand Up @@ -301,7 +301,7 @@ def estimate(self, eppci: ExtendedPPCI, **kwargs):
E = eppci.E
num_clusters = len(self.eppci["clusters"])
while current_error > self.tolerance and cur_it < self.max_iterations:
self.logger.debug("Starting iteration {:d}".format(1 + cur_it))
# self.logger.debug("Starting iteration {:d}".format(1 + cur_it))
try:
# residual r
r = csr_matrix(sem.create_rx(E)).T
Expand All @@ -326,21 +326,14 @@ def estimate(self, eppci: ExtendedPPCI, **kwargs):
# state vector difference d_E
d_E = spsolve(G_m, H.T * (r_inv * r))

# # Scaling of Delta_X to avoid divergence due o ill-conditioning and
# # operating conditions far from starting state variables
# current_error = np.max(np.abs(d_E))
# if current_error > 0.25:
# d_E = d_E*0.25/current_error

# Update E with d_E
E += d_E.ravel()
# eppci.update_E(E1)

# log data
current_error = np.max(np.abs(d_E))
obj_func = (r.T*r_inv*r)[0,0]
self.logger.debug("Current delta_x: {:.7f}".format(current_error))
self.logger.debug("Current objective function value: {:.1f}".format(obj_func))
# obj_func = (r.T*r_inv*r)[0,0]
# self.logger.debug("Current delta_x: {:.7f}".format(current_error))
# self.logger.debug("Current objective function value: {:.1f}".format(obj_func))

# Restore full weighting matrix
if cur_it == 0 and eppci.any_i_meas:
Expand All @@ -357,7 +350,7 @@ def estimate(self, eppci: ExtendedPPCI, **kwargs):
# check if the estimation is successfull
self.check_result(current_error, cur_it)
self.iterations = cur_it
self.obj_func = obj_func
# self.obj_func = obj_func
if self.successful:
# store variables required for chi^2 and r_N_max test:
self.R_inv = r_inv.toarray()
Expand Down

0 comments on commit 97df1aa

Please sign in to comment.