Beispiel #1
0
    def _reduce(self, omega, xi, method=0):
        """
        Reduce the size of information matrix and vector.
        """

        print("reducing...")
        t1 = time()

        n = 3*(self.T + 1)

        omega_til = np.zeros((n,n))
        xi_til = np.zeros(n)
        omega_til += omega[:n, :n]
        xi_til += xi[:n]

        if method == 0:
            omega_til -= omega[:n, n:] @ inv(omega[n:, n:]) @ omega[n:, :n]
            xi_til -= omega[:n, n:] @ inv(omega[n:, n:]) @ xi[n:]
        elif method == 1:
            for j in range(self.nfeature):
                jrange = [n+2*j, n+2*j+1]
                alpha = omega[:n, :][:, jrange] @ inv(omega[jrange, :][:, jrange])
                omega_til -= alpha @ omega[:n, :][:, jrange].T
                xi_til -= alpha @ xi[jrange]
        elif method == 2:
            omega_csc = sparse.csc_matrix(omega)
            inv_omega = inv_sparse(omega_csc[n:,n:])
            omega_til -= omega_csc[:n,n:].dot(inv_omega.dot(omega_csc[n:,:n])).toarray()
            xi_til -= omega_csc[:n, n:].dot(inv_omega).toarray() @ xi[n:]

        t2 = time()
        print("done\n")
        self.time_reduce = t2 - t1

        return omega_til, xi_til
Beispiel #2
0
def _calc_zbus(ppc):
    Ybus = ppc["internal"]["Ybus"]
    sparsity = Ybus.nnz / Ybus.shape[0]**2
    if sparsity < 0.002:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            ppc["internal"]["Zbus"] = inv_sparse(Ybus).toarray()
    else:
        ppc["internal"]["Zbus"] = inv(Ybus.toarray())
Beispiel #3
0
def _calc_zbus(net, ppci):
    try:
        Ybus = ppci["internal"]["Ybus"]
        sparsity = Ybus.nnz / Ybus.shape[0]**2
        if sparsity < 0.002:
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                ppci["internal"]["Zbus"] = inv_sparse(Ybus).toarray()
        else:
            ppci["internal"]["Zbus"] = inv(Ybus.toarray())
    except Exception as e:
        _clean_up(net, res=False)
        raise (e)
Beispiel #4
0
    def _solve(self, omega_til, xi_til, omega, xi, method=0):
        """
        Estimate the track and map.
        """
        print("solving...")
        t1 = time()

        n = 3 * (self.T + 1)

        if method == 0:
            mu = np.zeros_like(xi)
            sigma = inv(omega_til)
            mu[:n] = sigma @ xi_til
            sigma_m = inv(omega[n:, n:])
            mu[n:] = sigma_m @ (xi[n:] - omega[n:, :n] @ mu[:n])
        elif method == 1:
            mu = np.zeros_like(xi)
            sigma = inv(omega_til)
            mu[:n] = sigma @ xi_til
            for j in range(self.nfeature):
                self.tau[j] = np.array(self.tau[j])
                jrange = [n+2*j, n+2*j+1]
                sigma_j = inv(omega[jrange, :][:, jrange])
                tau = np.hstack((3*self.tau[j], 3*self.tau[j]+1, 3*self.tau[j]+2))
                mu[n+2*j:n+2*j+2] = sigma_j @ (xi[jrange] - omega[jrange, :][:, tau] @ mu[tau])
        elif method == 2:
            mu = np.zeros_like(xi)
            omega_csc = sparse.csc_matrix(omega)
            omega_til_csc = sparse.csc_matrix(omega_til)
            sigma = inv_sparse(omega_til_csc)
            mu[:n] = sigma @ xi_til
            sigma_m = inv_sparse(omega_csc[n:,n:])
            mu[n:] = sigma_m @ (xi[n:] - omega_csc[n:,:n].dot(mu[:n]))

        t2 = time()
        self.time_solve = t2 - t1
        print("done\n")

        return mu, sigma