def estimate(self, eppci: ExtendedPPCI, **kwargs): self.initialize(eppci) # matrix calculation object sem = BaseAlgebra(eppci) current_error, cur_it = 100., 0 # invert covariance matrix 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)) 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 * R^-1 * H G_m = H.T * (r_inv * H) # state vector difference d_E # d_E = G_m^-1 * (H' * R^-1 * r) d_E = spsolve(G_m, H.T * (r_inv * r)) # Update E with d_E 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) if self.successful: # store variables required for chi^2 and r_N_max test: self.R_inv = r_inv.toarray() self.Gm = G_m.toarray() self.r = r.toarray() self.H = H.toarray() # create h(x) for the current iteration self.hx = sem.create_hx(eppci.E) return eppci
def estimate(self, eppci, **kwargs): if "estimator" in kwargs and kwargs["estimator"].lower( ) != "lav": # pragma: no cover self.logger.warning( "LP Algorithm supports only LAV Estimator!! Set to LAV!!") # matrix calculation object sem = BaseAlgebra(eppci) 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 = sem.create_rx(E) # jacobian matrix H H = sem.create_hx_jacobian(E) # state vector difference d_E # d_E = G_m^-1 * (H' * R^-1 * r) d_E = self.solve_lp(H, E, r) E += d_E 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: # pragma: no cover 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) return eppci