def estimate(self, eppci, estimator="wls", **opt_vars): opt_method = DEFAULT_OPT_METHOD if 'opt_method' not in opt_vars else opt_vars['opt_method'] # matrix calculation object estm = get_estimator(BaseEstimatorOpt, estimator)(eppci, **opt_vars) jac = estm.create_cost_jacobian res = minimize(estm.cost_function, x0=eppci.E, method=opt_method, jac=jac, tol=self.tolerance, options={"disp":True}) self.successful = res.success if self.successful: E = res.x eppci.update_E(E) return eppci else: raise Exception("Optimiaztion failed! State Estimation not successful!")
def estimate(self, eppci: ExtendedPPCI, estimator="wls", **kwargs): self.initialize(eppci) # matrix calculation object sem = get_estimator(BaseEstimatorIRWLS, estimator)(eppci, **kwargs) current_error, cur_it = 100., 0 E = eppci.E while current_error > self.tolerance and cur_it < self.max_iterations: self.logger.debug("Starting iteration {:d}".format(1 + cur_it)) try: # residual r r = csr_matrix(sem.create_rx(E)).T # jacobian matrix H H = csr_matrix(sem.create_hx_jacobian(E)) # gain matrix G_m # G_m = H^t * Phi * H phi = csr_matrix(sem.create_phi(E)) G_m = H.T * (phi * H) # state vector difference d_E and update E d_E = spsolve(G_m, H.T * (phi * r)) E += d_E.ravel() eppci.update_E(E) # prepare next iteration cur_it += 1 current_error = np.max(np.abs(d_E)) self.logger.debug( "Current error: {:.7f}".format(current_error)) except np.linalg.linalg.LinAlgError: self.logger.error( "A problem appeared while using the linear algebra methods." "Check and change the measurement set.") return False # check if the estimation is successfull self.check_result(current_error, cur_it) # update V/delta return eppci