Esempio n. 1
0
senti_data.weight = load_weight(a=6, b=14, c=7, d=23)
senti_data.weight = normalize(senti_data.weight, axis=1, norm='l1')
P = sparse.eye(d) - senti_data.weight
P = P.T.dot(P)

echo_perf = []
for j in range(20):
    train, valid, test = senti_data.split_data()
    echo_cv = []
    word_base_mat, acc_valid_orig, acc_test_orig = EL_genX(train,
                                                           valid,
                                                           test,
                                                           p=p)
    echo_cv.append([0., acc_valid_orig, acc_test_orig])
    init_X = input_data.dot(word_base_mat)
    echo = funs.GEC(d=d, p=p)

    # Parameters
    learning_rate = .005
    num_steps = 500
    display_step = 5

    # Network Parameters
    n_hidden = 128
    num_input = p
    num_classes = 1

    X = tf.placeholder("float", [None, num_input])
    Y = tf.placeholder("float", [None, num_classes])

    A = {
import funs
from scipy import sparse
from sklearn.svm import LinearSVC
from sklearn.metrics import hinge_loss

np.random.seed(21)
P2P_data = funs.P_data()
d = 1000
P2P_data.y, P2P_data.weight = np.sign(np.random.randn(d)), np.abs(
    np.random.randn(d, d)),
P2P_data.id = np.array(range(len(P2P_data.y)))

p, d = 10, P2P_data.weight.shape[0]

## construct weight matrix
echo = funs.GEC(p=p)
P = sparse.eye(d) - P2P_data.weight
P = np.dot(P.T, P)
## compute max eigen-value to determine the step size
sigma = np.max(np.linalg.eigvals(P))

## tensorflow
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

train, valid, test = P2P_data.split_data()

## tunning parameters
lam1, lam2, delta = .1, .1, .1

## one-hot encoding
Esempio n. 3
0
import numpy as np
import funs
from scipy import sparse
from sklearn.svm import LinearSVC
from sklearn.metrics import hinge_loss

np.random.seed(21)
P2P_data = funs.P_data()
P2P_data.load_data('wiki.mat')
p, d = 5, P2P_data.weight.shape[0]

# LLE
LLE = funs.GEC(p=p)
P = sparse.eye(d) - P2P_data.weight
P = np.dot(P.T, P)
P = P.toarray()
eigvalue, eigvector = np.linalg.eig(P)
eigen_index = np.argsort(eigvalue)
LLE.X = eigvector[:, eigen_index[1:p + 1]].real

## Laplacian eigenmaps
from sklearn.manifold import spectral_embedding
from scipy.sparse import csgraph
LE = funs.GEC(p=p)
LE.X = spectral_embedding(P2P_data.weight, n_components=p)

C_range = [5. * 1e-5, 1e-4, 5. * 1e-4, 1e-3, 5. * 1e-3]
delta_range = [1e-4]
C1_range = 10**np.arange(-3, 3., .3)

echo_perf, LLE_perf, LE_perf = [], [], []