Example #1
0
def estimate_M_unbiased(X):
    """Estimating M with unbiased HSIC-estimator"""
    p = X.shape[1]
    x_bw = util.meddistance(X, subsample = 1000)**2
    kx = kernel.KGauss(x_bw)
    hsic_M = hsic.HSIC_U(kx, kx)
    M_true = np.zeros((p, p))
    for i in range(p):
        for j in range(i+1):
            M_true[i, j] = hsic_M.compute(X[:,i,np.newaxis], X[:, j, np.newaxis])
            M_true[j, i] = M_true[i, j] # due to symmetry
    M = nearestPD(M_true) # positive definite approximation
    return M_true, M
Example #2
0
def estimate_H_unbiased_parallel(X, Y, discrete_output = None):
    """Parallelised estimation of H with unbiased HSIC-estimator"""
    assert Y.shape[0] == X.shape[0]
    p = X.shape[1]  
    x_bw = util.meddistance(X, subsample = 1000)**2
    kx = kernel.KGauss(x_bw)
    if discrete_output is not None:
        freq_dict1, freq_dict2 = discrete_output
        ky = KDiscrete(freq_dict1, freq_dict2)
    else:
        y_bw = util.meddistance(Y[:, np.newaxis], subsample = 1000)**2
        ky = kernel.KGauss(y_bw)
    
    hsic_H = hsic.HSIC_U(kx, ky)    
    def one_calc(i):
        return hsic_H.compute(X[:,i,np.newaxis], Y[:,np.newaxis])
    par = Parallel(n_jobs = -1)
    res = par(delayed(one_calc)(i) for i in range(p))
    return np.array(res)
Example #3
0
def estimate_H_unbiased(X, Y, discrete_output = None):
    """Estimating H with unbiased HSIC-estimator"""
    assert Y.shape[0] == X.shape[0]
    p = X.shape[1]
    # Creating X- and Y-kernels
    x_bw = util.meddistance(X, subsample = 1000)**2 # bandwith of Gaussian kernel
    kx = kernel.KGauss(x_bw)
    if discrete_output is not None:
        freq_dict1, freq_dict2 = discrete_output
        ky = KDiscrete(freq_dict1, freq_dict2)
    else:
        y_bw = util.meddistance(Y[:, np.newaxis], subsample = 1000)**2
        ky = kernel.KGauss(y_bw)
    # H estimation
    hsic_H = hsic.HSIC_U(kx, ky)
    H = np.zeros(p)
    for i in range(p):
        H[i] = hsic_H.compute(X[:,i,np.newaxis], Y[:,np.newaxis])
    return H
Example #4
0
def estimate_M_unbiased_parallel(X):
    """Parallelised estimation of M with unbiased HSIC-estimator"""
    p = X.shape[1]
    x_bw = util.meddistance(X, subsample = 1000)**2
    kx = kernel.KGauss(x_bw)
    hsic_M = hsic.HSIC_U(kx, kx)
    M_true = np.zeros((p, p))
    
    def one_calc(i, j):
        return hsic_M.compute(X[:,i,np.newaxis], X[:, j, np.newaxis])
    
    par = Parallel(n_jobs = -1)
    res = par(delayed(one_calc)(i, j) for i in range(p) for j in range(i+1))
    sp = 0
    for i in range(p):
        for j in range(i+1):
            M_true[i, j] = M_true[j, i] = res[sp + j]
        sp += i+1
    M = nearestPD(M_true) # positive definite approximation
    return M_true, M