Esempio n. 1
0
def ComputeCCA(X, Y):
    assert X.shape[0] == Y.shape[0], (X.shape, Y.shape, "Unequal number of rows")
    assert X.shape[0] > 1, (X.shape, "Must have more than 1 row")

    X = NormCenterMatrix(X)
    Y = NormCenterMatrix(Y)
    X_q, _, _ = decomp_qr.qr(X, overwrite_a=True, mode='economic', pivoting=True)
    Y_q, _, _ = decomp_qr.qr(Y, overwrite_a=True, mode='economic', pivoting=True)
    C = np.dot(X_q.T, Y_q)
    r = linalg.svd(C, full_matrices=False, compute_uv=False)
    d = min(X.shape[1], Y.shape[1])
    r = r[:d]
    r = np.minimum(np.maximum(r, 0.0), 1.0)  # remove roundoff errs
    return r.mean()
Esempio n. 2
0
def ComputeCCA(X, Y):
  assert X.shape[0] == Y.shape[0], (X.shape, Y.shape, "Unequal number of rows")
  assert X.shape[0] > 1, (X.shape, "Must have more than 1 row")
  
  X = NormCenterMatrix(X)
  Y = NormCenterMatrix(Y)
  X_q, _, _ = decomp_qr.qr(X, overwrite_a=True, mode='economic', pivoting=True)
  Y_q, _, _ = decomp_qr.qr(Y, overwrite_a=True, mode='economic', pivoting=True)
  C = np.dot(X_q.T, Y_q)
  r = linalg.svd(C, full_matrices=False, compute_uv=False)
  d = min(X.shape[1], Y.shape[1])
  r = r[:d]
  r = np.minimum(np.maximum(r, 0.0), 1.0)  # remove roundoff errs
  return r.mean()
Esempio n. 3
0
def original(**kwargs):
    embeddings = load_embeddings(**kwargs)
    lg = kwargs["lg"]
    features = load_features(lg)
    common_phonemes = embeddings.index.intersection(features.index)
    S = features.loc[common_phonemes]
    X = embeddings.loc[common_phonemes]
    assert X.shape[0] == S.shape[0], (X.shape, S.shape,
                                      "Unequal number of rows")
    assert X.shape[0] > 1, (X.shape, "Must have more than 1 row")
    X = norm_center_matrix(X)
    S = norm_center_matrix(S)
    X_q, _, _ = decomp_qr.qr(X,
                             overwrite_a=True,
                             mode="economic",
                             pivoting=True)
    S_q, _, _ = decomp_qr.qr(S,
                             overwrite_a=True,
                             mode="economic",
                             pivoting=True)
    C = np.dot(X_q.T, S_q)
    r = linalg.svd(C, full_matrices=False, compute_uv=False)
    d = min(X.shape[1], S.shape[1])
    r = r[:d]
    r = np.minimum(np.maximum(r, 0.0), 1.0)  # remove roundoff errs
    r = r.mean()
    # Write results to disk
    level, lg, name = kwargs["level"], kwargs["lg"], kwargs["name"]
    if "hidden" in kwargs:
        hyperparams = f"{kwargs['size']}-{kwargs['hidden']}"
    else:
        hyperparams = f"{kwargs['size']}-{kwargs['window']}"
    path = f"results/{level}/qvec/{lg}/{name}/{hyperparams}"
    ensure_dir(path)
    epoch = kwargs["epoch"]
    filename = os.path.join(path, f"{epoch}.txt")
    with open(filename, "w") as file:
        file.write(str(r))
    return r
Esempio n. 4
0
    def solve_linear(self, order_to_opt):
        self.computeCost(order_to_opt)
        self.computeReorderingMatrix()
        self.computeR()
        for i in range(self.D_):
            R_pf = self.R[self.n_fixed_constrains:, 0:self.n_fixed_constrains]
            R_pp = self.R[self.n_fixed_constrains:, self.n_fixed_constrains:]
            df = self.df_compact[:, i]
            R_pp_q, R_pp_r = QR.qr(R_pp)

            RHS = np.dot(R_pf, df)

            df = np.dot(np.dot(np.linalg.inv(R_pp_r), R_pp_q.T), RHS)

        return True