Exemplo n.º 1
0
def MSE_compute_1_5(model, n, ITER):
    res1 = np.zeros(ITER)
    res2 = np.zeros(ITER)
    for j in range(ITER):
        random.seed(j)
        if model == 1:
            cov = [[1, 0.9], [0.9, 1]]
            beta = 0.9
            p_con, p_dis = 0.5, 0.5
            gt = -p_con * 0.5 * log(np.linalg.det(cov)) + p_dis * (
                log(2) + beta * log(beta) + (1 - beta) *
                log(1 - beta)) - p_con * log(p_con) - p_dis * log(p_dis)
            x_con, y_con = nr.multivariate_normal([0, 0], cov,
                                                  int(n * p_con)).T
            x_dis = nr.binomial(1, 0.5, int(n * p_dis))
            y_dis = (x_dis + nr.binomial(1, 1 - beta, int(n * p_dis))) % 2
            x_dis, y_dis = 2 * x_dis - np.ones(int(
                n * p_dis)), 2 * y_dis - np.ones(int(n * p_dis))
            x = np.concatenate((x_con, x_dis)).reshape((n, 1))
            y = np.concatenate((y_con, y_dis)).reshape((n, 1))
        if model == 2:
            m = 5
            gt = log(m) - 0.8 * log(2)
            x = nr.randint(m, size=n)
            z = nr.uniform(0, 2, size=n)
            y = x + z
        if model == 3:
            m = 5
            gt = 5 * (log(m) - 0.8 * log(2))
            x = nr.randint(m, size=5 * n)
            z = nr.uniform(0, 2, size=5 * n)
            y = x + z
            x = x.reshape((n, 5))
            y = y.reshape((n, 5))
        if model == 4:
            p = 0.15
            gt = (1 - p) * 0.3012
            x = nr.exponential(1, size=n)
            z = nr.binomial(1, 1 - p, size=n)
            w = nr.poisson(x, size=n)
            y = z * w
        if model == 5:
            p = 0
            gt = (1 - p) * 0.3012
            x = nr.exponential(1, size=n)
            z = nr.binomial(1, 1 - p, size=n)
            w = nr.poisson(x, size=n)
            y = z * w
        res1[j] = (mixed.Mixed_KSG(x, y) - gt) * (mixed.Mixed_KSG(x, y) - gt)
        res2[j] = (mixed.KSG(x, y) - gt) * (mixed.KSG(x, y) - gt)
    MSE_Mixed_KSG = np.mean(res1)
    MSE_copulaksg = np.mean(res2)
    return [MSE_Mixed_KSG, MSE_copulaksg]
Exemplo n.º 2
0
def estimate_mi(X, y, label, est_H_Y, norm_factor):

    if label == "IRF":
        frac_eval = 0.3
        irf = CalibratedClassifierCV(
            base_estimator=RandomForestClassifier(n_estimators=60),
            method='isotonic',
            cv=5)
        # X_train, y_train, X_eval, y_eval = split_train_eval(X, y, frac_eval)
        X_train, X_eval, y_train, y_eval = train_test_split(
            X, y, test_size=frac_eval)
        irf.fit(X_train, y_train)
        p = irf.predict_proba(X_eval)
        return (est_H_Y - np.mean(entropy(p.T, base=np.exp(1)))) / norm_factor
    elif label == "UF":
        return (est_H_Y - uf(np.array(X), y)) / norm_factor
    elif label == "KSG":
        return mixed.KSG(X, y.reshape(-1, 1)) / norm_factor
    elif label == "Mixed KSG":
        return mixed.Mixed_KSG(X, y.reshape(-1, 1)) / norm_factor
    elif label == "UF2":
        return (est_H_Y - uf2(np.array(X), y)) / norm_factor
    elif label == "UF3":
        return UncertaintyForest().fit(X,
                                       y).estimate_mutual_info() / norm_factor
    else:
        raise ValueError("Unrecognized Label!")
Exemplo n.º 3
0
def main():
	n = 1000
	cov = [[1,0.9],[0.9,1]]
	beta = 0.9
	p_con, p_dis = 0.5, 0.5
	gt = -p_con*0.5*log(np.linalg.det(cov))+p_dis*(log(2)+beta*log(beta)+(1-beta)*log(1-beta))-p_con*log(p_con)-p_dis*log(p_dis)

	x_con,y_con = nr.multivariate_normal([0,0],cov,int(n*p_con)).T
	x_dis = nr.binomial(1,0.5,int(n*p_dis))
	y_dis = (x_dis + nr.binomial(1,1-beta,int(n*p_dis)))%2
	x_dis, y_dis = 2*x_dis-np.ones(int(n*p_dis)), 2*y_dis-np.ones(int(n*p_dis))
	x = np.concatenate((x_con,x_dis)).reshape((n,1))
	y = np.concatenate((y_con,y_dis)).reshape((n,1))

	print "Ground Truth = ", gt
	print "Mixed KSG: I(X:Y) = ", mixed.Mixed_KSG(x,y)
	print "Partitioning: I(X:Y) = ", mixed.Partitioning(x,y)
	print "Noisy KSG: I(X:Y) = ", mixed.Noisy_KSG(x,y)
	print "KSG: I(X:Y) = ", mixed.KSG(x,y)
Exemplo n.º 4
0
def main(sample_num, node_num, d, method='KSG'):

    mat = np.zeros((trans, all_gene))
    value = []
    for i in range(trans):
        for j in range(all_gene):
            if i == j:
                continue
            if method == 'KSG':
                mat[i, j] = mixed.KSG(X[:, i], X[:, j])
            elif method == 'Noisy_KSG':
                mat[i, j] = mixed.Noisy_KSG(X[:, i], X[:, j])
            elif method == 'Partitioning':
                mat[i, j] = mixed.Partitioning(X[:, i], X[:, j])
            elif method == 'Mixed_KSG':
                mat[i, j] = mixed.Mixed_KSG(X[:, i], X[:, j])
            elif method == 'mutual_kde':
                mat[i, j] = mutual_kde(X[:, i], X[:, j])
            value += [mat[i, j]]

    #test(method,node_num,mat)
    return cal_auc(method, np.array(value))