Пример #1
0
def mp_static_gl((theta, z0, u0, emp_cov_mat, rho, lambd, eta, dimension,
                  max_iter)):

    # Multiprocessing worker computing the
    # Static Graphical Lasso for given subset
    # of blocks

    try:
        iteration = 0
        stopping_criteria = False
        theta_pre = []
        while iteration < max_iter and stopping_criteria is False:
            """ Theta update """
            a = z0 - u0
            at = a.transpose()
            m = eta * (a + at) / 2 - emp_cov_mat
            d, q = np.linalg.eig(m)
            qt = q.transpose()
            sqrt_matrix = np.sqrt(d**2 + 4 / eta * np.ones(dimension))
            diagonal = np.diag(d) + np.diag(sqrt_matrix)
            theta = np.real(eta / 2 * np.dot(np.dot(q, diagonal), qt))
            """ Z-update """
            z0 = pf.soft_threshold_odd(theta + u0, lambd, rho)
            """ U-update """
            u0 += theta - z0
            """ Check stopping criteria """
            if iteration > 0:
                dif = theta - theta_pre
                fro_norm = np.linalg.norm(dif)
                if fro_norm < 1e-5:
                    stopping_criteria = True
            theta_pre = list(theta)
            iteration += 1
    except Exception as e:
        traceback.print_exc()
        raise e
    return theta
Пример #2
0
 def z0_update(self):
     self.z0s = [
         pf.soft_threshold_odd(self.thetas[i] + self.u0s[i], self.lambd,
                               self.rho) for i in range(self.blocks)
     ]
Пример #3
0
     sqrt_matrix = np.sqrt(d**2 + 4 / eta * np.ones(dimension))
     diagonal = np.diag(d) + np.diag(sqrt_matrix)
     thetas[i] = np.real(eta / 2 * np.dot(np.dot(q, diagonal), qt))
     final_thetas[j] = thetas[i]
 """ Send first Theta value to previous process,
     Receive last Theta value from next process """
 if prev_pipe is not None:
     prev_pipe.send(thetas[0])
 if next_pipe is not None:
     received = next_pipe.recv()
     if received is None:
         break
     thetas[-1] = received
 """ Z0 Update """
 for i in range(nn):
     z0s[i] = pf.soft_threshold_odd(thetas[i] + u0s[i], lambd, rho)
 """ Z1-Z2 Update """
 if pen_func == "perturbed_node":
     for i in range(1, n):
         z1s[i - 1], z2s[i] = pf.perturbed_node(
             thetas[i - 1], thetas[i], u1s[i - 1], u2s[i], beta,
             rho, ct, cc)
 else:
     for i in range(1, n):
         a = thetas[i] - thetas[i - 1] + u2s[i] - u1s[i - 1]
         e = getattr(pf, pen_func)(a, beta, rho)
         summ = thetas[i] + thetas[i - 1] + u2s[i] + u1s[i - 1]
         z1s[i - 1] = 0.5 * (summ - e)
         z2s[i] = 0.5 * (summ + e)
 """ U0 Update """
 for i in range(nn):