Experiments with Similarity Encoders

...to show that SimEc can create similarity preserving embeddings for linear and non-linear similarities (like kernel PCA)

In this iPython Notebook are some examples to illustrate the potential of Similarity Encoders (SimEc) for creating similarity preserving embeddings. For further details and theoretical background on this new neural network architecture, please refer to the corresponding paper.

The notebook is structured as follows: After a short toy example, we present several experiments performed on the sklearn handwritten digits dataset (a small real world dataset which works great to quickly test some things out). Then we present the results on the MNIST and 20 newsgroups datasets reported in the original paper.


In [1]:
from __future__ import unicode_literals, division, print_function, absolute_import
from builtins import range
import numpy as np
np.random.seed(28)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.spatial.distance import pdist, squareform
from sklearn.metrics.pairwise import rbf_kernel
from sklearn.manifold import Isomap
from sklearn.decomposition import PCA, KernelPCA
from sklearn.random_projection import SparseRandomProjection
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_digits, fetch_mldata, fetch_20newsgroups
import tensorflow as tf
tf.set_random_seed(28)
import keras

# find nlputils at https://github.com/cod3licious/nlputils
from nlputils.features import FeatureTransform, features2mat

from simec import SimilarityEncoder
from utils import center_K, check_embed_match, check_similarity_match
from utils_datasets import load_dataset
from utils_plotting import get_colors, plot2d, plot3d, plot_digits, plot_mnist, plot_20news

%matplotlib inline
%load_ext autoreload
%autoreload 2
# set this to True if you want to save the figures from the paper
savefigs = False


/home/franzi/anaconda2/envs/python36/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.

Toy Dataset: 3 Circles

Sanity check on an artificially generated toy dataset: Linear similarity encoders reach the same solution as PCA/linear kPCA (up to a rotation and scaling) and nicely map the test examples where they belong.


In [2]:
n_train = 1000
n_test = 500
dataset = '3_circles'
# get training and test data
X, Y_plot = load_dataset(dataset, n_train, 3)
X_test, Y_plot_test = load_dataset(dataset, n_test, 5)
ss = StandardScaler(with_std=False)
X = ss.fit_transform(X)
X_test = ss.transform(X_test)
# plot the original data
plot3d(X, Y_plot, X_test, Y_plot_test, title='%s dataset' % dataset.replace('_', ' '))



In [3]:
# simple 2D PCA solution
pca = PCA(n_components=2)
X_embed = pca.fit_transform(X)
X_embed_test = pca.transform(X_test)
plot2d(X_embed, Y_plot, X_embed_test, Y_plot_test, 
       title='%s embedded with PCA' % dataset.replace('_', ' '))
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, center_K(np.dot(X, X.T))))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_test, center_K(np.dot(X_test, X_test.T))))


similarity approximation       : msqe: 0.0629632072 ; r^2: 0.8971205805 ; rho: 0.9186299240
similarity approximation (test): msqe: 0.0725416555 ; r^2: 0.8727695604 ; rho: 0.8905702688

In [4]:
# similarity encoder no activation function, linear similarities as targets
K_lin = center_K(np.dot(X, X.T))
simec = SimilarityEncoder(X.shape[1], 2, K_lin.shape[1], l2_reg_emb=0.01, s_ll_reg=0.5, S_ll=K_lin, opt=keras.optimizers.Adamax(lr=0.01))
simec.fit(X, K_lin)
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot2d(X_embeds, Y_plot, X_embed_tests, Y_plot_test, 
       title='%s embedded with a linear similarity encoder' % dataset.replace('_', ' '))
print("correlation with PCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with PCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_lin))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_tests, center_K(np.dot(X_test, X_test.T))))


Epoch 1/25
1000/1000 [==============================] - 1s 605us/step - loss: 0.8715
Epoch 2/25
1000/1000 [==============================] - 0s 84us/step - loss: 0.6392
Epoch 3/25
1000/1000 [==============================] - 0s 86us/step - loss: 0.3487
Epoch 4/25
1000/1000 [==============================] - 0s 89us/step - loss: 0.2103
Epoch 5/25
1000/1000 [==============================] - 0s 97us/step - loss: 0.1595
Epoch 6/25
1000/1000 [==============================] - 0s 84us/step - loss: 0.1347
Epoch 7/25
1000/1000 [==============================] - 0s 94us/step - loss: 0.1232
Epoch 8/25
1000/1000 [==============================] - 0s 102us/step - loss: 0.1180
Epoch 9/25
1000/1000 [==============================] - 0s 92us/step - loss: 0.1155
Epoch 10/25
1000/1000 [==============================] - 0s 95us/step - loss: 0.1143
Epoch 11/25
1000/1000 [==============================] - 0s 102us/step - loss: 0.1137
Epoch 12/25
1000/1000 [==============================] - 0s 86us/step - loss: 0.1135
Epoch 13/25
1000/1000 [==============================] - 0s 86us/step - loss: 0.1134
Epoch 14/25
1000/1000 [==============================] - 0s 86us/step - loss: 0.1133
Epoch 15/25
1000/1000 [==============================] - 0s 81us/step - loss: 0.1133
Epoch 16/25
1000/1000 [==============================] - 0s 84us/step - loss: 0.1133
Epoch 17/25
1000/1000 [==============================] - 0s 86us/step - loss: 0.1132
Epoch 18/25
1000/1000 [==============================] - 0s 90us/step - loss: 0.1132
Epoch 19/25
1000/1000 [==============================] - 0s 88us/step - loss: 0.1131
Epoch 20/25
1000/1000 [==============================] - 0s 80us/step - loss: 0.1131
Epoch 21/25
1000/1000 [==============================] - 0s 83us/step - loss: 0.1131
Epoch 22/25
1000/1000 [==============================] - 0s 75us/step - loss: 0.1130
Epoch 23/25
1000/1000 [==============================] - 0s 88us/step - loss: 0.1130
Epoch 24/25
1000/1000 [==============================] - 0s 87us/step - loss: 0.1130
Epoch 25/25
1000/1000 [==============================] - 0s 102us/step - loss: 0.1129
correlation with PCA       : 0.974167
correlation with PCA (test): 0.971557
similarity approximation       : msqe: 0.0706573192 ; r^2: 0.8902181127 ; rho: 0.9147941627
similarity approximation (test): msqe: 0.0811339167 ; r^2: 0.8631831589 ; rho: 0.8878053757

Handwritten Digits (8x8 px)

See http://scikit-learn.org/stable/auto_examples/datasets/plot_digits_last_image.html


In [5]:
# load digits dataset
digits = load_digits()
X = digits.data
X /= float(X.max())
ss = StandardScaler(with_std=False)
X = ss.fit_transform(X)
y = digits.target
n_samples, n_features = X.shape
n_targets = 1000

Linear Similarity

A linear SimEc gets the same solution as PCA (= linear kernel PCA) up to a rotation


In [6]:
# PCA
pca = PCA(n_components=2)
X_embedp = pca.fit_transform(X)
plot_digits(X_embedp, digits, title='Digits embedded with PCA')



In [7]:
# linear kPCA - same as regular PCA...;)
kpca = KernelPCA(n_components=2, kernel='linear')
X_embed = kpca.fit_transform(X)
plot_digits(X_embed, digits, title='Digits embedded with linear Kernel PCA')
print("correlation of PCA and linear kPCA: %f" % check_embed_match(X_embed, X_embedp)[1])
K_lin = center_K(np.dot(X, X.T))
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_lin))


correlation of PCA and linear kPCA: 1.000000
similarity approximation: msqe: 0.7757558402 ; r^2: 0.5362227063 ; rho: 0.7272769661

In [8]:
# linear similarity encoder
simec = SimilarityEncoder(X.shape[1], 2, n_targets, l2_reg_emb=0.0001, l2_reg_out=0.0000001, 
                          s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets], opt=keras.optimizers.Adamax(lr=0.01))
simec.fit(X, K_lin[:,:n_targets], epochs=15)
X_embeds = simec.transform(X)
plot_digits(X_embeds, digits, title='Digits embedded with a linear similarity encoder')
print("correlation with linear kPCA: %f" % check_embed_match(X_embed, X_embeds)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_lin))


Epoch 1/15
1797/1797 [==============================] - 0s 154us/step - loss: 2.2556
Epoch 2/15
1797/1797 [==============================] - 0s 101us/step - loss: 1.8459
Epoch 3/15
1797/1797 [==============================] - 0s 93us/step - loss: 1.6266
Epoch 4/15
1797/1797 [==============================] - 0s 85us/step - loss: 1.5647
Epoch 5/15
1797/1797 [==============================] - 0s 87us/step - loss: 1.5053
Epoch 6/15
1797/1797 [==============================] - 0s 87us/step - loss: 1.4515
Epoch 7/15
1797/1797 [==============================] - 0s 96us/step - loss: 1.4114
Epoch 8/15
1797/1797 [==============================] - 0s 98us/step - loss: 1.3867
Epoch 9/15
1797/1797 [==============================] - 0s 100us/step - loss: 1.3722
Epoch 10/15
1797/1797 [==============================] - 0s 93us/step - loss: 1.3616
Epoch 11/15
1797/1797 [==============================] - 0s 91us/step - loss: 1.3512
Epoch 12/15
1797/1797 [==============================] - 0s 88us/step - loss: 1.3386
Epoch 13/15
1797/1797 [==============================] - 0s 107us/step - loss: 1.3236
Epoch 14/15
1797/1797 [==============================] - 0s 87us/step - loss: 1.3074
Epoch 15/15
1797/1797 [==============================] - 0s 95us/step - loss: 1.2902
correlation with linear kPCA: 0.587603
similarity approximation: msqe: 0.8464062511 ; r^2: 0.4940871263 ; rho: 0.6895984211

In [9]:
# check how many relevant dimensions there are - obviously at most # feature dim, not # of data points
eigenvals = np.linalg.eigvalsh(K_lin)[::-1]
plt.figure();
plt.plot(list(range(1, K_lin.shape[0]+1)), eigenvals, '-o', markersize=3);
plt.plot([1, K_lin.shape[0]],[0,0], 'k--', linewidth=0.5);
plt.xlim(1, X.shape[1]+1);
plt.title('Eigenvalue Spectrum of the linear Kernel');



In [10]:
mse_kpca, rsq_kpca = [], []
mse_simec, rsq_simec = [], []
e_dims = [2, 4, 6, 10, 15, 25, 35, X.shape[1]]
for e_dim in e_dims:
    print(e_dim)
    kpca = KernelPCA(n_components=e_dim, kernel='linear')
    X_embed = kpca.fit_transform(X)
    mse_k, rsq, _ = check_similarity_match(X_embed, K_lin)
    mse_kpca.append(mse_k)
    rsq_kpca.append(rsq)
    simec = SimilarityEncoder(X.shape[1], e_dim, n_targets, l2_reg_emb=0.0001, l2_reg_out=0.0000001, 
                              s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets], 
                              opt=keras.optimizers.Adamax(lr=0.01))
    simec.fit(X, K_lin[:,:n_targets])
    X_embeds = simec.transform(X)
    mse, rsq, _ = check_similarity_match(X_embeds, K_lin)
    mse_simec.append(mse)
    rsq_simec.append(rsq)
    print("mse kpca: %f; mse simec: %f" % (mse_k, mse))
    print("correlation with linear kPCA: %f" % check_embed_match(X_embed, X_embeds)[1])
plt.figure();
plt.plot(e_dims, mse_kpca, '-o', markersize=3, label='kPCA');
plt.plot(e_dims, mse_simec, '-o', markersize=3, label='SimEc');
plt.legend(loc=0);
plt.title('Mean Squared Error');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.figure();
plt.plot(e_dims, rsq_kpca, '-o', markersize=3, label='kPCA');
plt.plot(e_dims, rsq_simec, '-o', markersize=3, label='SimEc');
plt.plot([0, e_dims[-1]], [1,1], 'k--', linewidth=0.5);
plt.legend(loc=0);
plt.title('$R^2$');
plt.xticks(e_dims, e_dims);


2
Epoch 1/25
1797/1797 [==============================] - 0s 171us/step - loss: 2.1801
Epoch 2/25
1797/1797 [==============================] - 0s 84us/step - loss: 1.5766
Epoch 3/25
1797/1797 [==============================] - 0s 86us/step - loss: 1.4730
Epoch 4/25
1797/1797 [==============================] - 0s 94us/step - loss: 1.4115
Epoch 5/25
1797/1797 [==============================] - 0s 87us/step - loss: 1.3472
Epoch 6/25
1797/1797 [==============================] - 0s 85us/step - loss: 1.2927
Epoch 7/25
1797/1797 [==============================] - 0s 93us/step - loss: 1.2575
Epoch 8/25
1797/1797 [==============================] - 0s 91us/step - loss: 1.2399
Epoch 9/25
1797/1797 [==============================] - 0s 86us/step - loss: 1.2327
Epoch 10/25
1797/1797 [==============================] - 0s 87us/step - loss: 1.2303
Epoch 11/25
1797/1797 [==============================] - 0s 91us/step - loss: 1.2293
Epoch 12/25
1797/1797 [==============================] - 0s 92us/step - loss: 1.2290
Epoch 13/25
1797/1797 [==============================] - 0s 92us/step - loss: 1.2288
Epoch 14/25
1797/1797 [==============================] - 0s 83us/step - loss: 1.2287
Epoch 15/25
1797/1797 [==============================] - 0s 93us/step - loss: 1.2286
Epoch 16/25
1797/1797 [==============================] - 0s 93us/step - loss: 1.2286
Epoch 17/25
1797/1797 [==============================] - 0s 98us/step - loss: 1.2286
Epoch 18/25
1797/1797 [==============================] - 0s 90us/step - loss: 1.2285
Epoch 19/25
1797/1797 [==============================] - 0s 91us/step - loss: 1.2287
Epoch 20/25
1797/1797 [==============================] - 0s 85us/step - loss: 1.2286
Epoch 21/25
1797/1797 [==============================] - 0s 89us/step - loss: 1.2285
Epoch 22/25
1797/1797 [==============================] - 0s 91us/step - loss: 1.2285
Epoch 23/25
1797/1797 [==============================] - 0s 93us/step - loss: 1.2286
Epoch 24/25
1797/1797 [==============================] - 0s 85us/step - loss: 1.2285
Epoch 25/25
1797/1797 [==============================] - 0s 90us/step - loss: 1.2285
mse kpca: 0.775756; mse simec: 0.798288
correlation with linear kPCA: 0.802679
4
Epoch 1/25
1797/1797 [==============================] - 0s 179us/step - loss: 2.0248
Epoch 2/25
1797/1797 [==============================] - 0s 88us/step - loss: 1.1879
Epoch 3/25
1797/1797 [==============================] - 0s 98us/step - loss: 0.9224
Epoch 4/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.7519
Epoch 5/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.6313
Epoch 6/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.5461
Epoch 7/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.4994
Epoch 8/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.4779
Epoch 9/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.4691
Epoch 10/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.4660
Epoch 11/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.4649
Epoch 12/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.4646
Epoch 13/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.4646
Epoch 14/25
1797/1797 [==============================] - 0s 103us/step - loss: 0.4645
Epoch 15/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.4645
Epoch 16/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.4645
Epoch 17/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.4645
Epoch 18/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.4645
Epoch 19/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.4646
Epoch 20/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.4647
Epoch 21/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.4646
Epoch 22/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.4646
Epoch 23/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.4646
Epoch 24/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.4647
Epoch 25/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.4647
mse kpca: 0.313544; mse simec: 0.316445
correlation with linear kPCA: 0.995490
6
Epoch 1/25
1797/1797 [==============================] - 0s 164us/step - loss: 1.8162
Epoch 2/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.9715
Epoch 3/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.7497
Epoch 4/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.5763
Epoch 5/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.4511
Epoch 6/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.3826
Epoch 7/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.3450
Epoch 8/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.3228
Epoch 9/25
1797/1797 [==============================] - 0s 83us/step - loss: 0.3088
Epoch 10/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.2990
Epoch 11/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.2918
Epoch 12/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.2867
Epoch 13/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.2833
Epoch 14/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.2810
Epoch 15/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.2795
Epoch 16/25
1797/1797 [==============================] - 0s 79us/step - loss: 0.2785
Epoch 17/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.2778
Epoch 18/25
1797/1797 [==============================] - 0s 81us/step - loss: 0.2774
Epoch 19/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.2770
Epoch 20/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.2767
Epoch 21/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.2766
Epoch 22/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.2765
Epoch 23/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.2764
Epoch 24/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.2764
Epoch 25/25
1797/1797 [==============================] - 0s 83us/step - loss: 0.2763
mse kpca: 0.186642; mse simec: 0.190521
correlation with linear kPCA: 0.988319
10
Epoch 1/25
1797/1797 [==============================] - 0s 172us/step - loss: 1.6901
Epoch 2/25
1797/1797 [==============================] - 0s 95us/step - loss: 0.8110
Epoch 3/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.5186
Epoch 4/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.3261
Epoch 5/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.2264
Epoch 6/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.1741
Epoch 7/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.1492
Epoch 8/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.1354
Epoch 9/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.1272
Epoch 10/25
1797/1797 [==============================] - 0s 99us/step - loss: 0.1223
Epoch 11/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.1192
Epoch 12/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.1170
Epoch 13/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.1152
Epoch 14/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.1135
Epoch 15/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.1118
Epoch 16/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.1099
Epoch 17/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.1081
Epoch 18/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.1064
Epoch 19/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.1052
Epoch 20/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.1042
Epoch 21/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.1035
Epoch 22/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.1031
Epoch 23/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.1028
Epoch 24/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.1027
Epoch 25/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.1026
mse kpca: 0.070436; mse simec: 0.074112
correlation with linear kPCA: 0.991210
15
Epoch 1/25
1797/1797 [==============================] - 0s 199us/step - loss: 1.5039
Epoch 2/25
1797/1797 [==============================] - 0s 90us/step - loss: 0.6698
Epoch 3/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.3681
Epoch 4/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.1987
Epoch 5/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.1316
Epoch 6/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0985
Epoch 7/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0783
Epoch 8/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0667
Epoch 9/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.0596
Epoch 10/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.0547
Epoch 11/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0510
Epoch 12/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0482
Epoch 13/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0463
Epoch 14/25
1797/1797 [==============================] - 0s 82us/step - loss: 0.0450
Epoch 15/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0442
Epoch 16/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0436
Epoch 17/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.0432
Epoch 18/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.0428
Epoch 19/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.0426
Epoch 20/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.0424
Epoch 21/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0422
Epoch 22/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0421
Epoch 23/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0420
Epoch 24/25
1797/1797 [==============================] - 0s 105us/step - loss: 0.0419
Epoch 25/25
1797/1797 [==============================] - 0s 83us/step - loss: 0.0419
mse kpca: 0.027679; mse simec: 0.029915
correlation with linear kPCA: 0.988621
25
Epoch 1/25
1797/1797 [==============================] - 0s 200us/step - loss: 1.3047
Epoch 2/25
1797/1797 [==============================] - 0s 95us/step - loss: 0.5179
Epoch 3/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.2214
Epoch 4/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.1142
Epoch 5/25
1797/1797 [==============================] - 0s 100us/step - loss: 0.0751
Epoch 6/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0541
Epoch 7/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.0415
Epoch 8/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.0337
Epoch 9/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0287
Epoch 10/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0253
Epoch 11/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0228
Epoch 12/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0208
Epoch 13/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0192
Epoch 14/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0178
Epoch 15/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.0165
Epoch 16/25
1797/1797 [==============================] - 0s 89us/step - loss: 0.0154
Epoch 17/25
1797/1797 [==============================] - 0s 93us/step - loss: 0.0145
Epoch 18/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.0137
Epoch 19/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0130
Epoch 20/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.0125
Epoch 21/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0121
Epoch 22/25
1797/1797 [==============================] - 0s 99us/step - loss: 0.0118
Epoch 23/25
1797/1797 [==============================] - 0s 86us/step - loss: 0.0115
Epoch 24/25
1797/1797 [==============================] - 0s 83us/step - loss: 0.0113
Epoch 25/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0112
mse kpca: 0.005295; mse simec: 0.006428
correlation with linear kPCA: 0.997754
35
Epoch 1/25
1797/1797 [==============================] - 0s 213us/step - loss: 1.2063
Epoch 2/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.4052
Epoch 3/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.1462
Epoch 4/25
1797/1797 [==============================] - 0s 104us/step - loss: 0.0775
Epoch 5/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0514
Epoch 6/25
1797/1797 [==============================] - 0s 100us/step - loss: 0.0374
Epoch 7/25
1797/1797 [==============================] - 0s 80us/step - loss: 0.0288
Epoch 8/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.0233
Epoch 9/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0196
Epoch 10/25
1797/1797 [==============================] - 0s 98us/step - loss: 0.0168
Epoch 11/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0147
Epoch 12/25
1797/1797 [==============================] - 0s 104us/step - loss: 0.0130
Epoch 13/25
1797/1797 [==============================] - 0s 88us/step - loss: 0.0117
Epoch 14/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0106
Epoch 15/25
1797/1797 [==============================] - 0s 99us/step - loss: 0.0097
Epoch 16/25
1797/1797 [==============================] - 0s 99us/step - loss: 0.0090
Epoch 17/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.0084
Epoch 18/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0080
Epoch 19/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0077
Epoch 20/25
1797/1797 [==============================] - 0s 83us/step - loss: 0.0074
Epoch 21/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.0071
Epoch 22/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0069
Epoch 23/25
1797/1797 [==============================] - 0s 84us/step - loss: 0.0067
Epoch 24/25
1797/1797 [==============================] - 0s 91us/step - loss: 0.0065
Epoch 25/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0063
mse kpca: 0.000986; mse simec: 0.002997
correlation with linear kPCA: 0.997433
64
Epoch 1/25
1797/1797 [==============================] - 0s 233us/step - loss: 1.0319
Epoch 2/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.2372
Epoch 3/25
1797/1797 [==============================] - 0s 100us/step - loss: 0.0729
Epoch 4/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0409
Epoch 5/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.0272
Epoch 6/25
1797/1797 [==============================] - 0s 97us/step - loss: 0.0201
Epoch 7/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0159
Epoch 8/25
1797/1797 [==============================] - 0s 85us/step - loss: 0.0131
Epoch 9/25
1797/1797 [==============================] - 0s 95us/step - loss: 0.0111
Epoch 10/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0096
Epoch 11/25
1797/1797 [==============================] - 0s 87us/step - loss: 0.0086
Epoch 12/25
1797/1797 [==============================] - 0s 104us/step - loss: 0.0078
Epoch 13/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0071
Epoch 14/25
1797/1797 [==============================] - 0s 107us/step - loss: 0.0066
Epoch 15/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0062
Epoch 16/25
1797/1797 [==============================] - 0s 109us/step - loss: 0.0059
Epoch 17/25
1797/1797 [==============================] - 0s 105us/step - loss: 0.0056
Epoch 18/25
1797/1797 [==============================] - 0s 98us/step - loss: 0.0054
Epoch 19/25
1797/1797 [==============================] - 0s 105us/step - loss: 0.0052
Epoch 20/25
1797/1797 [==============================] - 0s 92us/step - loss: 0.0050
Epoch 21/25
1797/1797 [==============================] - 0s 101us/step - loss: 0.0049
Epoch 22/25
1797/1797 [==============================] - 0s 98us/step - loss: 0.0048
Epoch 23/25
1797/1797 [==============================] - 0s 96us/step - loss: 0.0047
Epoch 24/25
1797/1797 [==============================] - 0s 95us/step - loss: 0.0046
Epoch 25/25
1797/1797 [==============================] - 0s 94us/step - loss: 0.0045
mse kpca: 0.000000; mse simec: 0.001801
correlation with linear kPCA: 0.996483

Non-linear similarities

Linear kPCA is straight forward, but what if we use a non-linear kernel function like the Gaussian kernel or isomap? For the corresponding SimEcs we add some non-linear hidden layers.


In [11]:
# Gaussian kernel PCA
D = squareform(pdist(X, 'euclidean'))
gamma = 1./(np.median(D)**2)
K_rbf = center_K(rbf_kernel(X, X, gamma))
kpca = KernelPCA(n_components=2, kernel='rbf', gamma=gamma)
X_embed = kpca.fit_transform(X)
plot_digits(X_embed, digits, title='Digits embedded with Gaussian Kernel PCA')
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_rbf))


similarity approximation: msqe: 0.0063632361 ; r^2: 0.5114399447 ; rho: 0.7355431671

In [12]:
# non-linear SimEc with rbf kernel
simec = SimilarityEncoder(X.shape[1], 2, n_targets, hidden_layers=[(100, 'tanh')], l2_reg=0.00000001,
                          l2_reg_emb=0.0001, l2_reg_out=0.0000001, s_ll_reg=0.5, S_ll=K_rbf[:n_targets,:n_targets], 
                          opt=keras.optimizers.Adamax(lr=0.01))
simec.fit(X, K_rbf[:,:n_targets], epochs=15)
X_embeds = simec.transform(X)
plot_digits(X_embeds, digits, title='Digits - SimEc (rbf kernel, 1 h.l.)')
print("correlation with Gaussian kPCA: %f" % check_embed_match(X_embed, X_embeds)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_rbf))


Epoch 1/15
1797/1797 [==============================] - 0s 245us/step - loss: 0.0147
Epoch 2/15
1797/1797 [==============================] - 0s 124us/step - loss: 0.0119
Epoch 3/15
1797/1797 [==============================] - 0s 119us/step - loss: 0.0109
Epoch 4/15
1797/1797 [==============================] - 0s 109us/step - loss: 0.0103
Epoch 5/15
1797/1797 [==============================] - 0s 121us/step - loss: 0.0102
Epoch 6/15
1797/1797 [==============================] - 0s 111us/step - loss: 0.0101
Epoch 7/15
1797/1797 [==============================] - 0s 115us/step - loss: 0.0101
Epoch 8/15
1797/1797 [==============================] - 0s 109us/step - loss: 0.0101
Epoch 9/15
1797/1797 [==============================] - 0s 117us/step - loss: 0.0101
Epoch 10/15
1797/1797 [==============================] - 0s 108us/step - loss: 0.0101
Epoch 11/15
1797/1797 [==============================] - 0s 101us/step - loss: 0.0101
Epoch 12/15
1797/1797 [==============================] - 0s 115us/step - loss: 0.0101
Epoch 13/15
1797/1797 [==============================] - 0s 110us/step - loss: 0.0101
Epoch 14/15
1797/1797 [==============================] - 0s 109us/step - loss: 0.0101 0s - loss: 0.01
Epoch 15/15
1797/1797 [==============================] - 0s 115us/step - loss: 0.0101
correlation with Gaussian kPCA: 0.958390
similarity approximation: msqe: 0.0064759303 ; r^2: 0.5038607399 ; rho: 0.7294460344

In [13]:
# isomap
isomap = Isomap(n_neighbors=10, n_components=2)
X_embed = isomap.fit_transform(X)
plot_digits(X_embed, digits, title='Digits embedded with isomap')
K_geod = center_K(-0.5*(isomap.dist_matrix_**2))
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_geod))


similarity approximation: msqe: 147.6631794001 ; r^2: 0.6349471008 ; rho: 0.7669624925

In [14]:
# non-linear SimEc based on isomap
simec = SimilarityEncoder(X.shape[1], 2, n_targets, hidden_layers=[(100, 'tanh')], s_ll_reg=10., 
                          S_ll=K_geod[:n_targets,:n_targets], opt=keras.optimizers.Adamax(lr=0.01))
simec.fit(X, K_geod[:,:n_targets])
X_embeds = simec.transform(X)
plot_digits(X_embeds, digits, title='Digits - SimEc (geodesic, 1 h.l.)')
print("correlation with isomap: %f" % check_embed_match(X_embed, X_embeds)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_geod))


Epoch 1/25
1797/1797 [==============================] - 0s 241us/step - loss: 4293.0235
Epoch 2/25
1797/1797 [==============================] - 0s 129us/step - loss: 4090.5591
Epoch 3/25
1797/1797 [==============================] - 0s 129us/step - loss: 3986.0831
Epoch 4/25
1797/1797 [==============================] - 0s 123us/step - loss: 3817.0565
Epoch 5/25
1797/1797 [==============================] - 0s 138us/step - loss: 3512.3662
Epoch 6/25
1797/1797 [==============================] - 0s 135us/step - loss: 3079.3507
Epoch 7/25
1797/1797 [==============================] - 0s 140us/step - loss: 2598.3086
Epoch 8/25
1797/1797 [==============================] - 0s 129us/step - loss: 2189.2839
Epoch 9/25
1797/1797 [==============================] - 0s 132us/step - loss: 1925.8843
Epoch 10/25
1797/1797 [==============================] - 0s 126us/step - loss: 1785.2773
Epoch 11/25
1797/1797 [==============================] - 0s 132us/step - loss: 1715.0002
Epoch 12/25
1797/1797 [==============================] - 0s 126us/step - loss: 1679.1449
Epoch 13/25
1797/1797 [==============================] - 0s 129us/step - loss: 1660.6773
Epoch 14/25
1797/1797 [==============================] - 0s 128us/step - loss: 1651.0606
Epoch 15/25
1797/1797 [==============================] - 0s 126us/step - loss: 1645.7910
Epoch 16/25
1797/1797 [==============================] - 0s 139us/step - loss: 1642.7839
Epoch 17/25
1797/1797 [==============================] - 0s 138us/step - loss: 1640.9309
Epoch 18/25
1797/1797 [==============================] - 0s 137us/step - loss: 1639.8848
Epoch 19/25
1797/1797 [==============================] - 0s 136us/step - loss: 1639.2212
Epoch 20/25
1797/1797 [==============================] - 0s 131us/step - loss: 1638.3854
Epoch 21/25
1797/1797 [==============================] - 0s 125us/step - loss: 1637.9395
Epoch 22/25
1797/1797 [==============================] - 0s 132us/step - loss: 1637.5782
Epoch 23/25
1797/1797 [==============================] - 0s 139us/step - loss: 1637.1956
Epoch 24/25
1797/1797 [==============================] - 0s 147us/step - loss: 1636.7877
Epoch 25/25
1797/1797 [==============================] - 0s 132us/step - loss: 1636.7483
correlation with isomap: 0.944148
similarity approximation: msqe: 158.9540286446 ; r^2: 0.6084372422 ; rho: 0.7535624361

In [15]:
# non-linear SimEc based on isomap - 2 hidden layers
simec = SimilarityEncoder(X.shape[1], 2, n_targets, hidden_layers=[(200, 'tanh'), (100, 'tanh')],
                          s_ll_reg=10., S_ll=K_geod[:n_targets,:n_targets], 
                          opt=keras.optimizers.Adamax(lr=0.01))
simec.fit(X, K_geod[:,:n_targets])
X_embeds = simec.transform(X)
plot_digits(X_embeds, digits, title='Digits - SimEc (geodesic, 2 h.l.)')
print("correlation with isomap: %f" % check_embed_match(X_embed, X_embeds)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_geod))


Epoch 1/25
1797/1797 [==============================] - 0s 274us/step - loss: 4277.5565
Epoch 2/25
1797/1797 [==============================] - 0s 136us/step - loss: 4168.8094
Epoch 3/25
1797/1797 [==============================] - 0s 139us/step - loss: 4073.6531
Epoch 4/25
1797/1797 [==============================] - 0s 138us/step - loss: 3962.5300
Epoch 5/25
1797/1797 [==============================] - 0s 137us/step - loss: 3786.0767
Epoch 6/25
1797/1797 [==============================] - 0s 136us/step - loss: 3510.4661
Epoch 7/25
1797/1797 [==============================] - 0s 134us/step - loss: 3150.8524
Epoch 8/25
1797/1797 [==============================] - 0s 140us/step - loss: 2758.5493
Epoch 9/25
1797/1797 [==============================] - 0s 131us/step - loss: 2398.2024
Epoch 10/25
1797/1797 [==============================] - 0s 140us/step - loss: 2103.3338
Epoch 11/25
1797/1797 [==============================] - 0s 143us/step - loss: 1889.1052
Epoch 12/25
1797/1797 [==============================] - 0s 136us/step - loss: 1763.3984
Epoch 13/25
1797/1797 [==============================] - 0s 151us/step - loss: 1700.7169
Epoch 14/25
1797/1797 [==============================] - 0s 157us/step - loss: 1670.6984
Epoch 15/25
1797/1797 [==============================] - 0s 141us/step - loss: 1655.2781
Epoch 16/25
1797/1797 [==============================] - 0s 136us/step - loss: 1646.7692
Epoch 17/25
1797/1797 [==============================] - 0s 139us/step - loss: 1641.8014
Epoch 18/25
1797/1797 [==============================] - 0s 143us/step - loss: 1638.7935
Epoch 19/25
1797/1797 [==============================] - 0s 141us/step - loss: 1636.9259
Epoch 20/25
1797/1797 [==============================] - 0s 141us/step - loss: 1635.7611
Epoch 21/25
1797/1797 [==============================] - 0s 142us/step - loss: 1635.1262
Epoch 22/25
1797/1797 [==============================] - 0s 146us/step - loss: 1634.8017
Epoch 23/25
1797/1797 [==============================] - 0s 144us/step - loss: 1634.2372
Epoch 24/25
1797/1797 [==============================] - 0s 138us/step - loss: 1634.0722
Epoch 25/25
1797/1797 [==============================] - 0s 147us/step - loss: 1634.1559
correlation with isomap: 0.970914
similarity approximation: msqe: 153.6287625695 ; r^2: 0.6225019451 ; rho: 0.7605637353

MNIST Dataset

Embedding the regular 28x28 pixel MNIST digits


In [16]:
# load digits
mnist = fetch_mldata('MNIST original', data_home='data')
X = mnist.data/255.  # normalize to 0-1
y = np.array(mnist.target, dtype=int)
# subsample 10000 random data points
np.random.seed(42)
n_samples = 10000
n_test = 2000
n_targets = 1000
rnd_idx = np.random.permutation(X.shape[0])[:n_samples]
X_test, y_test = X[rnd_idx[:n_test],:], y[rnd_idx[:n_test]]
X, y = X[rnd_idx[n_test:],:], y[rnd_idx[n_test:]]
ss = StandardScaler(with_std=False)
X = ss.fit_transform(X)
X_test = ss.transform(X_test)
n_train, n_features = X.shape
keras.backend.clear_session()

Linear Similarity

Linear SimEc again gives the same solution as PCA/linear kPCA.


In [17]:
# linear kPCA
K_lin = center_K(np.dot(X, X.T))
K_lin_test = center_K(np.dot(X_test, X_test.T))
kpca = KernelPCA(n_components=2, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
plot_mnist(X_embed, y, X_embed_test, y_test, title='MNIST - linear Kernel PCA')
if savefigs: plt.savefig('fig_spectral_mnist_lin_kpca.png', dpi=300)
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_lin))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_test, K_lin_test))


similarity approximation       : msqe: 51.4531662441 ; r^2: 0.4438507851 ; rho: 0.6341602248
similarity approximation (test): msqe: 50.7905947898 ; r^2: 0.4383615137 ; rho: 0.6283114626

In [18]:
# linear similarity encoder
simec = SimilarityEncoder(X.shape[1], 2, n_targets, l2_reg_emb=0.001, l2_reg_out=0.00001, 
                          s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets], 
                          opt=keras.optimizers.Adamax(lr=0.005))
simec.fit(X, K_lin[:,:n_targets])
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot_mnist(X_embeds, y, X_embed_tests, y_test, title='MNIST - SimEc (lin. kernel, 0 h.l.)')
if savefigs: plt.savefig('fig_spectral_mnist_lin_simec.png', dpi=300)
print("correlation with lin kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with lin kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_lin))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_tests, K_lin_test))


Epoch 1/25
8000/8000 [==============================] - 1s 108us/step - loss: 117.3314
Epoch 2/25
8000/8000 [==============================] - 1s 95us/step - loss: 99.1230
Epoch 3/25
8000/8000 [==============================] - 1s 95us/step - loss: 98.2795
Epoch 4/25
8000/8000 [==============================] - 1s 92us/step - loss: 97.9529
Epoch 5/25
8000/8000 [==============================] - 1s 90us/step - loss: 97.6107
Epoch 6/25
8000/8000 [==============================] - 1s 94us/step - loss: 97.1363
Epoch 7/25
8000/8000 [==============================] - 1s 95us/step - loss: 96.4552
Epoch 8/25
8000/8000 [==============================] - 1s 93us/step - loss: 95.4403
Epoch 9/25
8000/8000 [==============================] - 1s 92us/step - loss: 93.9135
Epoch 10/25
8000/8000 [==============================] - 1s 92us/step - loss: 91.7323
Epoch 11/25
8000/8000 [==============================] - 1s 92us/step - loss: 88.9059
Epoch 12/25
8000/8000 [==============================] - 1s 91us/step - loss: 85.8502
Epoch 13/25
8000/8000 [==============================] - 1s 91us/step - loss: 83.1520
Epoch 14/25
8000/8000 [==============================] - 1s 90us/step - loss: 81.1103
Epoch 15/25
8000/8000 [==============================] - 1s 93us/step - loss: 79.8138
Epoch 16/25
8000/8000 [==============================] - 1s 98us/step - loss: 79.1810
Epoch 17/25
8000/8000 [==============================] - 1s 95us/step - loss: 78.9535
Epoch 18/25
8000/8000 [==============================] - 1s 91us/step - loss: 78.8919
Epoch 19/25
8000/8000 [==============================] - 1s 86us/step - loss: 78.8735
Epoch 20/25
8000/8000 [==============================] - 1s 92us/step - loss: 78.8698
Epoch 21/25
8000/8000 [==============================] - 1s 91us/step - loss: 78.8663
Epoch 22/25
8000/8000 [==============================] - 1s 94us/step - loss: 78.8676
Epoch 23/25
8000/8000 [==============================] - 1s 100us/step - loss: 78.8661
Epoch 24/25
8000/8000 [==============================] - 1s 93us/step - loss: 78.8660
Epoch 25/25
8000/8000 [==============================] - 1s 93us/step - loss: 78.8657
correlation with lin kPCA       : 0.980825
correlation with lin kPCA (test): 0.982211
similarity approximation       : msqe: 51.6574858189 ; r^2: 0.4416434756 ; rho: 0.6325980947
similarity approximation (test): msqe: 51.0746013955 ; r^2: 0.4352177520 ; rho: 0.6261610143

In [19]:
# check how many relevant dimensions there are - obviously at most # feature dim, not # of data points
eigenvals = np.linalg.eigvalsh(K_lin)[::-1]
plt.figure();
plt.plot(list(range(1, K_lin.shape[0]+1)), eigenvals, '-o', markersize=3);
plt.plot([1, K_lin.shape[0]],[0,0], 'k--', linewidth=0.5);
plt.xlim(1, 100);
plt.title('Eigenvalue Spectrum of the linear Kernel');



In [20]:
mse_rp, mse_rp_test, rsq_rp = [], [], []
mse_kpca, mse_kpca_test, rsq_kpca = [], [], []
mse_simec, mse_simec_test, rsq_simec = [], [], []
e_dims = [2, 4, 6, 10, 15, 25, 50, 100]
for e_dim in e_dims:
    print(e_dim)
    # random projections
    rp = SparseRandomProjection(n_components=10*e_dim, random_state=42)
    X_embed = rp.fit_transform(X)
    X_embed_test = rp.transform(X_test)
    mse_r, rsq, _ = check_similarity_match(X_embed, K_lin)
    mse_rp.append(mse_r)
    rsq_rp.append(rsq)
    mse_rt, _, _ = check_similarity_match(X_embed_test, K_lin_test)
    mse_rp_test.append(mse_rt)
    # kpca
    kpca = KernelPCA(n_components=e_dim, kernel='linear')
    X_embed = kpca.fit_transform(X)
    X_embed_test = kpca.transform(X_test)
    mse_k, rsq, _ = check_similarity_match(X_embed, K_lin)
    mse_kpca.append(mse_k)
    rsq_kpca.append(rsq)
    mse_kt, _, _ = check_similarity_match(X_embed_test, K_lin_test)
    mse_kpca_test.append(mse_kt)
    # simec
    l = 0.002 if e_dim == 100 else 0.001
    simec = SimilarityEncoder(X.shape[1], e_dim, n_targets, s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets],
                              l2_reg_emb=l, l2_reg_out=0.00001, opt=keras.optimizers.Adamax(lr=0.003))
    simec.fit(X, K_lin[:,:n_targets])
    X_embeds = simec.transform(X)
    X_embed_tests = simec.transform(X_test)
    mse, rsq, _ = check_similarity_match(X_embeds, K_lin)
    mse_simec.append(mse)
    rsq_simec.append(rsq)
    mse_t, _, _ = check_similarity_match(X_embed_tests, K_lin_test)
    mse_simec_test.append(mse_t)
    print("mse rp: %f (%f); mse kpca: %f (%f); mse simec: %f (%f)" % (mse_r, mse_rt, mse_k, mse_kt, mse, mse_t))
    print("correlation with linear kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
    print("correlation with linear kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
keras.backend.clear_session()
colors = get_colors(15)
plt.figure();
plt.plot(e_dims, mse_kpca, '-o', markersize=3, c=colors[0], label='kPCA');
plt.plot(e_dims, mse_kpca_test, '-o', markersize=3, c=colors[2], label='kPCA (test)');
plt.plot(e_dims, mse_simec, '-o', markersize=3, c=colors[6], label='SimEc');
plt.plot(e_dims, mse_simec_test, '-o', markersize=3, c=colors[8], label='SimEc (test)');
plt.plot(e_dims, mse_rp, '-o', markersize=3, c=colors[12], label='Sparse Random Proj. $\\times$ 10');
plt.plot(e_dims, mse_rp_test, '-o', markersize=3, c=colors[14], label='SPR $\\times$ 10 (test)');
plt.legend(loc=0);
plt.title('MNIST (linear kernel)');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.xlabel('Number of Embedding Dimensions ($d$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
plt.figure();
colors = get_colors(10)
plt.plot(e_dims, mse_kpca, '-o', markersize=3, c=colors[4], label='kPCA');
plt.plot(e_dims, mse_kpca_test, '-o', markersize=3, c=colors[2], label='kPCA (test)');
plt.plot(e_dims, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(e_dims, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('MNIST (linear kernel)');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.xlabel('Number of Embedding Dimensions ($d$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
#plt.ylabel(r'$\frac{1}{N^2} \sum ( S-\hat{S} )^2$')
print("e_dims=", e_dims)
print("mse_kpca=", mse_kpca)
print("mse_kpca_test=", mse_kpca_test)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_mnist_lin_mse_edim.pdf', dpi=300)
plt.figure();
plt.plot(e_dims, rsq_kpca, '-o', markersize=3, label='kPCA');
plt.plot(e_dims, rsq_simec, '-o', markersize=3, label='SimEc');
plt.plot(e_dims, rsq_rp, '-o', markersize=3, label='SPR $\\times$ 10');
plt.plot([0, e_dims[-1]], [1,1], 'k--', linewidth=0.5);
plt.legend(loc=0);
plt.title('$R^2$');
plt.xticks(e_dims, e_dims);


2
Epoch 1/25
8000/8000 [==============================] - 1s 105us/step - loss: 125.8069
Epoch 2/25
8000/8000 [==============================] - 1s 90us/step - loss: 105.9089
Epoch 3/25
8000/8000 [==============================] - 1s 91us/step - loss: 100.9113
Epoch 4/25
8000/8000 [==============================] - 1s 90us/step - loss: 99.8149
Epoch 5/25
8000/8000 [==============================] - 1s 89us/step - loss: 99.1342
Epoch 6/25
8000/8000 [==============================] - 1s 94us/step - loss: 98.6052
Epoch 7/25
8000/8000 [==============================] - 1s 92us/step - loss: 98.1797
Epoch 8/25
8000/8000 [==============================] - 1s 91us/step - loss: 97.8252
Epoch 9/25
8000/8000 [==============================] - 1s 89us/step - loss: 97.4848
Epoch 10/25
8000/8000 [==============================] - 1s 93us/step - loss: 97.1184
Epoch 11/25
8000/8000 [==============================] - 1s 94us/step - loss: 96.6854
Epoch 12/25
8000/8000 [==============================] - 1s 83us/step - loss: 96.1569
Epoch 13/25
8000/8000 [==============================] - 1s 93us/step - loss: 95.5019
Epoch 14/25
8000/8000 [==============================] - 1s 92us/step - loss: 94.6453
Epoch 15/25
8000/8000 [==============================] - 1s 94us/step - loss: 93.5692
Epoch 16/25
8000/8000 [==============================] - 1s 91us/step - loss: 92.1889
Epoch 17/25
8000/8000 [==============================] - 1s 93us/step - loss: 90.4810
Epoch 18/25
8000/8000 [==============================] - 1s 93us/step - loss: 88.5067
Epoch 19/25
8000/8000 [==============================] - 1s 93us/step - loss: 86.3971
Epoch 20/25
8000/8000 [==============================] - 1s 91us/step - loss: 84.3559
Epoch 21/25
8000/8000 [==============================] - 1s 91us/step - loss: 82.5577
Epoch 22/25
8000/8000 [==============================] - 1s 88us/step - loss: 81.0976
Epoch 23/25
8000/8000 [==============================] - 1s 100us/step - loss: 80.0689
Epoch 24/25
8000/8000 [==============================] - 1s 92us/step - loss: 79.4420
Epoch 25/25
8000/8000 [==============================] - 1s 90us/step - loss: 79.1111
mse rp: 143.741860 (140.563994); mse kpca: 51.453166 (50.790595); mse simec: 51.863004 (51.242425)
correlation with linear kPCA       : 0.980714
correlation with linear kPCA (test): 0.982334
4
Epoch 1/25
8000/8000 [==============================] - 1s 87us/step - loss: 119.2688
Epoch 2/25
8000/8000 [==============================] - 1s 68us/step - loss: 88.3103
Epoch 3/25
8000/8000 [==============================] - 1s 74us/step - loss: 78.7155
Epoch 4/25
8000/8000 [==============================] - 1s 68us/step - loss: 78.0491
Epoch 5/25
8000/8000 [==============================] - 1s 71us/step - loss: 77.7542
Epoch 6/25
8000/8000 [==============================] - 1s 74us/step - loss: 77.4293
Epoch 7/25
8000/8000 [==============================] - 1s 69us/step - loss: 77.0373
Epoch 8/25
8000/8000 [==============================] - 1s 73us/step - loss: 76.5230
Epoch 9/25
8000/8000 [==============================] - 1s 74us/step - loss: 75.8527
Epoch 10/25
8000/8000 [==============================] - 1s 74us/step - loss: 74.9895
Epoch 11/25
8000/8000 [==============================] - 1s 81us/step - loss: 73.8667
Epoch 12/25
8000/8000 [==============================] - 1s 72us/step - loss: 72.4125
Epoch 13/25
8000/8000 [==============================] - 1s 78us/step - loss: 70.5205
Epoch 14/25
8000/8000 [==============================] - 1s 77us/step - loss: 68.1732
Epoch 15/25
8000/8000 [==============================] - 1s 87us/step - loss: 65.4288
Epoch 16/25
8000/8000 [==============================] - 1s 88us/step - loss: 62.4757
Epoch 17/25
8000/8000 [==============================] - 1s 86us/step - loss: 59.5875
Epoch 18/25
8000/8000 [==============================] - 1s 91us/step - loss: 56.9828
Epoch 19/25
8000/8000 [==============================] - 1s 92us/step - loss: 54.7325
Epoch 20/25
8000/8000 [==============================] - 1s 89us/step - loss: 52.8823
Epoch 21/25
8000/8000 [==============================] - 1s 90us/step - loss: 51.4128
Epoch 22/25
8000/8000 [==============================] - 1s 93us/step - loss: 50.3269
Epoch 23/25
8000/8000 [==============================] - 1s 87us/step - loss: 49.5930
Epoch 24/25
8000/8000 [==============================] - 1s 85us/step - loss: 49.1376
Epoch 25/25
8000/8000 [==============================] - 1s 90us/step - loss: 48.8842
mse rp: 76.839822 (75.978730); mse kpca: 32.545259 (31.977131); mse simec: 33.021989 (32.497493)
correlation with linear kPCA       : 0.981556
correlation with linear kPCA (test): 0.983711
6
Epoch 1/25
8000/8000 [==============================] - 1s 109us/step - loss: 113.5709
Epoch 2/25
8000/8000 [==============================] - 1s 89us/step - loss: 82.3164
Epoch 3/25
8000/8000 [==============================] - 1s 92us/step - loss: 73.2991
Epoch 4/25
8000/8000 [==============================] - 1s 97us/step - loss: 67.9683
Epoch 5/25
8000/8000 [==============================] - 1s 94us/step - loss: 65.5920
Epoch 6/25
8000/8000 [==============================] - 1s 89us/step - loss: 64.5229
Epoch 7/25
8000/8000 [==============================] - 1s 95us/step - loss: 63.7126
Epoch 8/25
8000/8000 [==============================] - 1s 89us/step - loss: 62.7105
Epoch 9/25
8000/8000 [==============================] - 1s 91us/step - loss: 61.3437
Epoch 10/25
8000/8000 [==============================] - 1s 96us/step - loss: 59.4579
Epoch 11/25
8000/8000 [==============================] - 1s 89us/step - loss: 56.9059
Epoch 12/25
8000/8000 [==============================] - 1s 87us/step - loss: 53.7006
Epoch 13/25
8000/8000 [==============================] - 1s 89us/step - loss: 49.9977
Epoch 14/25
8000/8000 [==============================] - 1s 94us/step - loss: 46.2040
Epoch 15/25
8000/8000 [==============================] - 1s 91us/step - loss: 42.7365
Epoch 16/25
8000/8000 [==============================] - 1s 94us/step - loss: 39.7511
Epoch 17/25
8000/8000 [==============================] - 1s 100us/step - loss: 37.2538
Epoch 18/25
8000/8000 [==============================] - 1s 98us/step - loss: 35.2386
Epoch 19/25
8000/8000 [==============================] - 1s 94us/step - loss: 33.6513
Epoch 20/25
8000/8000 [==============================] - 1s 89us/step - loss: 32.4792
Epoch 21/25
8000/8000 [==============================] - 1s 89us/step - loss: 31.6505
Epoch 22/25
8000/8000 [==============================] - 1s 94us/step - loss: 31.0603
Epoch 23/25
8000/8000 [==============================] - 1s 91us/step - loss: 30.6462
Epoch 24/25
8000/8000 [==============================] - 1s 92us/step - loss: 30.3899
Epoch 25/25
8000/8000 [==============================] - 1s 93us/step - loss: 30.2611
mse rp: 50.375350 (50.016024); mse kpca: 20.132313 (20.823148); mse simec: 20.487688 (21.201258)
correlation with linear kPCA       : 0.990846
correlation with linear kPCA (test): 0.990951
10
Epoch 1/25
8000/8000 [==============================] - 1s 113us/step - loss: 104.8481
Epoch 2/25
8000/8000 [==============================] - 1s 89us/step - loss: 70.2016
Epoch 3/25
8000/8000 [==============================] - 1s 89us/step - loss: 63.2064
Epoch 4/25
8000/8000 [==============================] - 1s 88us/step - loss: 58.3722
Epoch 5/25
8000/8000 [==============================] - 1s 93us/step - loss: 55.9635
Epoch 6/25
8000/8000 [==============================] - 1s 94us/step - loss: 54.0795
Epoch 7/25
8000/8000 [==============================] - 1s 93us/step - loss: 51.8577
Epoch 8/25
8000/8000 [==============================] - 1s 89us/step - loss: 48.6099
Epoch 9/25
8000/8000 [==============================] - 1s 92us/step - loss: 44.2284
Epoch 10/25
8000/8000 [==============================] - 1s 96us/step - loss: 39.2749
Epoch 11/25
8000/8000 [==============================] - 1s 90us/step - loss: 34.6103
Epoch 12/25
8000/8000 [==============================] - 1s 96us/step - loss: 30.6714
Epoch 13/25
8000/8000 [==============================] - 1s 92us/step - loss: 27.4535
Epoch 14/25
8000/8000 [==============================] - 1s 89us/step - loss: 24.8293
Epoch 15/25
8000/8000 [==============================] - 1s 90us/step - loss: 22.7049
Epoch 16/25
8000/8000 [==============================] - 1s 89us/step - loss: 21.0409
Epoch 17/25
8000/8000 [==============================] - 1s 92us/step - loss: 19.8038
Epoch 18/25
8000/8000 [==============================] - 1s 87us/step - loss: 18.8944
Epoch 19/25
8000/8000 [==============================] - 1s 93us/step - loss: 18.2103
Epoch 20/25
8000/8000 [==============================] - 1s 93us/step - loss: 17.7132
Epoch 21/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.3914
Epoch 22/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.2113
Epoch 23/25
8000/8000 [==============================] - 1s 86us/step - loss: 17.1298
Epoch 24/25
8000/8000 [==============================] - 1s 93us/step - loss: 17.0963
Epoch 25/25
8000/8000 [==============================] - 1s 93us/step - loss: 17.0844
mse rp: 31.293646 (30.809644); mse kpca: 11.208740 (11.554723); mse simec: 11.510554 (11.874728)
correlation with linear kPCA       : 0.984946
correlation with linear kPCA (test): 0.984005
15
Epoch 1/25
8000/8000 [==============================] - 1s 119us/step - loss: 101.2396
Epoch 2/25
8000/8000 [==============================] - 1s 94us/step - loss: 66.5801
Epoch 3/25
8000/8000 [==============================] - 1s 94us/step - loss: 59.2163
Epoch 4/25
8000/8000 [==============================] - 1s 91us/step - loss: 54.3262
Epoch 5/25
8000/8000 [==============================] - 1s 96us/step - loss: 51.1619
Epoch 6/25
8000/8000 [==============================] - 1s 92us/step - loss: 47.8803
Epoch 7/25
8000/8000 [==============================] - 1s 98us/step - loss: 43.6452
Epoch 8/25
8000/8000 [==============================] - 1s 92us/step - loss: 37.6453
Epoch 9/25
8000/8000 [==============================] - 1s 90us/step - loss: 31.0110
Epoch 10/25
8000/8000 [==============================] - 1s 96us/step - loss: 25.5254
Epoch 11/25
8000/8000 [==============================] - 1s 92us/step - loss: 21.3518
Epoch 12/25
8000/8000 [==============================] - 1s 94us/step - loss: 18.1499
Epoch 13/25
8000/8000 [==============================] - 1s 92us/step - loss: 15.7520
Epoch 14/25
8000/8000 [==============================] - 1s 94us/step - loss: 14.0507
Epoch 15/25
8000/8000 [==============================] - 1s 95us/step - loss: 12.8159
Epoch 16/25
8000/8000 [==============================] - 1s 93us/step - loss: 11.8719
Epoch 17/25
8000/8000 [==============================] - 1s 91us/step - loss: 11.1608
Epoch 18/25
8000/8000 [==============================] - 1s 89us/step - loss: 10.6587
Epoch 19/25
8000/8000 [==============================] - 1s 93us/step - loss: 10.3133
Epoch 20/25
8000/8000 [==============================] - 1s 91us/step - loss: 10.1062
Epoch 21/25
8000/8000 [==============================] - 1s 92us/step - loss: 9.9929
Epoch 22/25
8000/8000 [==============================] - 1s 95us/step - loss: 9.9444
Epoch 23/25
8000/8000 [==============================] - 1s 97us/step - loss: 9.9220
Epoch 24/25
8000/8000 [==============================] - 1s 93us/step - loss: 9.9176
Epoch 25/25
8000/8000 [==============================] - 1s 97us/step - loss: 9.9095
mse rp: 21.269326 (20.976171); mse kpca: 6.400754 (6.839900); mse simec: 6.649549 (7.071296)
correlation with linear kPCA       : 0.991693
correlation with linear kPCA (test): 0.992336
25
Epoch 1/25
8000/8000 [==============================] - 1s 122us/step - loss: 90.2402
Epoch 2/25
8000/8000 [==============================] - 1s 92us/step - loss: 60.3314
Epoch 3/25
8000/8000 [==============================] - 1s 92us/step - loss: 53.5913
Epoch 4/25
8000/8000 [==============================] - 1s 90us/step - loss: 49.1999
Epoch 5/25
8000/8000 [==============================] - 1s 91us/step - loss: 44.6187
Epoch 6/25
8000/8000 [==============================] - 1s 84us/step - loss: 37.9870
Epoch 7/25
8000/8000 [==============================] - 1s 87us/step - loss: 29.1079
Epoch 8/25
8000/8000 [==============================] - 1s 93us/step - loss: 21.2618
Epoch 9/25
8000/8000 [==============================] - 1s 90us/step - loss: 15.7449
Epoch 10/25
8000/8000 [==============================] - 1s 93us/step - loss: 11.9459
Epoch 11/25
8000/8000 [==============================] - 1s 86us/step - loss: 9.4583
Epoch 12/25
8000/8000 [==============================] - 1s 88us/step - loss: 7.8214
Epoch 13/25
8000/8000 [==============================] - 1s 93us/step - loss: 6.7067
Epoch 14/25
8000/8000 [==============================] - 1s 94us/step - loss: 5.9366
Epoch 15/25
8000/8000 [==============================] - 1s 93us/step - loss: 5.3851
Epoch 16/25
8000/8000 [==============================] - 1s 93us/step - loss: 5.0157
Epoch 17/25
8000/8000 [==============================] - 1s 90us/step - loss: 4.7687
Epoch 18/25
8000/8000 [==============================] - 1s 91us/step - loss: 4.6350
Epoch 19/25
8000/8000 [==============================] - 1s 93us/step - loss: 4.5596
Epoch 20/25
8000/8000 [==============================] - 1s 92us/step - loss: 4.5246
Epoch 21/25
8000/8000 [==============================] - 1s 94us/step - loss: 4.5093
Epoch 22/25
8000/8000 [==============================] - 1s 91us/step - loss: 4.5022
Epoch 23/25
8000/8000 [==============================] - 1s 89us/step - loss: 4.4992
Epoch 24/25
8000/8000 [==============================] - 1s 94us/step - loss: 4.4936
Epoch 25/25
8000/8000 [==============================] - 1s 93us/step - loss: 4.4898
mse rp: 12.930091 (12.600212); mse kpca: 2.727446 (3.064743); mse simec: 2.921284 (3.280938)
correlation with linear kPCA       : 0.992667
correlation with linear kPCA (test): 0.992920
50
Epoch 1/25
8000/8000 [==============================] - 1s 127us/step - loss: 82.6307
Epoch 2/25
8000/8000 [==============================] - 1s 94us/step - loss: 55.1946
Epoch 3/25
8000/8000 [==============================] - 1s 88us/step - loss: 49.0626
Epoch 4/25
8000/8000 [==============================] - 1s 97us/step - loss: 43.7323
Epoch 5/25
8000/8000 [==============================] - 1s 90us/step - loss: 35.5385
Epoch 6/25
8000/8000 [==============================] - 1s 86us/step - loss: 24.5745
Epoch 7/25
8000/8000 [==============================] - 1s 91us/step - loss: 16.0992
Epoch 8/25
8000/8000 [==============================] - 1s 95us/step - loss: 10.6105
Epoch 9/25
8000/8000 [==============================] - 1s 88us/step - loss: 7.1128
Epoch 10/25
8000/8000 [==============================] - 1s 89us/step - loss: 4.9430
Epoch 11/25
8000/8000 [==============================] - 1s 93us/step - loss: 3.6167
Epoch 12/25
8000/8000 [==============================] - 1s 94us/step - loss: 2.7707
Epoch 13/25
8000/8000 [==============================] - 1s 97us/step - loss: 2.2064
Epoch 14/25
8000/8000 [==============================] - 1s 87us/step - loss: 1.8596
Epoch 15/25
8000/8000 [==============================] - 1s 94us/step - loss: 1.6604
Epoch 16/25
8000/8000 [==============================] - 1s 96us/step - loss: 1.5384
Epoch 17/25
8000/8000 [==============================] - 1s 94us/step - loss: 1.4858
Epoch 18/25
8000/8000 [==============================] - 1s 96us/step - loss: 1.4554
Epoch 19/25
8000/8000 [==============================] - 1s 99us/step - loss: 1.4345
Epoch 20/25
8000/8000 [==============================] - 1s 99us/step - loss: 1.4120
Epoch 21/25
8000/8000 [==============================] - 1s 96us/step - loss: 1.4140
Epoch 22/25
8000/8000 [==============================] - 1s 95us/step - loss: 1.4057
Epoch 23/25
8000/8000 [==============================] - 1s 90us/step - loss: 1.4114
Epoch 24/25
8000/8000 [==============================] - 1s 90us/step - loss: 1.3931
Epoch 25/25
8000/8000 [==============================] - 1s 87us/step - loss: 1.4011
mse rp: 6.079103 (5.998758); mse kpca: 0.596014 (0.879592); mse simec: 0.712311 (0.978156)
correlation with linear kPCA       : 0.997026
correlation with linear kPCA (test): 0.997541
100
/home/franzi/anaconda2/lib/python2.7/site-packages/sklearn/random_projection.py:378: DataDimensionalityWarning: The number of components is higher than the number of features: n_features < n_components (784 < 1000).The dimensionality of the problem will not be reduced.
  DataDimensionalityWarning)
Epoch 1/25
8000/8000 [==============================] - 1s 130us/step - loss: 74.0261
Epoch 2/25
8000/8000 [==============================] - 1s 100us/step - loss: 50.3449
Epoch 3/25
8000/8000 [==============================] - 1s 100us/step - loss: 42.8453
Epoch 4/25
8000/8000 [==============================] - 1s 103us/step - loss: 31.5501
Epoch 5/25
8000/8000 [==============================] - 1s 100us/step - loss: 18.7264
Epoch 6/25
8000/8000 [==============================] - 1s 97us/step - loss: 10.8143
Epoch 7/25
8000/8000 [==============================] - 1s 100us/step - loss: 6.4521
Epoch 8/25
8000/8000 [==============================] - 1s 98us/step - loss: 4.1013
Epoch 9/25
8000/8000 [==============================] - 1s 95us/step - loss: 2.8298
Epoch 10/25
8000/8000 [==============================] - 1s 101us/step - loss: 2.0606
Epoch 11/25
8000/8000 [==============================] - 1s 101us/step - loss: 1.6248
Epoch 12/25
8000/8000 [==============================] - 1s 99us/step - loss: 1.3467
Epoch 13/25
8000/8000 [==============================] - 1s 98us/step - loss: 1.1881
Epoch 14/25
8000/8000 [==============================] - 1s 99us/step - loss: 1.0919
Epoch 15/25
8000/8000 [==============================] - 1s 102us/step - loss: 1.0122
Epoch 16/25
8000/8000 [==============================] - 1s 97us/step - loss: 0.9662
Epoch 17/25
8000/8000 [==============================] - 1s 102us/step - loss: 0.9325
Epoch 18/25
8000/8000 [==============================] - 1s 98us/step - loss: 0.9172
Epoch 19/25
8000/8000 [==============================] - 1s 99us/step - loss: 0.9010
Epoch 20/25
8000/8000 [==============================] - 1s 103us/step - loss: 0.8839
Epoch 21/25
8000/8000 [==============================] - 1s 98us/step - loss: 0.8653
Epoch 22/25
8000/8000 [==============================] - 1s 99us/step - loss: 0.8654
Epoch 23/25
8000/8000 [==============================] - 1s 98us/step - loss: 0.8538
Epoch 24/25
8000/8000 [==============================] - 1s 100us/step - loss: 0.8510
Epoch 25/25
8000/8000 [==============================] - 1s 98us/step - loss: 0.8295
mse rp: 2.947054 (3.006889); mse kpca: 0.097698 (0.332784); mse simec: 0.249603 (0.519057)
correlation with linear kPCA       : 0.996118
correlation with linear kPCA (test): 0.996360
e_dims= [2, 4, 6, 10, 15, 25, 50, 100]
mse_kpca= [51.45316624408823, 32.545258652392327, 20.132313436147445, 11.208740102257787, 6.4007541123006071, 2.7274459242800466, 0.59601390462995119, 0.097697891589151722]
mse_kpca_test= [50.790594789835531, 31.977131482486342, 20.823147631268355, 11.554723044591604, 6.8399003859083054, 3.064743109210236, 0.87959240219492674, 0.33278438676816635]
mse_simec= [51.863003883628593, 33.02198909217644, 20.48768820309601, 11.510553658448284, 6.6495486965493606, 2.9212844592657579, 0.71231061624868097, 0.24960314175403481]
mse_simec_test= [51.242425143028782, 32.497492723735057, 21.201258451913802, 11.874727559163142, 7.0712961122834521, 3.2809375173090118, 0.97815645966522002, 0.51905689005356903]

In [21]:
# check effect of different number of targets
mse_simec, mse_simec_test = [], []
targets = [100, 250, 500, 750, 1000, 1500, 2500, 5000]
kpca = KernelPCA(n_components=10, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
mse_k = check_similarity_match(X_embed, K_lin)[0]
mse_kt = check_similarity_match(X_embed_test, K_lin_test)[0]
for n in targets:
    print(n)
    simec = SimilarityEncoder(X.shape[1], 10, n, s_ll_reg=0.5, S_ll=K_lin[:n,:n], l2_reg_emb=0.001, 
                              l2_reg_out=0.00001, opt=keras.optimizers.Adamax(lr=0.003))
    simec.fit(X, K_lin[:,:n])
    X_embed = simec.transform(X)
    X_embed_test = simec.transform(X_test)
    mse = check_similarity_match(X_embed, K_lin)[0]
    mse_simec.append(mse)
    mse_t = check_similarity_match(X_embed_test, K_lin_test)[0]
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
keras.backend.clear_session()
colors = get_colors(10)
plt.figure();
plt.plot([0, targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('MNIST (linear kernel)');
plt.xticks([100, 500, 1000, 1500, 2500, 5000], [100, 500, 1000, 1500, 2500, 5000]);
plt.xlabel('Number of Targets ($n$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("targets=", targets)
print("mse_k=", mse_k)
print("mse_kt=", mse_kt)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_mnist_lin_mse_ntargets.pdf', dpi=300)


100
Epoch 1/25
8000/8000 [==============================] - 1s 93us/step - loss: 116.3805
Epoch 2/25
8000/8000 [==============================] - 1s 83us/step - loss: 81.2289
Epoch 3/25
8000/8000 [==============================] - 1s 83us/step - loss: 74.5045
Epoch 4/25
8000/8000 [==============================] - 1s 86us/step - loss: 70.6748
Epoch 5/25
8000/8000 [==============================] - 1s 86us/step - loss: 67.7915
Epoch 6/25
8000/8000 [==============================] - 1s 90us/step - loss: 64.3912
Epoch 7/25
8000/8000 [==============================] - 1s 87us/step - loss: 59.4398
Epoch 8/25
8000/8000 [==============================] - 1s 86us/step - loss: 52.6649
Epoch 9/25
8000/8000 [==============================] - 1s 89us/step - loss: 44.8417
Epoch 10/25
8000/8000 [==============================] - 1s 84us/step - loss: 37.2295
Epoch 11/25
8000/8000 [==============================] - 1s 86us/step - loss: 30.7684
Epoch 12/25
8000/8000 [==============================] - 1s 77us/step - loss: 26.1373
Epoch 13/25
8000/8000 [==============================] - 1s 88us/step - loss: 23.1747
Epoch 14/25
8000/8000 [==============================] - 1s 82us/step - loss: 21.3034
Epoch 15/25
8000/8000 [==============================] - 1s 83us/step - loss: 20.1060
Epoch 16/25
8000/8000 [==============================] - 1s 87us/step - loss: 19.3124
Epoch 17/25
8000/8000 [==============================] - 1s 89us/step - loss: 18.7860
Epoch 18/25
8000/8000 [==============================] - 1s 84us/step - loss: 18.4682
Epoch 19/25
8000/8000 [==============================] - 1s 86us/step - loss: 18.3009
Epoch 20/25
8000/8000 [==============================] - 1s 89us/step - loss: 18.2215
Epoch 21/25
8000/8000 [==============================] - 1s 82us/step - loss: 18.1946
Epoch 22/25
8000/8000 [==============================] - 1s 88us/step - loss: 18.1794
Epoch 23/25
8000/8000 [==============================] - 1s 87us/step - loss: 18.1752
Epoch 24/25
8000/8000 [==============================] - 1s 81us/step - loss: 18.1716
Epoch 25/25
8000/8000 [==============================] - 1s 85us/step - loss: 18.1715
mse kpca: 11.208740 (11.554723); mse simec: 14.712876 (15.368073)
250
Epoch 1/25
8000/8000 [==============================] - 1s 92us/step - loss: 107.3535
Epoch 2/25
8000/8000 [==============================] - 1s 81us/step - loss: 71.2075
Epoch 3/25
8000/8000 [==============================] - 1s 83us/step - loss: 64.2049
Epoch 4/25
8000/8000 [==============================] - 1s 88us/step - loss: 60.4592
Epoch 5/25
8000/8000 [==============================] - 1s 82us/step - loss: 57.9869
Epoch 6/25
8000/8000 [==============================] - 1s 85us/step - loss: 56.3117
Epoch 7/25
8000/8000 [==============================] - 1s 87us/step - loss: 54.2314
Epoch 8/25
8000/8000 [==============================] - 1s 89us/step - loss: 51.1440
Epoch 9/25
8000/8000 [==============================] - 1s 81us/step - loss: 46.8107
Epoch 10/25
8000/8000 [==============================] - 1s 86us/step - loss: 41.4581
Epoch 11/25
8000/8000 [==============================] - 1s 82us/step - loss: 35.7861
Epoch 12/25
8000/8000 [==============================] - 1s 80us/step - loss: 30.5993
Epoch 13/25
8000/8000 [==============================] - 1s 83us/step - loss: 26.4178
Epoch 14/25
8000/8000 [==============================] - 1s 84us/step - loss: 23.4506
Epoch 15/25
8000/8000 [==============================] - 1s 84us/step - loss: 21.4638
Epoch 16/25
8000/8000 [==============================] - 1s 84us/step - loss: 20.0691
Epoch 17/25
8000/8000 [==============================] - 1s 86us/step - loss: 19.0453
Epoch 18/25
8000/8000 [==============================] - 1s 85us/step - loss: 18.3069
Epoch 19/25
8000/8000 [==============================] - 1s 82us/step - loss: 17.8155
Epoch 20/25
8000/8000 [==============================] - 1s 80us/step - loss: 17.5200
Epoch 21/25
8000/8000 [==============================] - 1s 83us/step - loss: 17.3609
Epoch 22/25
8000/8000 [==============================] - 1s 87us/step - loss: 17.2853
Epoch 23/25
8000/8000 [==============================] - 1s 82us/step - loss: 17.2545
Epoch 24/25
8000/8000 [==============================] - 1s 85us/step - loss: 17.2370
Epoch 25/25
8000/8000 [==============================] - 1s 88us/step - loss: 17.2319
mse kpca: 11.208740 (11.554723); mse simec: 12.644849 (12.965724)
500
Epoch 1/25
8000/8000 [==============================] - 1s 98us/step - loss: 107.0409
Epoch 2/25
8000/8000 [==============================] - 1s 84us/step - loss: 70.2897
Epoch 3/25
8000/8000 [==============================] - 1s 86us/step - loss: 63.5359
Epoch 4/25
8000/8000 [==============================] - 1s 85us/step - loss: 60.0937
Epoch 5/25
8000/8000 [==============================] - 1s 89us/step - loss: 57.4669
Epoch 6/25
8000/8000 [==============================] - 1s 84us/step - loss: 55.5997
Epoch 7/25
8000/8000 [==============================] - 1s 82us/step - loss: 53.2304
Epoch 8/25
8000/8000 [==============================] - 1s 84us/step - loss: 49.6892
Epoch 9/25
8000/8000 [==============================] - 1s 84us/step - loss: 44.7708
Epoch 10/25
8000/8000 [==============================] - 1s 82us/step - loss: 39.0296
Epoch 11/25
8000/8000 [==============================] - 1s 88us/step - loss: 33.6203
Epoch 12/25
8000/8000 [==============================] - 1s 86us/step - loss: 29.2387
Epoch 13/25
8000/8000 [==============================] - 1s 90us/step - loss: 25.8060
Epoch 14/25
8000/8000 [==============================] - 1s 90us/step - loss: 23.1248
Epoch 15/25
8000/8000 [==============================] - 1s 87us/step - loss: 21.0942
Epoch 16/25
8000/8000 [==============================] - 1s 88us/step - loss: 19.6541
Epoch 17/25
8000/8000 [==============================] - 1s 88us/step - loss: 18.6775
Epoch 18/25
8000/8000 [==============================] - 1s 84us/step - loss: 17.9981
Epoch 19/25
8000/8000 [==============================] - 1s 87us/step - loss: 17.5014
Epoch 20/25
8000/8000 [==============================] - 1s 89us/step - loss: 17.1529
Epoch 21/25
8000/8000 [==============================] - 1s 87us/step - loss: 16.9410
Epoch 22/25
8000/8000 [==============================] - 1s 90us/step - loss: 16.8338
Epoch 23/25
8000/8000 [==============================] - 1s 85us/step - loss: 16.7910
Epoch 24/25
8000/8000 [==============================] - 1s 88us/step - loss: 16.7746
Epoch 25/25
8000/8000 [==============================] - 1s 82us/step - loss: 16.7672
mse kpca: 11.208740 (11.554723); mse simec: 11.828513 (12.171532)
750
Epoch 1/25
8000/8000 [==============================] - 1s 109us/step - loss: 106.5573
Epoch 2/25
8000/8000 [==============================] - 1s 92us/step - loss: 69.4583
Epoch 3/25
8000/8000 [==============================] - 1s 84us/step - loss: 62.1601
Epoch 4/25
8000/8000 [==============================] - 1s 84us/step - loss: 58.5940
Epoch 5/25
8000/8000 [==============================] - 1s 90us/step - loss: 56.7007
Epoch 6/25
8000/8000 [==============================] - 1s 89us/step - loss: 55.0708
Epoch 7/25
8000/8000 [==============================] - 1s 86us/step - loss: 52.8965
Epoch 8/25
8000/8000 [==============================] - 1s 84us/step - loss: 49.5893
Epoch 9/25
8000/8000 [==============================] - 1s 90us/step - loss: 44.9959
Epoch 10/25
8000/8000 [==============================] - 1s 85us/step - loss: 39.6954
Epoch 11/25
8000/8000 [==============================] - 1s 92us/step - loss: 34.6948
Epoch 12/25
8000/8000 [==============================] - 1s 85us/step - loss: 30.4913
Epoch 13/25
8000/8000 [==============================] - 1s 89us/step - loss: 27.0109
Epoch 14/25
8000/8000 [==============================] - 1s 90us/step - loss: 24.1686
Epoch 15/25
8000/8000 [==============================] - 1s 89us/step - loss: 21.9709
Epoch 16/25
8000/8000 [==============================] - 1s 90us/step - loss: 20.3982
Epoch 17/25
8000/8000 [==============================] - 1s 89us/step - loss: 19.3144
Epoch 18/25
8000/8000 [==============================] - 1s 93us/step - loss: 18.5605
Epoch 19/25
8000/8000 [==============================] - 1s 89us/step - loss: 18.0083
Epoch 20/25
8000/8000 [==============================] - 1s 86us/step - loss: 17.6050
Epoch 21/25
8000/8000 [==============================] - 1s 85us/step - loss: 17.3345
Epoch 22/25
8000/8000 [==============================] - 1s 92us/step - loss: 17.1773
Epoch 23/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.0985
Epoch 24/25
8000/8000 [==============================] - 1s 92us/step - loss: 17.0612
Epoch 25/25
8000/8000 [==============================] - 1s 95us/step - loss: 17.0461
mse kpca: 11.208740 (11.554723); mse simec: 11.568571 (11.924045)
1000
Epoch 1/25
8000/8000 [==============================] - 1s 121us/step - loss: 105.6294
Epoch 2/25
8000/8000 [==============================] - 1s 95us/step - loss: 73.1678
Epoch 3/25
8000/8000 [==============================] - 1s 96us/step - loss: 63.3200
Epoch 4/25
8000/8000 [==============================] - 1s 96us/step - loss: 59.4703
Epoch 5/25
8000/8000 [==============================] - 1s 94us/step - loss: 56.6510
Epoch 6/25
8000/8000 [==============================] - 1s 93us/step - loss: 54.7518
Epoch 7/25
8000/8000 [==============================] - 1s 91us/step - loss: 52.6301
Epoch 8/25
8000/8000 [==============================] - 1s 91us/step - loss: 49.6100
Epoch 9/25
8000/8000 [==============================] - 1s 96us/step - loss: 45.4162
Epoch 10/25
8000/8000 [==============================] - 1s 89us/step - loss: 40.3849
Epoch 11/25
8000/8000 [==============================] - 1s 87us/step - loss: 35.3206
Epoch 12/25
8000/8000 [==============================] - 1s 94us/step - loss: 31.0016
Epoch 13/25
8000/8000 [==============================] - 1s 93us/step - loss: 27.5421
Epoch 14/25
8000/8000 [==============================] - 1s 93us/step - loss: 24.8203
Epoch 15/25
8000/8000 [==============================] - 1s 90us/step - loss: 22.6580
Epoch 16/25
8000/8000 [==============================] - 1s 92us/step - loss: 20.9854
Epoch 17/25
8000/8000 [==============================] - 1s 94us/step - loss: 19.7397
Epoch 18/25
8000/8000 [==============================] - 1s 95us/step - loss: 18.8226
Epoch 19/25
8000/8000 [==============================] - 1s 95us/step - loss: 18.1312
Epoch 20/25
8000/8000 [==============================] - 1s 89us/step - loss: 17.6347
Epoch 21/25
8000/8000 [==============================] - 1s 95us/step - loss: 17.3320
Epoch 22/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.1723
Epoch 23/25
8000/8000 [==============================] - 1s 95us/step - loss: 17.1117
Epoch 24/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.0901
Epoch 25/25
8000/8000 [==============================] - 1s 92us/step - loss: 17.0771
mse kpca: 11.208740 (11.554723); mse simec: 11.517113 (11.890194)
1500
Epoch 1/25
8000/8000 [==============================] - 1s 141us/step - loss: 106.1333
Epoch 2/25
8000/8000 [==============================] - 1s 110us/step - loss: 71.5847
Epoch 3/25
8000/8000 [==============================] - 1s 111us/step - loss: 63.1147
Epoch 4/25
8000/8000 [==============================] - 1s 113us/step - loss: 58.7756
Epoch 5/25
8000/8000 [==============================] - 1s 119us/step - loss: 56.1645
Epoch 6/25
8000/8000 [==============================] - 1s 115us/step - loss: 54.3946
Epoch 7/25
8000/8000 [==============================] - 1s 118us/step - loss: 52.4095
Epoch 8/25
8000/8000 [==============================] - 1s 113us/step - loss: 49.4695
Epoch 9/25
8000/8000 [==============================] - 1s 117us/step - loss: 45.3572
Epoch 10/25
8000/8000 [==============================] - 1s 117us/step - loss: 40.3909
Epoch 11/25
8000/8000 [==============================] - 1s 115us/step - loss: 35.4704
Epoch 12/25
8000/8000 [==============================] - 1s 114us/step - loss: 31.3208
Epoch 13/25
8000/8000 [==============================] - 1s 114us/step - loss: 27.9858
Epoch 14/25
8000/8000 [==============================] - 1s 117us/step - loss: 25.2629
Epoch 15/25
8000/8000 [==============================] - 1s 113us/step - loss: 23.0074
Epoch 16/25
8000/8000 [==============================] - 1s 113us/step - loss: 21.2021
Epoch 17/25
8000/8000 [==============================] - 1s 119us/step - loss: 19.8549
Epoch 18/25
8000/8000 [==============================] - 1s 113us/step - loss: 18.9028
Epoch 19/25
8000/8000 [==============================] - 1s 119us/step - loss: 18.2355
Epoch 20/25
8000/8000 [==============================] - 1s 114us/step - loss: 17.7839
Epoch 21/25
8000/8000 [==============================] - 1s 112us/step - loss: 17.4986
Epoch 22/25
8000/8000 [==============================] - 1s 112us/step - loss: 17.3449
Epoch 23/25
8000/8000 [==============================] - 1s 115us/step - loss: 17.2771
Epoch 24/25
8000/8000 [==============================] - 1s 116us/step - loss: 17.2492
Epoch 25/25
8000/8000 [==============================] - 1s 113us/step - loss: 17.2410
mse kpca: 11.208740 (11.554723); mse simec: 11.362948 (11.733056)
2500
Epoch 1/25
8000/8000 [==============================] - 2s 233us/step - loss: 104.6954
Epoch 2/25
8000/8000 [==============================] - 1s 180us/step - loss: 70.8940
Epoch 3/25
8000/8000 [==============================] - 1s 178us/step - loss: 61.0918
Epoch 4/25
8000/8000 [==============================] - 1s 178us/step - loss: 56.8037
Epoch 5/25
8000/8000 [==============================] - 1s 176us/step - loss: 54.5299
Epoch 6/25
8000/8000 [==============================] - 1s 179us/step - loss: 53.0782
Epoch 7/25
8000/8000 [==============================] - 1s 179us/step - loss: 51.1640
Epoch 8/25
8000/8000 [==============================] - 1s 179us/step - loss: 48.2749
Epoch 9/25
8000/8000 [==============================] - 1s 180us/step - loss: 44.2813
Epoch 10/25
8000/8000 [==============================] - 1s 182us/step - loss: 39.6477
Epoch 11/25
8000/8000 [==============================] - 1s 178us/step - loss: 35.2130
Epoch 12/25
8000/8000 [==============================] - 1s 177us/step - loss: 31.3887
Epoch 13/25
8000/8000 [==============================] - 1s 177us/step - loss: 28.0859
Epoch 14/25
8000/8000 [==============================] - 1s 177us/step - loss: 25.2669
Epoch 15/25
8000/8000 [==============================] - 1s 178us/step - loss: 22.9689
Epoch 16/25
8000/8000 [==============================] - 1s 177us/step - loss: 21.1828
Epoch 17/25
8000/8000 [==============================] - ETA: 0s - loss: 19.87 - 1s 177us/step - loss: 19.8632
Epoch 18/25
8000/8000 [==============================] - 1s 180us/step - loss: 18.9140
Epoch 19/25
8000/8000 [==============================] - 1s 177us/step - loss: 18.2569
Epoch 20/25
8000/8000 [==============================] - 1s 180us/step - loss: 17.8234
Epoch 21/25
8000/8000 [==============================] - 1s 177us/step - loss: 17.5647
Epoch 22/25
8000/8000 [==============================] - 1s 179us/step - loss: 17.4323
Epoch 23/25
8000/8000 [==============================] - 1s 177us/step - loss: 17.3735
Epoch 24/25
8000/8000 [==============================] - 1s 177us/step - loss: 17.3478
Epoch 25/25
8000/8000 [==============================] - 1s 179us/step - loss: 17.3369
mse kpca: 11.208740 (11.554723); mse simec: 11.306205 (11.652621)
5000
Epoch 1/25
8000/8000 [==============================] - 5s 613us/step - loss: 103.2671
Epoch 2/25
8000/8000 [==============================] - 3s 437us/step - loss: 70.3628
Epoch 3/25
8000/8000 [==============================] - 4s 441us/step - loss: 61.5912
Epoch 4/25
8000/8000 [==============================] - 3s 435us/step - loss: 57.2115
Epoch 5/25
8000/8000 [==============================] - 4s 438us/step - loss: 54.4865
Epoch 6/25
8000/8000 [==============================] - 4s 438us/step - loss: 53.0511
Epoch 7/25
8000/8000 [==============================] - 3s 437us/step - loss: 51.0429
Epoch 8/25
8000/8000 [==============================] - 4s 439us/step - loss: 47.9928
Epoch 9/25
8000/8000 [==============================] - 4s 439us/step - loss: 43.8087
Epoch 10/25
8000/8000 [==============================] - 4s 439us/step - loss: 39.0267
Epoch 11/25
8000/8000 [==============================] - 4s 440us/step - loss: 34.5015
Epoch 12/25
8000/8000 [==============================] - 4s 442us/step - loss: 30.7335
Epoch 13/25
8000/8000 [==============================] - 4s 440us/step - loss: 27.6738
Epoch 14/25
8000/8000 [==============================] - 4s 441us/step - loss: 25.1775
Epoch 15/25
8000/8000 [==============================] - 4s 441us/step - loss: 23.1841
Epoch 16/25
8000/8000 [==============================] - 3s 436us/step - loss: 21.6550
Epoch 17/25
8000/8000 [==============================] - 4s 438us/step - loss: 20.5006
Epoch 18/25
8000/8000 [==============================] - 4s 441us/step - loss: 19.6101
Epoch 19/25
8000/8000 [==============================] - 4s 438us/step - loss: 18.9463
Epoch 20/25
8000/8000 [==============================] - 4s 439us/step - loss: 18.4962
Epoch 21/25
8000/8000 [==============================] - 4s 441us/step - loss: 18.2432
Epoch 22/25
8000/8000 [==============================] - 4s 438us/step - loss: 18.1240
Epoch 23/25
8000/8000 [==============================] - 4s 439us/step - loss: 18.0757
Epoch 24/25
8000/8000 [==============================] - 4s 440us/step - loss: 18.0581
Epoch 25/25
8000/8000 [==============================] - 3s 437us/step - loss: 18.0525
mse kpca: 11.208740 (11.554723); mse simec: 11.280052 (11.593425)
targets= [100, 250, 500, 750, 1000, 1500, 2500, 5000]
mse_k= 11.2087401023
mse_kt= 11.5547230446
mse_simec= [14.712875975862231, 12.644849130025829, 11.828513240439401, 11.56857132716323, 11.517113230240517, 11.362948327739812, 11.306205072172812, 11.280052476235269]
mse_simec_test= [15.368073196559283, 12.965723583319948, 12.171532356246319, 11.924045139720759, 11.890194492563305, 11.733055929949774, 11.652621141147163, 11.593424661110095]

In [22]:
# missing targets
n_targets = 1000
np.random.seed(15)
mse_simec, mse_simec_test = [], []
kpca = KernelPCA(n_components=10, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
mse_k = check_similarity_match(X_embed, K_lin)[0]
mse_kt = check_similarity_match(X_embed_test, K_lin_test)[0]
missing_targets = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
for m in missing_targets:
    print(m)
    K_lin_noisy = K_lin.copy()
    K_lin_noisy[np.random.rand(*K_lin_noisy.shape)<=m] = -100
    simec = SimilarityEncoder(X.shape[1], 10, n_targets, mask_value=-100, s_ll_reg=0.5, 
                              S_ll=K_lin_noisy[:n_targets,:n_targets], l2_reg_emb=0.01, 
                              l2_reg_out=0.00001, opt=keras.optimizers.Adamax(lr=0.003))
    simec.fit(X, K_lin_noisy[:,:n_targets])
    X_embed = simec.transform(X)
    X_embed_test = simec.transform(X_test)
    mse = check_similarity_match(X_embed, K_lin)[0]
    mse_simec.append(mse)
    mse_t = check_similarity_match(X_embed_test, K_lin_test)[0]
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
keras.backend.clear_session()
colors = get_colors(10)
plt.figure();
plt.plot([0, missing_targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, missing_targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(missing_targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(missing_targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('MNIST (linear kernel)');
plt.xticks(missing_targets, missing_targets);
plt.xlabel('Fraction of Missing Targets')
plt.ylabel('Mean Squared Error of $\hat{S}$')
plt.figure();
plt.plot([0, missing_targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, missing_targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(missing_targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(missing_targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.ylim([10, 40])
plt.title('MNIST (linear kernel)');
plt.xticks(missing_targets, missing_targets);
plt.xlabel('Fraction of Missing Targets')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("missing_targets=", missing_targets)
print("mse_k=", mse_k)
print("mse_kt=", mse_kt)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_mnist_lin_mse_missingt.pdf', dpi=300)


0.0
Epoch 1/25
8000/8000 [==============================] - 1s 151us/step - loss: 105.2221
Epoch 2/25
8000/8000 [==============================] - 1s 104us/step - loss: 70.9171
Epoch 3/25
8000/8000 [==============================] - 1s 108us/step - loss: 64.4375
Epoch 4/25
8000/8000 [==============================] - 1s 102us/step - loss: 59.1070
Epoch 5/25
8000/8000 [==============================] - 1s 105us/step - loss: 55.7027
Epoch 6/25
8000/8000 [==============================] - 1s 101us/step - loss: 52.9292
Epoch 7/25
8000/8000 [==============================] - 1s 101us/step - loss: 49.1944
Epoch 8/25
8000/8000 [==============================] - 1s 104us/step - loss: 44.0094
Epoch 9/25
8000/8000 [==============================] - 1s 103us/step - loss: 37.8490
Epoch 10/25
8000/8000 [==============================] - 1s 105us/step - loss: 31.9982
Epoch 11/25
8000/8000 [==============================] - 1s 99us/step - loss: 27.2606
Epoch 12/25
8000/8000 [==============================] - 1s 101us/step - loss: 23.6808
Epoch 13/25
8000/8000 [==============================] - 1s 98us/step - loss: 21.1294
Epoch 14/25
8000/8000 [==============================] - 1s 104us/step - loss: 19.4442
Epoch 15/25
8000/8000 [==============================] - 1s 103us/step - loss: 18.3976
Epoch 16/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.7772
Epoch 17/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.4471
Epoch 18/25
8000/8000 [==============================] - 1s 108us/step - loss: 17.2910
Epoch 19/25
8000/8000 [==============================] - 1s 105us/step - loss: 17.2263
Epoch 20/25
8000/8000 [==============================] - 1s 109us/step - loss: 17.1976
Epoch 21/25
8000/8000 [==============================] - 1s 104us/step - loss: 17.1805
Epoch 22/25
8000/8000 [==============================] - 1s 106us/step - loss: 17.1759
Epoch 23/25
8000/8000 [==============================] - 1s 105us/step - loss: 17.1737
Epoch 24/25
8000/8000 [==============================] - 1s 106us/step - loss: 17.1705
Epoch 25/25
8000/8000 [==============================] - 1s 105us/step - loss: 17.1699
mse kpca: 11.208740 (11.554723); mse simec: 11.511497 (11.893189)
0.1
Epoch 1/25
8000/8000 [==============================] - 1s 126us/step - loss: 106.2673
Epoch 2/25
8000/8000 [==============================] - 1s 103us/step - loss: 72.6780
Epoch 3/25
8000/8000 [==============================] - 1s 102us/step - loss: 63.9673
Epoch 4/25
8000/8000 [==============================] - 1s 103us/step - loss: 59.4162
Epoch 5/25
8000/8000 [==============================] - 1s 103us/step - loss: 56.7393
Epoch 6/25
8000/8000 [==============================] - 1s 106us/step - loss: 53.9282
Epoch 7/25
8000/8000 [==============================] - 1s 106us/step - loss: 50.5235
Epoch 8/25
8000/8000 [==============================] - 1s 101us/step - loss: 45.8880
Epoch 9/25
8000/8000 [==============================] - 1s 105us/step - loss: 40.1185
Epoch 10/25
8000/8000 [==============================] - 1s 101us/step - loss: 34.2453
Epoch 11/25
8000/8000 [==============================] - 1s 103us/step - loss: 29.2353
Epoch 12/25
8000/8000 [==============================] - 1s 105us/step - loss: 25.3563
Epoch 13/25
8000/8000 [==============================] - 1s 103us/step - loss: 22.5154
Epoch 14/25
8000/8000 [==============================] - 1s 103us/step - loss: 20.5605
Epoch 15/25
8000/8000 [==============================] - 1s 103us/step - loss: 19.2951
Epoch 16/25
8000/8000 [==============================] - 1s 104us/step - loss: 18.5054
Epoch 17/25
8000/8000 [==============================] - 1s 101us/step - loss: 18.0213
Epoch 18/25
8000/8000 [==============================] - 1s 100us/step - loss: 17.7345
Epoch 19/25
8000/8000 [==============================] - 1s 94us/step - loss: 17.5673
Epoch 20/25
8000/8000 [==============================] - 1s 100us/step - loss: 17.4708
Epoch 21/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.4106
Epoch 22/25
8000/8000 [==============================] - 1s 99us/step - loss: 17.3687
Epoch 23/25
8000/8000 [==============================] - 1s 98us/step - loss: 17.3363
Epoch 24/25
8000/8000 [==============================] - 1s 98us/step - loss: 17.3111
Epoch 25/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.2895
mse kpca: 11.208740 (11.554723); mse simec: 11.486374 (11.905400)
0.2
Epoch 1/25
8000/8000 [==============================] - 1s 133us/step - loss: 108.9106
Epoch 2/25
8000/8000 [==============================] - 1s 104us/step - loss: 74.1386
Epoch 3/25
8000/8000 [==============================] - 1s 102us/step - loss: 65.7942
Epoch 4/25
8000/8000 [==============================] - 1s 102us/step - loss: 60.9949
Epoch 5/25
8000/8000 [==============================] - 1s 106us/step - loss: 57.6718
Epoch 6/25
8000/8000 [==============================] - 1s 100us/step - loss: 55.2715
Epoch 7/25
8000/8000 [==============================] - 1s 96us/step - loss: 52.5674
Epoch 8/25
8000/8000 [==============================] - 1s 101us/step - loss: 48.8940
Epoch 9/25
8000/8000 [==============================] - 1s 100us/step - loss: 44.0548
Epoch 10/25
8000/8000 [==============================] - 1s 103us/step - loss: 38.4641
Epoch 11/25
8000/8000 [==============================] - 1s 100us/step - loss: 33.0701
Epoch 12/25
8000/8000 [==============================] - 1s 100us/step - loss: 28.5266
Epoch 13/25
8000/8000 [==============================] - 1s 103us/step - loss: 24.9675
Epoch 14/25
8000/8000 [==============================] - 1s 103us/step - loss: 22.3090
Epoch 15/25
8000/8000 [==============================] - 1s 101us/step - loss: 20.4203
Epoch 16/25
8000/8000 [==============================] - 1s 102us/step - loss: 19.1199
Epoch 17/25
8000/8000 [==============================] - 1s 100us/step - loss: 18.2736
Epoch 18/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.7609
Epoch 19/25
8000/8000 [==============================] - 1s 103us/step - loss: 17.4768
Epoch 20/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.3326
Epoch 21/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.2635
Epoch 22/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.2299
Epoch 23/25
8000/8000 [==============================] - 1s 98us/step - loss: 17.2109
Epoch 24/25
8000/8000 [==============================] - 1s 100us/step - loss: 17.1999
Epoch 25/25
8000/8000 [==============================] - 1s 103us/step - loss: 17.1918
mse kpca: 11.208740 (11.554723); mse simec: 11.500727 (11.870048)
0.3
Epoch 1/25
8000/8000 [==============================] - 1s 134us/step - loss: 107.6620
Epoch 2/25
8000/8000 [==============================] - 1s 104us/step - loss: 73.3468
Epoch 3/25
8000/8000 [==============================] - 1s 104us/step - loss: 65.9392
Epoch 4/25
8000/8000 [==============================] - 1s 101us/step - loss: 61.4641
Epoch 5/25
8000/8000 [==============================] - 1s 106us/step - loss: 57.7401
Epoch 6/25
8000/8000 [==============================] - 1s 102us/step - loss: 55.2117
Epoch 7/25
8000/8000 [==============================] - 1s 104us/step - loss: 52.7398
Epoch 8/25
8000/8000 [==============================] - 1s 101us/step - loss: 49.4832
Epoch 9/25
8000/8000 [==============================] - 1s 101us/step - loss: 45.1406
Epoch 10/25
8000/8000 [==============================] - 1s 100us/step - loss: 39.9581
Epoch 11/25
8000/8000 [==============================] - 1s 100us/step - loss: 34.7542
Epoch 12/25
8000/8000 [==============================] - 1s 106us/step - loss: 30.2351
Epoch 13/25
8000/8000 [==============================] - 1s 102us/step - loss: 26.5455
Epoch 14/25
8000/8000 [==============================] - 1s 101us/step - loss: 23.6658
Epoch 15/25
8000/8000 [==============================] - 1s 97us/step - loss: 21.4994
Epoch 16/25
8000/8000 [==============================] - 1s 98us/step - loss: 19.9090
Epoch 17/25
8000/8000 [==============================] - 1s 100us/step - loss: 18.7909
Epoch 18/25
8000/8000 [==============================] - 1s 102us/step - loss: 18.0550
Epoch 19/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.6127
Epoch 20/25
8000/8000 [==============================] - 1s 104us/step - loss: 17.3719
Epoch 21/25
8000/8000 [==============================] - 1s 95us/step - loss: 17.2554
Epoch 22/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.2041
Epoch 23/25
8000/8000 [==============================] - 1s 105us/step - loss: 17.1817
Epoch 24/25
8000/8000 [==============================] - 1s 99us/step - loss: 17.1734
Epoch 25/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.1691
mse kpca: 11.208740 (11.554723); mse simec: 11.523090 (11.894771)
0.4
Epoch 1/25
8000/8000 [==============================] - 1s 135us/step - loss: 107.5206
Epoch 2/25
8000/8000 [==============================] - 1s 100us/step - loss: 74.5684
Epoch 3/25
8000/8000 [==============================] - 1s 100us/step - loss: 66.2426
Epoch 4/25
8000/8000 [==============================] - 1s 106us/step - loss: 62.1534
Epoch 5/25
8000/8000 [==============================] - 1s 103us/step - loss: 58.7035
Epoch 6/25
8000/8000 [==============================] - 1s 106us/step - loss: 56.1679
Epoch 7/25
8000/8000 [==============================] - 1s 104us/step - loss: 54.0300
Epoch 8/25
8000/8000 [==============================] - 1s 109us/step - loss: 51.3970
Epoch 9/25
8000/8000 [==============================] - 1s 104us/step - loss: 47.9183
Epoch 10/25
8000/8000 [==============================] - 1s 102us/step - loss: 43.5563
Epoch 11/25
8000/8000 [==============================] - 1s 106us/step - loss: 38.7107
Epoch 12/25
8000/8000 [==============================] - 1s 103us/step - loss: 34.0911
Epoch 13/25
8000/8000 [==============================] - 1s 105us/step - loss: 30.1133
Epoch 14/25
8000/8000 [==============================] - 1s 101us/step - loss: 26.7933
Epoch 15/25
8000/8000 [==============================] - 1s 104us/step - loss: 24.0716
Epoch 16/25
8000/8000 [==============================] - 1s 103us/step - loss: 21.9118
Epoch 17/25
8000/8000 [==============================] - 1s 100us/step - loss: 20.2785
Epoch 18/25
8000/8000 [==============================] - 1s 105us/step - loss: 19.1152
Epoch 19/25
8000/8000 [==============================] - 1s 100us/step - loss: 18.3350
Epoch 20/25
8000/8000 [==============================] - 1s 108us/step - loss: 17.8276
Epoch 21/25
8000/8000 [==============================] - 1s 108us/step - loss: 17.5068
Epoch 22/25
8000/8000 [==============================] - 1s 104us/step - loss: 17.3202
Epoch 23/25
8000/8000 [==============================] - 1s 103us/step - loss: 17.2210
Epoch 24/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.1711
Epoch 25/25
8000/8000 [==============================] - 1s 106us/step - loss: 17.1480
mse kpca: 11.208740 (11.554723); mse simec: 11.544255 (11.911785)
0.5
Epoch 1/25
8000/8000 [==============================] - 1s 136us/step - loss: 109.5012
Epoch 2/25
8000/8000 [==============================] - 1s 102us/step - loss: 77.9319
Epoch 3/25
8000/8000 [==============================] - 1s 103us/step - loss: 67.1965
Epoch 4/25
8000/8000 [==============================] - 1s 99us/step - loss: 63.3052
Epoch 5/25
8000/8000 [==============================] - 1s 100us/step - loss: 60.6217
Epoch 6/25
8000/8000 [==============================] - 1s 98us/step - loss: 58.2773
Epoch 7/25
8000/8000 [==============================] - 1s 91us/step - loss: 56.0642
Epoch 8/25
8000/8000 [==============================] - 1s 104us/step - loss: 53.7020
Epoch 9/25
8000/8000 [==============================] - 1s 100us/step - loss: 50.8423
Epoch 10/25
8000/8000 [==============================] - 1s 103us/step - loss: 47.2793
Epoch 11/25
8000/8000 [==============================] - 1s 102us/step - loss: 43.0087
Epoch 12/25
8000/8000 [==============================] - 1s 103us/step - loss: 38.3743
Epoch 13/25
8000/8000 [==============================] - 1s 100us/step - loss: 33.9566
Epoch 14/25
8000/8000 [==============================] - 1s 103us/step - loss: 30.1581
Epoch 15/25
8000/8000 [==============================] - 1s 103us/step - loss: 27.0444
Epoch 16/25
8000/8000 [==============================] - 1s 103us/step - loss: 24.5227
Epoch 17/25
8000/8000 [==============================] - 1s 99us/step - loss: 22.5047
Epoch 18/25
8000/8000 [==============================] - 1s 105us/step - loss: 20.9334
Epoch 19/25
8000/8000 [==============================] - 1s 102us/step - loss: 19.7430
Epoch 20/25
8000/8000 [==============================] - 1s 101us/step - loss: 18.8663
Epoch 21/25
8000/8000 [==============================] - 1s 103us/step - loss: 18.2411
Epoch 22/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.8144
Epoch 23/25
8000/8000 [==============================] - 1s 101us/step - loss: 17.5348
Epoch 24/25
8000/8000 [==============================] - 1s 99us/step - loss: 17.3594
Epoch 25/25
8000/8000 [==============================] - 1s 102us/step - loss: 17.2537
mse kpca: 11.208740 (11.554723); mse simec: 11.712517 (12.061695)
0.6
Epoch 1/25
8000/8000 [==============================] - 1s 141us/step - loss: 109.7773
Epoch 2/25
8000/8000 [==============================] - 1s 102us/step - loss: 78.2199
Epoch 3/25
8000/8000 [==============================] - 1s 106us/step - loss: 68.3591
Epoch 4/25
8000/8000 [==============================] - 1s 103us/step - loss: 64.1107
Epoch 5/25
8000/8000 [==============================] - 1s 104us/step - loss: 61.2314
Epoch 6/25
8000/8000 [==============================] - 1s 104us/step - loss: 58.9505
Epoch 7/25
8000/8000 [==============================] - 1s 103us/step - loss: 57.2243
Epoch 8/25
8000/8000 [==============================] - 1s 102us/step - loss: 55.5707
Epoch 9/25
8000/8000 [==============================] - 1s 101us/step - loss: 53.6715
Epoch 10/25
8000/8000 [==============================] - 1s 104us/step - loss: 51.3328
Epoch 11/25
8000/8000 [==============================] - 1s 104us/step - loss: 48.4278
Epoch 12/25
8000/8000 [==============================] - 1s 103us/step - loss: 44.9271
Epoch 13/25
8000/8000 [==============================] - 1s 103us/step - loss: 40.9815
Epoch 14/25
8000/8000 [==============================] - 1s 95us/step - loss: 36.9789
Epoch 15/25
8000/8000 [==============================] - 1s 103us/step - loss: 33.2828
Epoch 16/25
8000/8000 [==============================] - 1s 100us/step - loss: 30.0452
Epoch 17/25
8000/8000 [==============================] - 1s 98us/step - loss: 27.2666
Epoch 18/25
8000/8000 [==============================] - 1s 101us/step - loss: 24.9091
Epoch 19/25
8000/8000 [==============================] - 1s 101us/step - loss: 22.9389
Epoch 20/25
8000/8000 [==============================] - 1s 98us/step - loss: 21.3458
Epoch 21/25
8000/8000 [==============================] - 1s 101us/step - loss: 20.1200
Epoch 22/25
8000/8000 [==============================] - 1s 103us/step - loss: 19.2111
Epoch 23/25
8000/8000 [==============================] - 1s 106us/step - loss: 18.5584
Epoch 24/25
8000/8000 [==============================] - 1s 103us/step - loss: 18.0910
Epoch 25/25
8000/8000 [==============================] - 1s 100us/step - loss: 17.7597
mse kpca: 11.208740 (11.554723); mse simec: 12.892938 (13.190620)
0.7
Epoch 1/25
8000/8000 [==============================] - 1s 133us/step - loss: 110.8376
Epoch 2/25
8000/8000 [==============================] - 1s 101us/step - loss: 79.5191
Epoch 3/25
8000/8000 [==============================] - 1s 108us/step - loss: 70.2550
Epoch 4/25
8000/8000 [==============================] - 1s 105us/step - loss: 65.2068
Epoch 5/25
8000/8000 [==============================] - 1s 99us/step - loss: 62.1682
Epoch 6/25
8000/8000 [==============================] - 1s 105us/step - loss: 60.0168
Epoch 7/25
8000/8000 [==============================] - 1s 100us/step - loss: 58.2956
Epoch 8/25
8000/8000 [==============================] - 1s 102us/step - loss: 56.8986
Epoch 9/25
8000/8000 [==============================] - 1s 103us/step - loss: 55.5200
Epoch 10/25
8000/8000 [==============================] - 1s 108us/step - loss: 53.9854
Epoch 11/25
8000/8000 [==============================] - 1s 108us/step - loss: 52.1568
Epoch 12/25
8000/8000 [==============================] - 1s 108us/step - loss: 49.9198
Epoch 13/25
8000/8000 [==============================] - 1s 103us/step - loss: 47.1933
Epoch 14/25
8000/8000 [==============================] - 1s 103us/step - loss: 43.9897
Epoch 15/25
8000/8000 [==============================] - 1s 104us/step - loss: 40.4695
Epoch 16/25
8000/8000 [==============================] - 1s 101us/step - loss: 36.8989
Epoch 17/25
8000/8000 [==============================] - 1s 103us/step - loss: 33.5506
Epoch 18/25
8000/8000 [==============================] - 1s 105us/step - loss: 30.5892
Epoch 19/25
8000/8000 [==============================] - 1s 104us/step - loss: 28.0511
Epoch 20/25
8000/8000 [==============================] - 1s 101us/step - loss: 25.8937
Epoch 21/25
8000/8000 [==============================] - 1s 105us/step - loss: 24.0736
Epoch 22/25
8000/8000 [==============================] - 1s 100us/step - loss: 22.5375
Epoch 23/25
8000/8000 [==============================] - 1s 102us/step - loss: 21.2579
Epoch 24/25
8000/8000 [==============================] - 1s 102us/step - loss: 20.2215
Epoch 25/25
8000/8000 [==============================] - 1s 106us/step - loss: 19.4024
mse kpca: 11.208740 (11.554723); mse simec: 26.331351 (26.320901)
0.8
Epoch 1/25
8000/8000 [==============================] - 1s 133us/step - loss: 116.5204
Epoch 2/25
8000/8000 [==============================] - 1s 104us/step - loss: 85.7389
Epoch 3/25
8000/8000 [==============================] - 1s 104us/step - loss: 74.5581
Epoch 4/25
8000/8000 [==============================] - 1s 100us/step - loss: 69.1376
Epoch 5/25
8000/8000 [==============================] - 1s 103us/step - loss: 66.2679
Epoch 6/25
8000/8000 [==============================] - 1s 104us/step - loss: 63.6918
Epoch 7/25
8000/8000 [==============================] - 1s 101us/step - loss: 61.2772
Epoch 8/25
8000/8000 [==============================] - 1s 105us/step - loss: 59.6159
Epoch 9/25
8000/8000 [==============================] - 1s 103us/step - loss: 58.4598
Epoch 10/25
8000/8000 [==============================] - 1s 101us/step - loss: 57.4331
Epoch 11/25
8000/8000 [==============================] - 1s 101us/step - loss: 56.4058
Epoch 12/25
8000/8000 [==============================] - 1s 101us/step - loss: 55.3049
Epoch 13/25
8000/8000 [==============================] - 1s 99us/step - loss: 54.0768
Epoch 14/25
8000/8000 [==============================] - 1s 102us/step - loss: 52.6608
Epoch 15/25
8000/8000 [==============================] - 1s 103us/step - loss: 51.0012
Epoch 16/25
8000/8000 [==============================] - 1s 100us/step - loss: 49.0514
Epoch 17/25
8000/8000 [==============================] - 1s 100us/step - loss: 46.7995
Epoch 18/25
8000/8000 [==============================] - 1s 102us/step - loss: 44.2851
Epoch 19/25
8000/8000 [==============================] - 1s 100us/step - loss: 41.6086
Epoch 20/25
8000/8000 [==============================] - 1s 100us/step - loss: 38.8966
Epoch 21/25
8000/8000 [==============================] - 1s 99us/step - loss: 36.2804
Epoch 22/25
8000/8000 [==============================] - 1s 103us/step - loss: 33.8018
Epoch 23/25
8000/8000 [==============================] - 1s 106us/step - loss: 31.4799
Epoch 24/25
8000/8000 [==============================] - 1s 103us/step - loss: 29.3273
Epoch 25/25
8000/8000 [==============================] - 1s 102us/step - loss: 27.3848
mse kpca: 11.208740 (11.554723); mse simec: 340.488319 (312.927015)
0.9
Epoch 1/25
8000/8000 [==============================] - 1s 140us/step - loss: 120.5253
Epoch 2/25
8000/8000 [==============================] - 1s 98us/step - loss: 90.3654
Epoch 3/25
8000/8000 [==============================] - 1s 106us/step - loss: 79.4913
Epoch 4/25
8000/8000 [==============================] - 1s 103us/step - loss: 73.5360
Epoch 5/25
8000/8000 [==============================] - 1s 102us/step - loss: 70.6120
Epoch 6/25
8000/8000 [==============================] - 1s 102us/step - loss: 68.3683
Epoch 7/25
8000/8000 [==============================] - 1s 99us/step - loss: 66.1282
Epoch 8/25
8000/8000 [==============================] - 1s 103us/step - loss: 64.3390
Epoch 9/25
8000/8000 [==============================] - 1s 104us/step - loss: 62.7836
Epoch 10/25
8000/8000 [==============================] - 1s 100us/step - loss: 61.4542
Epoch 11/25
8000/8000 [==============================] - 1s 95us/step - loss: 60.4660
Epoch 12/25
8000/8000 [==============================] - 1s 105us/step - loss: 59.6823
Epoch 13/25
8000/8000 [==============================] - 1s 105us/step - loss: 58.9833
Epoch 14/25
8000/8000 [==============================] - 1s 105us/step - loss: 58.3208
Epoch 15/25
8000/8000 [==============================] - 1s 104us/step - loss: 57.6699
Epoch 16/25
8000/8000 [==============================] - 1s 101us/step - loss: 57.0095
Epoch 17/25
8000/8000 [==============================] - 1s 103us/step - loss: 56.3275
Epoch 18/25
8000/8000 [==============================] - 1s 102us/step - loss: 55.6013
Epoch 19/25
8000/8000 [==============================] - 1s 106us/step - loss: 54.8131
Epoch 20/25
8000/8000 [==============================] - 1s 103us/step - loss: 53.9478
Epoch 21/25
8000/8000 [==============================] - 1s 102us/step - loss: 52.9902
Epoch 22/25
8000/8000 [==============================] - 1s 106us/step - loss: 51.9239
Epoch 23/25
8000/8000 [==============================] - 1s 102us/step - loss: 50.7285
Epoch 24/25
8000/8000 [==============================] - 1s 106us/step - loss: 49.3882
Epoch 25/25
8000/8000 [==============================] - 1s 100us/step - loss: 47.9061
mse kpca: 11.208740 (11.554723); mse simec: 4116.168943 (3810.765861)
missing_targets= [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
mse_k= 11.2087401023
mse_kt= 11.5547230446
mse_simec= [11.511496872938848, 11.486373711700184, 11.500727497069855, 11.523089797189529, 11.544255408073427, 11.712517135643738, 12.892937810953004, 26.331350519360143, 340.48831855761421, 4116.1689434474583]
mse_simec_test= [11.893188957843039, 11.905400335956248, 11.87004759031219, 11.894770633282004, 11.911785290787668, 12.06169490445386, 13.190620222310978, 26.32090087429016, 312.92701541502038, 3810.7658607812682]

Non-linear Similarities

Isomap and corresponding SimEc with 2 hidden layers.


In [23]:
# isomap
n_targets = 1000
isomap = Isomap(n_neighbors=10, n_components=2)
X_embed = isomap.fit_transform(X)
X_embed_test = isomap.transform(X_test)
plot_mnist(X_embed, y, X_embed_test, y_test, title='MNIST - isomap')
K_geod = center_K(-0.5*(isomap.dist_matrix_**2))
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_geod))


similarity approximation: msqe: 19389.7075635951 ; r^2: 0.4654955215 ; rho: 0.6520907770

In [24]:
# non-linear SimEc to approximate isomap solution
simec = SimilarityEncoder(X.shape[1], 2, n_targets, hidden_layers=[(200, 'tanh'), (100, 'tanh')], l2_reg=0.0005, 
                          l2_reg_emb=0.001, l2_reg_out=0.000001, s_ll_reg=10., S_ll=K_geod[:n_targets,:n_targets],
                          opt=keras.optimizers.Adamax(lr=0.005))
simec.fit(X, K_geod[:,:n_targets])
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot_mnist(X_embeds, y, X_embed_tests, y_test, title='MNIST - SimEc (isomap, 2 h.l.)')
print("correlation with isomap: %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with isomap (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_geod))


Epoch 1/25
8000/8000 [==============================] - 2s 193us/step - loss: 387395.0545
Epoch 2/25
8000/8000 [==============================] - 1s 169us/step - loss: 381733.2685
Epoch 3/25
8000/8000 [==============================] - 1s 168us/step - loss: 378625.1790
Epoch 4/25
8000/8000 [==============================] - 1s 168us/step - loss: 372833.8725
Epoch 5/25
8000/8000 [==============================] - 1s 168us/step - loss: 366694.2677
Epoch 6/25
8000/8000 [==============================] - 1s 169us/step - loss: 359559.5355
Epoch 7/25
8000/8000 [==============================] - 1s 167us/step - loss: 349702.0372
Epoch 8/25
8000/8000 [==============================] - 1s 166us/step - loss: 336639.4718
Epoch 9/25
8000/8000 [==============================] - 1s 167us/step - loss: 321316.4741
Epoch 10/25
8000/8000 [==============================] - 1s 165us/step - loss: 305084.1437
Epoch 11/25
8000/8000 [==============================] - 1s 165us/step - loss: 289244.2549
Epoch 12/25
8000/8000 [==============================] - 1s 165us/step - loss: 273892.1419
Epoch 13/25
8000/8000 [==============================] - 1s 167us/step - loss: 258895.3649
Epoch 14/25
8000/8000 [==============================] - 1s 167us/step - loss: 245306.6026
Epoch 15/25
8000/8000 [==============================] - 1s 166us/step - loss: 234750.7522
Epoch 16/25
8000/8000 [==============================] - 1s 169us/step - loss: 227895.7809
Epoch 17/25
8000/8000 [==============================] - 1s 167us/step - loss: 223816.5192
Epoch 18/25
8000/8000 [==============================] - 1s 167us/step - loss: 221325.9274
Epoch 19/25
8000/8000 [==============================] - 1s 163us/step - loss: 219736.1031
Epoch 20/25
8000/8000 [==============================] - 1s 165us/step - loss: 218689.2821
Epoch 21/25
8000/8000 [==============================] - 1s 167us/step - loss: 217993.6267
Epoch 22/25
8000/8000 [==============================] - 1s 169us/step - loss: 217531.0823
Epoch 23/25
8000/8000 [==============================] - 1s 168us/step - loss: 217235.3172
Epoch 24/25
8000/8000 [==============================] - 1s 168us/step - loss: 217066.4927
Epoch 25/25
8000/8000 [==============================] - 1s 165us/step - loss: 216975.6707
correlation with isomap: 0.897650
correlation with isomap (test): 0.797395
similarity approximation: msqe: 19943.9195695220 ; r^2: 0.4502681017 ; rho: 0.6424211278

In [25]:
# Gaussian kernel PCA
D = squareform(pdist(X, 'euclidean'))
sigma = np.median(D)
gamma = 0.5/(sigma**2)
print("gamma: %.5f" % gamma)
K_rbf_nonc = rbf_kernel(X, X, gamma)
K_rbf = center_K(K_rbf_nonc)
K_rbf_test_nonc = rbf_kernel(X_test, X_test, gamma)
K_rbf_test = center_K(K_rbf_test_nonc)
kpca = KernelPCA(n_components=2, kernel='rbf', gamma=gamma)
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
plot_mnist(X_embed, y, X_embed_test, y_test, title='MNIST - RBF Kernel PCA')
if savefigs: plt.savefig('fig_spectral_mnist_rbf_kpca.png', dpi=300)
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_rbf))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_test, K_rbf_test))


gamma: 0.00475
similarity approximation       : msqe: 0.0017745004 ; r^2: 0.4544257374 ; rho: 0.6513194244
similarity approximation (test): msqe: 0.0017821277 ; r^2: 0.4476707996 ; rho: 0.6471248815

In [26]:
# linear SimEc with rbf kernel
simec = SimilarityEncoder(X.shape[1], 2, n_targets, l2_reg_emb=0.0001, l2_reg_out=0.0000001, 
                          s_ll_reg=0.5, S_ll=K_rbf[:n_targets,:n_targets], opt=keras.optimizers.Adamax(lr=0.0003))
simec.fit(X, K_rbf[:,:n_targets], epochs=25)
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot_mnist(X_embeds, y, X_embed_tests, y_test, title='MNIST - SimEc (RBF kernel, 0 h.l.)')
print("correlation with kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_rbf))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_tests, K_rbf_test))


Epoch 1/25
8000/8000 [==============================] - 1s 157us/step - loss: 0.0053
Epoch 2/25
8000/8000 [==============================] - 1s 89us/step - loss: 0.0044
Epoch 3/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0038
Epoch 4/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0036
Epoch 5/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0035
Epoch 6/25
8000/8000 [==============================] - 1s 86us/step - loss: 0.0034
Epoch 7/25
8000/8000 [==============================] - 1s 89us/step - loss: 0.0033
Epoch 8/25
8000/8000 [==============================] - 1s 86us/step - loss: 0.0033
Epoch 9/25
8000/8000 [==============================] - 1s 88us/step - loss: 0.0032
Epoch 10/25
8000/8000 [==============================] - 1s 91us/step - loss: 0.0031
Epoch 11/25
8000/8000 [==============================] - 1s 94us/step - loss: 0.0030
Epoch 12/25
8000/8000 [==============================] - 1s 85us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0028
Epoch 14/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0028
Epoch 15/25
8000/8000 [==============================] - 1s 85us/step - loss: 0.0028
Epoch 16/25
8000/8000 [==============================] - 1s 87us/step - loss: 0.0028
Epoch 17/25
8000/8000 [==============================] - 1s 88us/step - loss: 0.0027
Epoch 18/25
8000/8000 [==============================] - 1s 87us/step - loss: 0.0027
Epoch 19/25
8000/8000 [==============================] - 1s 87us/step - loss: 0.0027
Epoch 20/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0027
Epoch 21/25
8000/8000 [==============================] - 1s 92us/step - loss: 0.0027
Epoch 22/25
8000/8000 [==============================] - 1s 92us/step - loss: 0.0027
Epoch 23/25
8000/8000 [==============================] - 1s 89us/step - loss: 0.0027
Epoch 24/25
8000/8000 [==============================] - 1s 86us/step - loss: 0.0027
Epoch 25/25
8000/8000 [==============================] - 1s 90us/step - loss: 0.0027
correlation with kPCA       : 0.980682
correlation with kPCA (test): 0.979332
similarity approximation       : msqe: 0.0017881808 ; r^2: 0.4502206079 ; rho: 0.6499580696
similarity approximation (test): msqe: 0.0017986777 ; r^2: 0.4425235991 ; rho: 0.6447889880

In [27]:
# non-linear SimEc with rbf kernel
simec = SimilarityEncoder(X.shape[1], 2, n_targets, hidden_layers=[(1000, 'tanh')], l2_reg=0.00000001, 
                          l2_reg_emb=0.00001, l2_reg_out=0.0000001, s_ll_reg=5., 
                          S_ll=K_rbf[:n_targets,:n_targets], opt=keras.optimizers.Adamax(lr=0.0003))
simec.fit(X, K_rbf[:,:n_targets], epochs=25)
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot_mnist(X_embeds, y, X_embed_tests, y_test, title='MNIST - SimEc (RBF kernel, 1 h.l.)')
if savefigs: plt.savefig('fig_spectral_mnist_rbf_simec.png', dpi=300)
print("correlation with kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_rbf))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_tests, K_rbf_test))


Epoch 1/25
8000/8000 [==============================] - 1s 146us/step - loss: 0.0200
Epoch 2/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0183
Epoch 3/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0158
Epoch 4/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0134
Epoch 5/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0120
Epoch 6/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0115
Epoch 7/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0114
Epoch 8/25
8000/8000 [==============================] - 1s 113us/step - loss: 0.0114
Epoch 9/25
8000/8000 [==============================] - 1s 114us/step - loss: 0.0113
Epoch 10/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0113
Epoch 11/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0113
Epoch 12/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0113
Epoch 13/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 14/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 15/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0113
Epoch 16/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0113
Epoch 17/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 18/25
8000/8000 [==============================] - 1s 115us/step - loss: 0.0113
Epoch 19/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0113
Epoch 20/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0113
Epoch 21/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 22/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 23/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0113
Epoch 24/25
8000/8000 [==============================] - 1s 111us/step - loss: 0.0113
Epoch 25/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0113
correlation with kPCA       : 0.963739
correlation with kPCA (test): 0.962955
similarity approximation       : msqe: 0.0018074345 ; r^2: 0.4447394709 ; rho: 0.6442441677
similarity approximation (test): msqe: 0.0018145114 ; r^2: 0.4381431990 ; rho: 0.6396442729

In [28]:
# check how many relevant dimensions there are - obviously at most # feature dim, not # of data points
eigenvals = np.linalg.eigvalsh(K_rbf)[::-1]
plt.figure();
plt.plot(list(range(1, K_rbf.shape[0]+1)), eigenvals, '-o', markersize=3);
plt.plot([1, K_rbf.shape[0]],[0,0], 'k--', linewidth=0.5);
plt.xlim(1, 100);
plt.title('Eigenvalue Spectrum of the RBF Kernel');



In [29]:
mse_rf, mse_rf_test, rsq_rf = [], [], []
mse_kpca, mse_kpca_test, rsq_kpca = [], [], []
mse_simec, mse_simec_test, rsq_simec = [], [], []
e_dims = [2, 4, 6, 10, 15, 25, 50, 100]
for e_dim in e_dims:
    print(e_dim)
    # random features
    W = np.random.normal(size=(5*e_dim, X.shape[1]), scale=1./sigma)
    tmp = X.dot(W.T)
    X_embed = np.sqrt(1./(5*e_dim)) * np.hstack([np.cos(tmp), np.sin(tmp)])
    tmp = X_test.dot(W.T)
    X_embed_test = np.sqrt(1./(5*e_dim)) * np.hstack([np.cos(tmp), np.sin(tmp)])
    mse_r, rsq, _ = check_similarity_match(X_embed, K_rbf_nonc)
    mse_rf.append(mse_r)
    rsq_rf.append(rsq)
    mse_rt, _, _ = check_similarity_match(X_embed_test, K_rbf_test_nonc)
    mse_rf_test.append(mse_rt)
    # kernel pca
    kpca = KernelPCA(n_components=e_dim, kernel='rbf', gamma=gamma)
    X_embed = kpca.fit_transform(X)
    X_embed_test = kpca.transform(X_test)
    mse_k, rsq, _ = check_similarity_match(X_embed, K_rbf)
    mse_kpca.append(mse_k)
    rsq_kpca.append(rsq)
    mse_kt, _, _ = check_similarity_match(X_embed_test, K_rbf_test)
    mse_kpca_test.append(mse_kt)
    # simec
    simec = SimilarityEncoder(X.shape[1], e_dim, n_targets, hidden_layers=[(1000, 'tanh')], 
                              l2_reg=0.00000001, l2_reg_emb=0.00001, l2_reg_out=0.0000001, 
                              s_ll_reg=5., S_ll=K_rbf[:n_targets,:n_targets], 
                              opt=keras.optimizers.Adamax(lr=0.0005))
    simec.fit(X, K_rbf[:,:n_targets])
    X_embeds = simec.transform(X)
    X_embed_tests = simec.transform(X_test)
    mse, rsq, _ = check_similarity_match(X_embeds, K_rbf)
    mse_simec.append(mse)
    rsq_simec.append(rsq)
    mse_t, _, _ = check_similarity_match(X_embed_tests, K_rbf_test)
    mse_simec_test.append(mse_t)
    print("mse rf: %f (%f); mse kpca: %f (%f); mse simec: %f (%f)" % (mse_r, mse_rt, mse_k, mse_kt, mse, mse_t))
    print("correlation with kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
    print("correlation with kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
keras.backend.clear_session()
colors = get_colors(15)
plt.figure();
plt.plot(e_dims, mse_kpca, '-o', markersize=3, c=colors[0], label='kPCA');
plt.plot(e_dims, mse_kpca_test, '-o', markersize=3, c=colors[2], label='kPCA (test)');
plt.plot(e_dims, mse_simec, '-o', markersize=3, c=colors[6], label='SimEc');
plt.plot(e_dims, mse_simec_test, '-o', markersize=3, c=colors[8], label='SimEc (test)');
plt.plot(e_dims, mse_rf, '-o', markersize=3, c=colors[12], label='Random Features $\\times$ 10');
plt.plot(e_dims, mse_rf_test, '-o', markersize=3, c=colors[14], label='RF $\\times$ 10 (test)');
plt.legend(loc=0);
plt.title('MNIST (RBF kernel)');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.ylim(ymax=0.005)
plt.xlabel('Number of Embedding Dimensions ($d$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
plt.figure();
colors = get_colors(10)
plt.plot(e_dims, mse_kpca, '-o', markersize=3, c=colors[4], label='kPCA');
plt.plot(e_dims, mse_kpca_test, '-o', markersize=3, c=colors[2], label='kPCA (test)');
plt.plot(e_dims, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(e_dims, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('MNIST (RBF kernel)');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.xlabel('Number of Embedding Dimensions ($d$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("e_dims=", e_dims)
print("mse_kpca=", mse_kpca)
print("mse_kpca_test=", mse_kpca_test)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_mnist_rbf_mse_edim.pdf', dpi=300)
plt.figure();
plt.plot(e_dims, rsq_kpca, '-o', markersize=3, label='kPCA');
plt.plot(e_dims, rsq_simec, '-o', markersize=3, label='SimEc');
plt.plot(e_dims, rsq_rf, '-o', markersize=3, label='RF $\\times$ 10');
plt.plot([0, e_dims[-1]], [1,1], 'k--', linewidth=0.5);
plt.legend(loc=0);
plt.title('$R^2$');
plt.xticks(e_dims, e_dims);


2
Epoch 1/25
8000/8000 [==============================] - 1s 152us/step - loss: 0.0194
Epoch 2/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0159
Epoch 3/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0129
Epoch 4/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0120
Epoch 5/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0117
Epoch 6/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0115
Epoch 7/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0114
Epoch 8/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0114
Epoch 9/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0114
Epoch 10/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0114
Epoch 11/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0114
Epoch 12/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0114
Epoch 13/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 14/25
8000/8000 [==============================] - 1s 115us/step - loss: 0.0113
Epoch 15/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0113
Epoch 16/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 17/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0113
Epoch 18/25
8000/8000 [==============================] - 1s 115us/step - loss: 0.0113
Epoch 19/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0113
Epoch 20/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0113
Epoch 21/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0113
Epoch 22/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0113
Epoch 23/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0113
Epoch 24/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0113
Epoch 25/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0113
mse rf: 0.022064 (0.022703); mse kpca: 0.001775 (0.001782); mse simec: 0.001816 (0.001834)
correlation with kPCA       : 0.945857
correlation with kPCA (test): 0.944123
4
Epoch 1/25
8000/8000 [==============================] - 1s 153us/step - loss: 0.0190
Epoch 2/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0131
Epoch 3/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0086
Epoch 4/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0076
Epoch 5/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0074
Epoch 6/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0074
Epoch 7/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0074
Epoch 8/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0074
Epoch 9/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0074
Epoch 10/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0074
Epoch 11/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0073
Epoch 12/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0074
Epoch 13/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0073
Epoch 14/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0073
Epoch 15/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0073
Epoch 16/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0073
Epoch 17/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0073
Epoch 18/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0073
Epoch 19/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0073
Epoch 20/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0073
Epoch 21/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0073
Epoch 22/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0073
Epoch 23/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0073
Epoch 24/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0073
Epoch 25/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0073
mse rf: 0.009136 (0.008573); mse kpca: 0.001166 (0.001172); mse simec: 0.001222 (0.001229)
correlation with kPCA       : 0.954591
correlation with kPCA (test): 0.952863
6
Epoch 1/25
8000/8000 [==============================] - 1s 149us/step - loss: 0.0186
Epoch 2/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0112
Epoch 3/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0066
Epoch 4/25
8000/8000 [==============================] - 1s 117us/step - loss: 0.0052 
Epoch 5/25
8000/8000 [==============================] - 1s 116us/step - loss: 0.0049
Epoch 6/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0049
Epoch 7/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0049
Epoch 8/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0049
Epoch 9/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0048
Epoch 10/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0048
Epoch 11/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0048
Epoch 12/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0048
Epoch 13/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0048
Epoch 14/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0048
Epoch 15/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0048
Epoch 16/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0048
Epoch 17/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0048
Epoch 18/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0048
Epoch 19/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0048
Epoch 20/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0048
Epoch 21/25
8000/8000 [==============================] - 1s 119us/step - loss: 0.0048
Epoch 22/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0048
Epoch 23/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0048
Epoch 24/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0048
Epoch 25/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0048
mse rf: 0.006184 (0.006173); mse kpca: 0.000751 (0.000787); mse simec: 0.000804 (0.000841)
correlation with kPCA       : 0.964884
correlation with kPCA (test): 0.964071
10
Epoch 1/25
8000/8000 [==============================] - 1s 156us/step - loss: 0.0175
Epoch 2/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0085
Epoch 3/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0046
Epoch 4/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0034
Epoch 5/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0031
Epoch 6/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0030
Epoch 7/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0030
Epoch 11/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0029
Epoch 20/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0029
Epoch 21/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 22/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
mse rf: 0.003968 (0.003823); mse kpca: 0.000432 (0.000460); mse simec: 0.000484 (0.000511)
correlation with kPCA       : 0.954845
correlation with kPCA (test): 0.951735
15
Epoch 1/25
8000/8000 [==============================] - 1s 157us/step - loss: 0.0170
Epoch 2/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0073
Epoch 3/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0038
Epoch 4/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0026
Epoch 5/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0022
Epoch 6/25
8000/8000 [==============================] - 1s 120us/step - loss: 0.0021
Epoch 7/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0020
Epoch 8/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0020
Epoch 9/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0020
Epoch 10/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0019
Epoch 11/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0019
Epoch 12/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0019
Epoch 13/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0019
Epoch 14/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0018
Epoch 15/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0018
Epoch 16/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0018
Epoch 17/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0018
Epoch 18/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0018
Epoch 19/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0018
Epoch 20/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0018
Epoch 21/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0018
Epoch 22/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0018
Epoch 23/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0017
Epoch 24/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0017
Epoch 25/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0017
mse rf: 0.002495 (0.002651); mse kpca: 0.000252 (0.000280); mse simec: 0.000295 (0.000322)
correlation with kPCA       : 0.969542
correlation with kPCA (test): 0.968980
25
Epoch 1/25
8000/8000 [==============================] - 1s 162us/step - loss: 0.0163
Epoch 2/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0057
Epoch 3/25
8000/8000 [==============================] - 1s 121us/step - loss: 0.0030
Epoch 4/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0020
Epoch 5/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0016
Epoch 6/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0014
Epoch 7/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0013
Epoch 8/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0012
Epoch 9/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0012
Epoch 10/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0011
Epoch 11/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0011
Epoch 12/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0011
Epoch 13/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0011
Epoch 14/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0010
Epoch 15/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0010
Epoch 16/25
8000/8000 [==============================] - 1s 122us/step - loss: 9.8146e-04
Epoch 17/25
8000/8000 [==============================] - 1s 119us/step - loss: 9.6370e-04
Epoch 18/25
8000/8000 [==============================] - 1s 125us/step - loss: 9.4591e-04
Epoch 19/25
8000/8000 [==============================] - 1s 130us/step - loss: 9.2935e-04
Epoch 20/25
8000/8000 [==============================] - 1s 125us/step - loss: 9.1643e-04
Epoch 21/25
8000/8000 [==============================] - 1s 127us/step - loss: 9.0356e-04
Epoch 22/25
8000/8000 [==============================] - 1s 122us/step - loss: 8.9271e-04
Epoch 23/25
8000/8000 [==============================] - 1s 125us/step - loss: 8.8277e-04
Epoch 24/25
8000/8000 [==============================] - 1s 124us/step - loss: 8.7428e-04
Epoch 25/25
8000/8000 [==============================] - 1s 126us/step - loss: 8.6808e-04
mse rf: 0.001566 (0.001596); mse kpca: 0.000118 (0.000139); mse simec: 0.000153 (0.000177)
correlation with kPCA       : 0.975941
correlation with kPCA (test): 0.973520
50
Epoch 1/25
8000/8000 [==============================] - 1s 164us/step - loss: 0.0169
Epoch 2/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0055
Epoch 3/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 4/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0020
Epoch 5/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0016
Epoch 6/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0013
Epoch 7/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0011
Epoch 8/25
8000/8000 [==============================] - 1s 129us/step - loss: 9.3030e-04
Epoch 9/25
8000/8000 [==============================] - 1s 127us/step - loss: 8.2244e-04
Epoch 10/25
8000/8000 [==============================] - 1s 120us/step - loss: 7.4355e-04
Epoch 11/25
8000/8000 [==============================] - 1s 123us/step - loss: 6.7606e-04
Epoch 12/25
8000/8000 [==============================] - 1s 127us/step - loss: 6.2486e-04
Epoch 13/25
8000/8000 [==============================] - 1s 128us/step - loss: 5.7394e-04
Epoch 14/25
8000/8000 [==============================] - 1s 126us/step - loss: 5.3639e-04
Epoch 15/25
8000/8000 [==============================] - 1s 121us/step - loss: 4.9659e-04
Epoch 16/25
8000/8000 [==============================] - 1s 124us/step - loss: 4.6444e-04
Epoch 17/25
8000/8000 [==============================] - 1s 132us/step - loss: 4.3876e-04
Epoch 18/25
8000/8000 [==============================] - 1s 127us/step - loss: 4.1476e-04
Epoch 19/25
8000/8000 [==============================] - 1s 128us/step - loss: 3.9451e-04
Epoch 20/25
8000/8000 [==============================] - 1s 125us/step - loss: 3.7966e-04
Epoch 21/25
8000/8000 [==============================] - 1s 126us/step - loss: 3.6410e-04
Epoch 22/25
8000/8000 [==============================] - 1s 125us/step - loss: 3.5379e-04
Epoch 23/25
8000/8000 [==============================] - 1s 121us/step - loss: 3.4450e-04
Epoch 24/25
8000/8000 [==============================] - 1s 126us/step - loss: 3.3674e-04
Epoch 25/25
8000/8000 [==============================] - 1s 122us/step - loss: 3.3136e-04
mse rf: 0.000736 (0.000724); mse kpca: 0.000034 (0.000050); mse simec: 0.000071 (0.000089)
correlation with kPCA       : 0.973940
correlation with kPCA (test): 0.971945
100
Epoch 1/25
8000/8000 [==============================] - 1s 175us/step - loss: 0.0184
Epoch 2/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0063
Epoch 3/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0036
Epoch 4/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0025
Epoch 5/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0020
Epoch 6/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0016
Epoch 7/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0013
Epoch 8/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0011
Epoch 9/25
8000/8000 [==============================] - 1s 132us/step - loss: 9.0128e-04
Epoch 10/25
8000/8000 [==============================] - 1s 129us/step - loss: 7.5898e-04
Epoch 11/25
8000/8000 [==============================] - 1s 127us/step - loss: 6.3259e-04
Epoch 12/25
8000/8000 [==============================] - 1s 125us/step - loss: 5.3339e-04
Epoch 13/25
8000/8000 [==============================] - 1s 129us/step - loss: 4.5072e-04
Epoch 14/25
8000/8000 [==============================] - 1s 132us/step - loss: 3.8347e-04
Epoch 15/25
8000/8000 [==============================] - 1s 132us/step - loss: 3.3209e-04
Epoch 16/25
8000/8000 [==============================] - 1s 129us/step - loss: 2.9111e-04
Epoch 17/25
8000/8000 [==============================] - 1s 128us/step - loss: 2.6088e-04
Epoch 18/25
8000/8000 [==============================] - 1s 129us/step - loss: 2.3791e-04
Epoch 19/25
8000/8000 [==============================] - 1s 131us/step - loss: 2.1515e-04
Epoch 20/25
8000/8000 [==============================] - 1s 133us/step - loss: 2.0405e-04
Epoch 21/25
8000/8000 [==============================] - 1s 129us/step - loss: 1.8960e-04
Epoch 22/25
8000/8000 [==============================] - 1s 129us/step - loss: 1.8229e-04
Epoch 23/25
8000/8000 [==============================] - 1s 132us/step - loss: 1.7549e-04
Epoch 24/25
8000/8000 [==============================] - 1s 128us/step - loss: 1.6932e-04
Epoch 25/25
8000/8000 [==============================] - 1s 132us/step - loss: 1.6681e-04
mse rf: 0.000407 (0.000399); mse kpca: 0.000010 (0.000023); mse simec: 0.000056 (0.000068)
correlation with kPCA       : 0.974452
correlation with kPCA (test): 0.972073
e_dims= [2, 4, 6, 10, 15, 25, 50, 100]
mse_kpca= [0.0017745004425213753, 0.001166401151421366, 0.00075083181389130904, 0.00043191616606265599, 0.00025243694438209887, 0.00011809942616316585, 3.3871972879344537e-05, 1.016539504971085e-05]
mse_kpca_test= [0.0017821276693317028, 0.0011723992778948215, 0.00078748496160346349, 0.0004597333554528355, 0.00027971620685967474, 0.00013939776556833784, 5.0165125897334507e-05, 2.2917705967027005e-05]
mse_simec= [0.0018161645647067728, 0.0012218944414793349, 0.00080368514323477349, 0.00048371029591127187, 0.00029537525667105806, 0.00015256422131176058, 7.1309300933208533e-05, 5.5766923006856243e-05]
mse_simec_test= [0.0018343358754230768, 0.0012294014129893948, 0.00084058675267920102, 0.00051143222669139865, 0.00032171828917811643, 0.00017650868466713443, 8.8958216178136628e-05, 6.8330028838937211e-05]

In [30]:
# missing targets
n_targets = 1000
np.random.seed(15)
mse_simec, mse_simec_test = [], []
kpca = KernelPCA(n_components=10, kernel='rbf', gamma=gamma)
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
mse_k = check_similarity_match(X_embed, K_rbf)[0]
mse_kt = check_similarity_match(X_embed_test, K_rbf_test)[0]
missing_targets = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
for m in missing_targets:
    print(m)
    K_rbf_noisy = K_rbf.copy()
    K_rbf_noisy[np.random.rand(*K_rbf_noisy.shape)<=m] = -100
    simec = SimilarityEncoder(X.shape[1], 10, n_targets, hidden_layers=[(1000, 'tanh')], 
                              l2_reg=0.00000001, l2_reg_emb=0.00001, l2_reg_out=0.0000001, 
                              mask_value=-100, s_ll_reg=5., S_ll=K_rbf_noisy[:n_targets,:n_targets], 
                              opt=keras.optimizers.Adamax(lr=0.0005))
    simec.fit(X, K_rbf_noisy[:,:n_targets])
    X_embed = simec.transform(X)
    X_embed_test = simec.transform(X_test)
    mse = check_similarity_match(X_embed, K_rbf)[0]
    mse_simec.append(mse)
    mse_t = check_similarity_match(X_embed_test, K_rbf_test)[0]
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
keras.backend.clear_session()
colors = get_colors(10)
plt.figure();
plt.plot([0, missing_targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, missing_targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(missing_targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(missing_targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('MNIST (RBF kernel)');
plt.xticks(missing_targets, missing_targets);
plt.xlabel('Fraction of Missing Targets');
plt.ylabel('Mean Squared Error of $\hat{S}$');


0.0
Epoch 1/25
8000/8000 [==============================] - 2s 210us/step - loss: 0.0179
Epoch 2/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0089
Epoch 3/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0048
Epoch 4/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0035
Epoch 5/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0031
Epoch 6/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0030
Epoch 7/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0030
Epoch 11/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0030
Epoch 12/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 20/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 21/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 22/25
8000/8000 [==============================] - 1s 138us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000480 (0.000506)
0.1
Epoch 1/25
8000/8000 [==============================] - 1s 163us/step - loss: 0.0176
Epoch 2/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0084
Epoch 3/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0048
Epoch 4/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0037
Epoch 5/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0033
Epoch 6/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0031
Epoch 7/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 11/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0030
Epoch 12/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 20/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0029
Epoch 21/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0029
Epoch 22/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 23/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000501 (0.000529)
0.2
Epoch 1/25
8000/8000 [==============================] - 1s 165us/step - loss: 0.0178
Epoch 2/25
8000/8000 [==============================] - 1s 135us/step - loss: 0.0091
Epoch 3/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0051
Epoch 4/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0039
Epoch 5/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0033
Epoch 6/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0031
Epoch 7/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0030
Epoch 11/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 118us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 20/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 21/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000483 (0.000507)
0.3
Epoch 1/25
8000/8000 [==============================] - 1s 168us/step - loss: 0.0182
Epoch 2/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0095
Epoch 3/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0049
Epoch 4/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0036
Epoch 5/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0032
Epoch 6/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0031
Epoch 7/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0031
Epoch 8/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0030
Epoch 11/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 20/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 21/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000487 (0.000514)
0.4
Epoch 1/25
8000/8000 [==============================] - 1s 170us/step - loss: 0.0183
Epoch 2/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0101
Epoch 3/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0053
Epoch 4/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0038
Epoch 5/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0032
Epoch 6/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0031
Epoch 7/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 20/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 21/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000486 (0.000514)
0.5
Epoch 1/25
8000/8000 [==============================] - 1s 178us/step - loss: 0.0186
Epoch 2/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0105
Epoch 3/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0056
Epoch 4/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0038
Epoch 5/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0032
Epoch 6/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0030
Epoch 7/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 20/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 21/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - ETA: 0s - loss: 0.002 - 1s 130us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000495 (0.000521)
0.6
Epoch 1/25
8000/8000 [==============================] - 1s 184us/step - loss: 0.0186
Epoch 2/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0106
Epoch 3/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0056
Epoch 4/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0041
Epoch 5/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0034
Epoch 6/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0031
Epoch 7/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0030
Epoch 8/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 10/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 123us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 122us/step - loss: 0.0028
Epoch 18/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
Epoch 19/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 20/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 21/25
8000/8000 [==============================] - 1s 125us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000500 (0.000527)
0.7
Epoch 1/25
8000/8000 [==============================] - 1s 183us/step - loss: 0.0191
Epoch 2/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0123
Epoch 3/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0066
Epoch 4/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0045
Epoch 5/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0036
Epoch 6/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0033
Epoch 7/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0031
Epoch 8/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 124us/step - loss: 0.0029
Epoch 14/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 15/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0029
Epoch 16/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0029
Epoch 17/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 18/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 19/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 20/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 21/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 135us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000502 (0.000529)
0.8
Epoch 1/25
8000/8000 [==============================] - 1s 185us/step - loss: 0.0195
Epoch 2/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0138
Epoch 3/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0081
Epoch 4/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0053
Epoch 5/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0040
Epoch 6/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0033
Epoch 7/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0031
Epoch 8/25
8000/8000 [==============================] - 1s 136us/step - loss: 0.0030
Epoch 9/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 10/25
8000/8000 [==============================] - 1s 135us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 12/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0029
Epoch 13/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 14/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0028
Epoch 15/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 16/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0028
Epoch 17/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0028
Epoch 18/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0028
Epoch 19/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
Epoch 20/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0028
Epoch 21/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
Epoch 22/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 23/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
Epoch 24/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0028
Epoch 25/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0028
mse kpca: 0.000432 (0.000460); mse simec: 0.000508 (0.000537)
0.9
Epoch 1/25
8000/8000 [==============================] - 2s 188us/step - loss: 0.0200
Epoch 2/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0163
Epoch 3/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0111
Epoch 4/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0074
Epoch 5/25
8000/8000 [==============================] - 1s 134us/step - loss: 0.0053
Epoch 6/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0042
Epoch 7/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0036
Epoch 8/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0032
Epoch 9/25
8000/8000 [==============================] - 1s 133us/step - loss: 0.0030
Epoch 10/25
8000/8000 [==============================] - 1s 128us/step - loss: 0.0029
Epoch 11/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 12/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0028
Epoch 13/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0028
Epoch 14/25
8000/8000 [==============================] - 1s 130us/step - loss: 0.0027
Epoch 15/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0027
Epoch 16/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0027
Epoch 17/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0027
Epoch 18/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0027
Epoch 19/25
8000/8000 [==============================] - 1s 127us/step - loss: 0.0027
Epoch 20/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0027
Epoch 21/25
8000/8000 [==============================] - 1s 126us/step - loss: 0.0027
Epoch 22/25
8000/8000 [==============================] - 1s 131us/step - loss: 0.0027
Epoch 23/25
8000/8000 [==============================] - 1s 136us/step - loss: 0.0027
Epoch 24/25
8000/8000 [==============================] - 1s 129us/step - loss: 0.0027
Epoch 25/25
8000/8000 [==============================] - 1s 132us/step - loss: 0.0026
mse kpca: 0.000432 (0.000460); mse simec: 0.000538 (0.000562)

20 Newsgroups

To show that SimEc embeddings can also be computed for other types of data, we do some further experiments with the 20 newsgroups dataset. We subsample 7 of the 20 categories and remove meta information such as headers to avoid overfitting (see also http://scikit-learn.org/stable/datasets/twenty_newsgroups.html). The posts are transformed into very high dimensional tf-idf vectors used as input to the SimEc and to compute the linear kernel matrix.


In [31]:
## load the data and transform it into a tf-idf representation
categories = [
    "comp.graphics",
    "rec.autos",
    "rec.sport.baseball",
    "sci.med",
    "sci.space",
    "soc.religion.christian",
    "talk.politics.guns"
]
newsgroups_train = fetch_20newsgroups(subset='train', remove=(
    'headers', 'footers', 'quotes'), data_home='data', categories=categories, random_state=42)
newsgroups_test = fetch_20newsgroups(subset='test', remove=(
    'headers', 'footers', 'quotes'), data_home='data', categories=categories, random_state=42)
# store in dicts (if the text contains more than 3 words)
textdict = {i: t for i, t in enumerate(newsgroups_train.data) if len(t.split()) > 3}
textdict.update({i: t for i, t in enumerate(newsgroups_test.data, len(newsgroups_train.data)) if len(t.split()) > 3})
train_ids = [i for i in range(len(newsgroups_train.data)) if i in textdict]
test_ids = [i for i in range(len(newsgroups_train.data), len(textdict)) if i in textdict]
print("%i training and %i test samples" % (len(train_ids), len(test_ids)))
# transform into tf-idf features
ft = FeatureTransform(norm='max', weight=True, renorm='max')
docfeats = ft.texts2features(textdict, fit_ids=train_ids)
# organize in feature matrix
X, featurenames = features2mat(docfeats, train_ids)
X_test, _ = features2mat(docfeats, test_ids, featurenames)
print("%i features" % len(featurenames))
targets = np.hstack([newsgroups_train.target,newsgroups_test.target])
y = targets[train_ids]
y_test = targets[test_ids]
target_names = newsgroups_train.target_names
n_targets = 1000


3959 training and 2359 test samples
45813 features

Linear Similarity

Again, linear kPCA and SimEc give the same solution (up to a rotation). Btw, here we can't use regular PCA as the covariance matrix would be very high dimensional and poorly estimated due to the small amount of samples.


In [32]:
# linear kPCA
kpca = KernelPCA(n_components=2, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
plot_20news(X_embed, y, target_names, X_embed_test, y_test,
            title='20newsgroups - linear Kernel PCA', legend=True)
if savefigs: plt.savefig('fig_spectral_20news_lin_kpca.png', dpi=300)
# compute linear kernel and center
K_lin = center_K(X.dot(X.T).A)
K_lin_test = center_K(X_test.dot(X_test.T).A)
print("similarity approximation       : msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed, K_lin))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_test, K_lin_test))


similarity approximation       : msqe: 0.0331868908 ; r^2: 0.2263374840 ; rho: 0.6310964767
similarity approximation (test): msqe: 0.0421617582 ; r^2: 0.1775899837 ; rho: 0.6165146584

In [33]:
# project to 2d with linear similarity encoder
n_targets = 1000
simec = SimilarityEncoder(X.shape[1], 2, n_targets, sparse_inputs=True, l2_reg_emb=0.00001, 
                          l2_reg_out=0.00000001, s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets],
                          opt=keras.optimizers.Adamax(lr=0.005))
simec.fit(X, K_lin[:,:n_targets])
X_embeds = simec.transform(X)
X_embed_tests = simec.transform(X_test)
plot_20news(X_embeds, y, target_names, X_embed_tests, y_test,
            title='20 newsgroups - SimEc (lin. kernel, 0 h.l.)', legend=True)
if savefigs: plt.savefig('fig_spectral_20news_lin_simec.png', dpi=300)
print("correlation with lin kPCA: %f" % check_embed_match(X_embed, X_embeds)[1])
print("correlation with lin kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
print("similarity approximation: msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embeds, K_lin))
print("similarity approximation (test): msqe: %.10f ; r^2: %.10f ; rho: %.10f" % check_similarity_match(X_embed_tests, K_lin_test))


Epoch 1/25
3959/3959 [==============================] - 1s 168us/step - loss: 0.0839
Epoch 2/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0793
Epoch 3/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0782
Epoch 4/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0773
Epoch 5/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0767
Epoch 6/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0763
Epoch 7/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0759
Epoch 8/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0756
Epoch 9/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0754
Epoch 10/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0752
Epoch 11/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0751
Epoch 12/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0750
Epoch 13/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0749
Epoch 14/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0748
Epoch 15/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0747
Epoch 16/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0747
Epoch 17/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0746
Epoch 18/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0746
Epoch 19/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0746
Epoch 20/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0745
Epoch 21/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0745
Epoch 22/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0745
Epoch 23/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0745
Epoch 24/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0745
Epoch 25/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0744
correlation with lin kPCA: 0.885040
correlation with lin kPCA (test): 0.956905
similarity approximation: msqe: 0.0336674847 ; r^2: 0.2155332529 ; rho: 0.6170153580
similarity approximation (test): msqe: 0.0425559335 ; r^2: 0.1727221183 ; rho: 0.6100763078

In [34]:
# check how many relevant dimensions there are - obviously at most # feature dim, not # of data points
eigenvals = np.linalg.eigvalsh(K_lin)[::-1]
plt.figure();
plt.plot(list(range(1, K_lin.shape[0]+1)), eigenvals, '-o', markersize=3);
plt.plot([1, K_lin.shape[0]],[0,0], 'k--', linewidth=0.5);
plt.xlim(1, 100);
plt.title('Eigenvalue Spectrum of the linear Kernel');



In [35]:
mse_kpca, mse_kpca_test, rsq_kpca = [], [], []
mse_simec, mse_simec_test, rsq_simec = [], [], []
e_dims = [2, 4, 6, 10, 15, 25, 50, 100]
for e_dim in e_dims:
    print(e_dim)
    kpca = KernelPCA(n_components=e_dim, kernel='linear')
    X_embed = kpca.fit_transform(X)
    X_embed_test = kpca.transform(X_test)
    mse_k, rsq, _ = check_similarity_match(X_embed, K_lin)
    mse_kpca.append(mse_k)
    rsq_kpca.append(rsq)
    mse_kt, _, _ = check_similarity_match(X_embed_test, K_lin_test)
    mse_kpca_test.append(mse_kt)
    simec = SimilarityEncoder(X.shape[1], e_dim, n_targets, sparse_inputs=True, l2_reg_emb=0.00001, 
                              l2_reg_out=0.00000001, s_ll_reg=0.5, S_ll=K_lin[:n_targets,:n_targets],
                              opt=keras.optimizers.Adamax(lr=0.005))
    simec.fit(X, K_lin[:,:n_targets])
    X_embeds = simec.transform(X)
    X_embed_tests = simec.transform(X_test)
    mse, rsq, _ = check_similarity_match(X_embeds, K_lin)
    mse_simec.append(mse)
    rsq_simec.append(rsq)
    mse_t, _, _ = check_similarity_match(X_embed_tests, K_lin_test)
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
    print("correlation with linear kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
    print("correlation with linear kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
keras.backend.clear_session()
colors = get_colors(10)
plt.figure();
plt.plot(e_dims, mse_kpca, '-o', markersize=3, c=colors[4], label='kPCA');
plt.plot(e_dims, mse_kpca_test, '-o', markersize=3, c=colors[2], label='kPCA (test)');
plt.plot(e_dims, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(e_dims, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=3);
plt.title('20 newsgroups (linear kernel)');
plt.plot([0, e_dims[-1]], [0,0], 'k--', linewidth=0.5);
plt.xticks(e_dims, e_dims);
plt.xlabel('Number of Embedding Dimensions ($d$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("e_dims=", e_dims)
print("mse_kpca=", mse_kpca)
print("mse_kpca_test=", mse_kpca_test)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_20news_lin_mse_edim.pdf', dpi=300)
plt.figure();
plt.plot(e_dims, rsq_kpca, '-o', markersize=3, label='kPCA');
plt.plot(e_dims, rsq_simec, '-o', markersize=3, label='SimEc');
plt.plot([0, e_dims[-1]], [1,1], 'k--', linewidth=0.5);
plt.legend(loc=0);
plt.title('$R^2$');
plt.xticks(e_dims, e_dims);


2
Epoch 1/25
3959/3959 [==============================] - 1s 168us/step - loss: 0.0837
Epoch 2/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0791
Epoch 3/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0780
Epoch 4/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0772
Epoch 5/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0766
Epoch 6/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0761
Epoch 7/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0758
Epoch 8/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0756
Epoch 9/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0754
Epoch 10/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0752
Epoch 11/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0751
Epoch 12/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0750
Epoch 13/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0749
Epoch 14/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0748
Epoch 15/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0747
Epoch 16/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0747
Epoch 17/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0747
Epoch 18/25
3959/3959 [==============================] - 0s 112us/step - loss: 0.0746
Epoch 19/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0746
Epoch 20/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0746
Epoch 21/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0746
Epoch 22/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0745
Epoch 23/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0745
Epoch 24/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0745
Epoch 25/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0745
mse kpca: 0.033187 (0.042162); mse simec: 0.033829 (0.042596)
correlation with linear kPCA       : 0.819091
correlation with linear kPCA (test): 0.873299
4
Epoch 1/25
3959/3959 [==============================] - 1s 174us/step - loss: 0.0828
Epoch 2/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0777
Epoch 3/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0764
Epoch 4/25
3959/3959 [==============================] - 0s 110us/step - loss: 0.0755
Epoch 5/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.0748
Epoch 6/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0743
Epoch 7/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0740
Epoch 8/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0737
Epoch 9/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0735
Epoch 10/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0733
Epoch 11/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0731
Epoch 12/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0730
Epoch 13/25
3959/3959 [==============================] - 0s 110us/step - loss: 0.0729
Epoch 14/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.0727
Epoch 15/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0726
Epoch 16/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0726
Epoch 17/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0725
Epoch 18/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0724
Epoch 19/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0724
Epoch 20/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0723
Epoch 21/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0723
Epoch 22/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0722
Epoch 23/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0722
Epoch 24/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0721
Epoch 25/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0721
mse kpca: 0.031640 (0.041250); mse simec: 0.032437 (0.041652)
correlation with linear kPCA       : 0.918255
correlation with linear kPCA (test): 0.966915
6
Epoch 1/25
3959/3959 [==============================] - 1s 182us/step - loss: 0.0818
Epoch 2/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0768
Epoch 3/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0751
Epoch 4/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0741
Epoch 5/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0733
Epoch 6/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0727
Epoch 7/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.0723
Epoch 8/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0719
Epoch 9/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0717
Epoch 10/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0714
Epoch 11/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0712
Epoch 12/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0711
Epoch 13/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0710
Epoch 14/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0708
Epoch 15/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0707
Epoch 16/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0707
Epoch 17/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0706
Epoch 18/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0705
Epoch 19/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0705
Epoch 20/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0704
Epoch 21/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0704
Epoch 22/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0703
Epoch 23/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0703
Epoch 24/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0703
Epoch 25/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0702
mse kpca: 0.030550 (0.040318); mse simec: 0.031641 (0.040863)
correlation with linear kPCA       : 0.902384
correlation with linear kPCA (test): 0.969861
10
Epoch 1/25
3959/3959 [==============================] - 1s 181us/step - loss: 0.0804
Epoch 2/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0754
Epoch 3/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0735
Epoch 4/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0723
Epoch 5/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0715
Epoch 6/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0708
Epoch 7/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0704
Epoch 8/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0700
Epoch 9/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0697
Epoch 10/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0694
Epoch 11/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0692
Epoch 12/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0689
Epoch 13/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0688
Epoch 14/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0686
Epoch 15/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0685
Epoch 16/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0684
Epoch 17/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0683
Epoch 18/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0682
Epoch 19/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0682
Epoch 20/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0681
Epoch 21/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0680
Epoch 22/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0680
Epoch 23/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0679
Epoch 24/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0679
Epoch 25/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0678
mse kpca: 0.029294 (0.039042); mse simec: 0.031022 (0.040043)
correlation with linear kPCA       : 0.840680
correlation with linear kPCA (test): 0.961377
15
Epoch 1/25
3959/3959 [==============================] - 1s 196us/step - loss: 0.0789
Epoch 2/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0742
Epoch 3/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0718
Epoch 4/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0705
Epoch 5/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0698
Epoch 6/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0692
Epoch 7/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0687
Epoch 8/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0683
Epoch 9/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0679
Epoch 10/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0676
Epoch 11/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0673
Epoch 12/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0671
Epoch 13/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0670
Epoch 14/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0667
Epoch 15/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0666
Epoch 16/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0665
Epoch 17/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0664
Epoch 18/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0662
Epoch 19/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0661
Epoch 20/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0660
Epoch 21/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0659
Epoch 22/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0658
Epoch 23/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0657
Epoch 24/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0656
Epoch 25/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0655
mse kpca: 0.028281 (0.038145); mse simec: 0.030579 (0.039635)
correlation with linear kPCA       : 0.750217
correlation with linear kPCA (test): 0.940522
25
Epoch 1/25
3959/3959 [==============================] - 1s 233us/step - loss: 0.0774
Epoch 2/25
3959/3959 [==============================] - 1s 153us/step - loss: 0.0723
Epoch 3/25
3959/3959 [==============================] - 1s 151us/step - loss: 0.0695
Epoch 4/25
3959/3959 [==============================] - 1s 162us/step - loss: 0.0681
Epoch 5/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0673
Epoch 6/25
3959/3959 [==============================] - 1s 148us/step - loss: 0.0666
Epoch 7/25
3959/3959 [==============================] - 1s 148us/step - loss: 0.0660
Epoch 8/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0655
Epoch 9/25
3959/3959 [==============================] - 1s 145us/step - loss: 0.0650
Epoch 10/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0647
Epoch 11/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0644
Epoch 12/25
3959/3959 [==============================] - 1s 148us/step - loss: 0.0641
Epoch 13/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0638
Epoch 14/25
3959/3959 [==============================] - 1s 148us/step - loss: 0.0635
Epoch 15/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0633
Epoch 16/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0631
Epoch 17/25
3959/3959 [==============================] - 1s 146us/step - loss: 0.0629
Epoch 18/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0627
Epoch 19/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0625
Epoch 20/25
3959/3959 [==============================] - 1s 145us/step - loss: 0.0623
Epoch 21/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0622
Epoch 22/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0621
Epoch 23/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0619
Epoch 24/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0617
Epoch 25/25
3959/3959 [==============================] - 1s 151us/step - loss: 0.0617
mse kpca: 0.026858 (0.037200); mse simec: 0.030044 (0.039104)
correlation with linear kPCA       : 0.614454
correlation with linear kPCA (test): 0.917135
50
Epoch 1/25
3959/3959 [==============================] - 1s 302us/step - loss: 0.0752
Epoch 2/25
3959/3959 [==============================] - 1s 197us/step - loss: 0.0689
Epoch 3/25
3959/3959 [==============================] - 1s 190us/step - loss: 0.0645
Epoch 4/25
3959/3959 [==============================] - 1s 195us/step - loss: 0.0626
Epoch 5/25
3959/3959 [==============================] - 1s 196us/step - loss: 0.0615
Epoch 6/25
3959/3959 [==============================] - 1s 200us/step - loss: 0.0606
Epoch 7/25
3959/3959 [==============================] - 1s 199us/step - loss: 0.0598
Epoch 8/25
3959/3959 [==============================] - 1s 201us/step - loss: 0.0590
Epoch 9/25
3959/3959 [==============================] - 1s 195us/step - loss: 0.0584
Epoch 10/25
3959/3959 [==============================] - 1s 198us/step - loss: 0.0578
Epoch 11/25
3959/3959 [==============================] - 1s 202us/step - loss: 0.0574
Epoch 12/25
3959/3959 [==============================] - 1s 199us/step - loss: 0.0569
Epoch 13/25
3959/3959 [==============================] - 1s 194us/step - loss: 0.0565
Epoch 14/25
3959/3959 [==============================] - 1s 193us/step - loss: 0.0561
Epoch 15/25
3959/3959 [==============================] - 1s 193us/step - loss: 0.0558
Epoch 16/25
3959/3959 [==============================] - 1s 195us/step - loss: 0.0555
Epoch 17/25
3959/3959 [==============================] - 1s 197us/step - loss: 0.0552
Epoch 18/25
3959/3959 [==============================] - 1s 196us/step - loss: 0.0549
Epoch 19/25
3959/3959 [==============================] - 1s 197us/step - loss: 0.0547
Epoch 20/25
3959/3959 [==============================] - 1s 195us/step - loss: 0.0545
Epoch 21/25
3959/3959 [==============================] - 1s 197us/step - loss: 0.0543
Epoch 22/25
3959/3959 [==============================] - 1s 203us/step - loss: 0.0541
Epoch 23/25
3959/3959 [==============================] - 1s 198us/step - loss: 0.0539
Epoch 24/25
3959/3959 [==============================] - 1s 199us/step - loss: 0.0538
Epoch 25/25
3959/3959 [==============================] - 1s 196us/step - loss: 0.0536
mse kpca: 0.024406 (0.036023); mse simec: 0.028369 (0.038228)
correlation with linear kPCA       : 0.532998
correlation with linear kPCA (test): 0.926088
100
Epoch 1/25
3959/3959 [==============================] - 2s 425us/step - loss: 0.0711
Epoch 2/25
3959/3959 [==============================] - 1s 295us/step - loss: 0.0622
Epoch 3/25
3959/3959 [==============================] - 1s 294us/step - loss: 0.0560
Epoch 4/25
3959/3959 [==============================] - 1s 294us/step - loss: 0.0531
Epoch 5/25
3959/3959 [==============================] - 1s 296us/step - loss: 0.0514
Epoch 6/25
3959/3959 [==============================] - 1s 298us/step - loss: 0.0500
Epoch 7/25
3959/3959 [==============================] - 1s 290us/step - loss: 0.0490
Epoch 8/25
3959/3959 [==============================] - 1s 298us/step - loss: 0.0482
Epoch 9/25
3959/3959 [==============================] - 1s 293us/step - loss: 0.0474
Epoch 10/25
3959/3959 [==============================] - 1s 296us/step - loss: 0.0466
Epoch 11/25
3959/3959 [==============================] - 1s 298us/step - loss: 0.0460
Epoch 12/25
3959/3959 [==============================] - 1s 298us/step - loss: 0.0456
Epoch 13/25
3959/3959 [==============================] - 1s 294us/step - loss: 0.0451
Epoch 14/25
3959/3959 [==============================] - 1s 299us/step - loss: 0.0446
Epoch 15/25
3959/3959 [==============================] - 1s 300us/step - loss: 0.0442
Epoch 16/25
3959/3959 [==============================] - 1s 300us/step - loss: 0.0437
Epoch 17/25
3959/3959 [==============================] - 1s 301us/step - loss: 0.0434
Epoch 18/25
3959/3959 [==============================] - 1s 297us/step - loss: 0.0431
Epoch 19/25
3959/3959 [==============================] - 1s 289us/step - loss: 0.0428
Epoch 20/25
3959/3959 [==============================] - 1s 298us/step - loss: 0.0426
Epoch 21/25
3959/3959 [==============================] - 1s 303us/step - loss: 0.0424
Epoch 22/25
3959/3959 [==============================] - 1s 302us/step - loss: 0.0421
Epoch 23/25
3959/3959 [==============================] - 1s 302us/step - loss: 0.0419
Epoch 24/25
3959/3959 [==============================] - 1s 301us/step - loss: 0.0418
Epoch 25/25
3959/3959 [==============================] - 1s 299us/step - loss: 0.0417
mse kpca: 0.021002 (0.034524); mse simec: 0.026541 (0.037030)
correlation with linear kPCA       : 0.465691
correlation with linear kPCA (test): 0.922928
e_dims= [2, 4, 6, 10, 15, 25, 50, 100]
mse_kpca= [0.033186890803593286, 0.031639502165242001, 0.030550446352557908, 0.02929391120094103, 0.028281273921272679, 0.026858088327732271, 0.024406205725514298, 0.021001803470957738]
mse_kpca_test= [0.042161758177902464, 0.041249801535220863, 0.040317551266763299, 0.039042077252335036, 0.03814530760262002, 0.037199552639659031, 0.036022809587031072, 0.03452397514033767]
mse_simec= [0.033829266374082921, 0.032436777333314806, 0.031640760954261125, 0.031021662377004121, 0.030579202260866835, 0.030044174870215969, 0.028369194847820852, 0.026541403025161555]
mse_simec_test= [0.042596307791198301, 0.041652056702888199, 0.040862871763862378, 0.040042507008801125, 0.039635288593212969, 0.039103635688072715, 0.038227993729053632, 0.037029810117198018]

In [36]:
# check effect of different number of targets
mse_simec, mse_simec_test = [], []
targets = [100, 250, 500, 750, 1000, 1500, 2500, K_lin.shape[1]]
e_dim = 10
kpca = KernelPCA(n_components=e_dim, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
mse_k, _, _ = check_similarity_match(X_embed, K_lin)
mse_kt, _, _ = check_similarity_match(X_embed_test, K_lin_test)
for n in targets:
    print(n)
    simec = SimilarityEncoder(X.shape[1], e_dim, n, sparse_inputs=True, l2_reg_emb=0.00001, 
                              l2_reg_out=0.00000001, s_ll_reg=0.5, S_ll=K_lin[:n,:n],
                              opt=keras.optimizers.Adamax(lr=0.005))
    simec.fit(X, K_lin[:,:n])
    X_embeds = simec.transform(X)
    X_embed_tests = simec.transform(X_test)
    mse, _, _ = check_similarity_match(X_embeds, K_lin)
    mse_simec.append(mse)
    mse_t, _, _ = check_similarity_match(X_embed_tests, K_lin_test)
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
    print("correlation with linear kPCA       : %f" % check_embed_match(X_embed, X_embeds)[1])
    print("correlation with linear kPCA (test): %f" % check_embed_match(X_embed_test, X_embed_tests)[1])
colors = get_colors(10)
plt.figure();
plt.plot([0, targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('20 newsgroups (linear kernel)');
plt.xticks([100, 500, 1000, 1500, 2500, 4000], [100, 500, 1000, 1500, 2500, 4000]);
plt.xlabel('Number of Targets ($n$)')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("targets=", targets)
print("mse_k=", mse_k)
print("mse_kt=", mse_kt)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_20news_lin_mse_ntargets.pdf', dpi=300)


100
Epoch 1/25
3959/3959 [==============================] - 1s 153us/step - loss: 0.4639
Epoch 2/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.4077
Epoch 3/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.3785
Epoch 4/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.3596
Epoch 5/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.3461
Epoch 6/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.3357
Epoch 7/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.3272
Epoch 8/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.3198
Epoch 9/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.3135
Epoch 10/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.3081
Epoch 11/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.3036
Epoch 12/25
3959/3959 [==============================] - 0s 113us/step - loss: 0.2999
Epoch 13/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.2970
Epoch 14/25
3959/3959 [==============================] - 0s 112us/step - loss: 0.2948
Epoch 15/25
3959/3959 [==============================] - 0s 110us/step - loss: 0.2932
Epoch 16/25
3959/3959 [==============================] - 0s 112us/step - loss: 0.2918
Epoch 17/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.2906
Epoch 18/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.2895
Epoch 19/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.2886
Epoch 20/25
3959/3959 [==============================] - 0s 113us/step - loss: 0.2877
Epoch 21/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.2869
Epoch 22/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.2861
Epoch 23/25
3959/3959 [==============================] - 0s 112us/step - loss: 0.2853
Epoch 24/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.2845
Epoch 25/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.2838
mse kpca: 0.029294 (0.039042); mse simec: 0.037255 (0.046164)
correlation with linear kPCA       : 0.226287
correlation with linear kPCA (test): 0.699562
250
Epoch 1/25
3959/3959 [==============================] - 1s 153us/step - loss: 0.1940
Epoch 2/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1819
Epoch 3/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.1764
Epoch 4/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.1732
Epoch 5/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.1710
Epoch 6/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.1693
Epoch 7/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.1678
Epoch 8/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.1664
Epoch 9/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.1652
Epoch 10/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.1641
Epoch 11/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1631
Epoch 12/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.1621
Epoch 13/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.1611
Epoch 14/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.1602
Epoch 15/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1594
Epoch 16/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.1586
Epoch 17/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.1579
Epoch 18/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1572
Epoch 19/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.1564
Epoch 20/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1558
Epoch 21/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.1553
Epoch 22/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.1547
Epoch 23/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.1541
Epoch 24/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.1535
Epoch 25/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.1530
mse kpca: 0.029294 (0.039042); mse simec: 0.034211 (0.043276)
correlation with linear kPCA       : 0.446842
correlation with linear kPCA (test): 0.857856
500
Epoch 1/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.1160
Epoch 2/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.1093
Epoch 3/25
3959/3959 [==============================] - 0s 114us/step - loss: 0.1066
Epoch 4/25
3959/3959 [==============================] - 0s 113us/step - loss: 0.1051
Epoch 5/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.1041
Epoch 6/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.1033
Epoch 7/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.1026
Epoch 8/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.1022
Epoch 9/25
3959/3959 [==============================] - 0s 112us/step - loss: 0.1018
Epoch 10/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.1014
Epoch 11/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.1010
Epoch 12/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.1006
Epoch 13/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.1003
Epoch 14/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.1002
Epoch 15/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0999
Epoch 16/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0997
Epoch 17/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0995
Epoch 18/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0993
Epoch 19/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0991
Epoch 20/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0989
Epoch 21/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0988
Epoch 22/25
3959/3959 [==============================] - 0s 115us/step - loss: 0.0986
Epoch 23/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0985
Epoch 24/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0984
Epoch 25/25
3959/3959 [==============================] - 0s 122us/step - loss: 0.0982
mse kpca: 0.029294 (0.039042); mse simec: 0.032331 (0.041131)
correlation with linear kPCA       : 0.665873
correlation with linear kPCA (test): 0.907408
750
Epoch 1/25
3959/3959 [==============================] - 1s 165us/step - loss: 0.0937
Epoch 2/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0879
Epoch 3/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0855 0s - loss:
Epoch 4/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0841
Epoch 5/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0832
Epoch 6/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0826
Epoch 7/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0820
Epoch 8/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0816
Epoch 9/25
3959/3959 [==============================] - 0s 111us/step - loss: 0.0812
Epoch 10/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0809
Epoch 11/25
3959/3959 [==============================] - 0s 119us/step - loss: 0.0806
Epoch 12/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0804
Epoch 13/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0802
Epoch 14/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0800
Epoch 15/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0798
Epoch 16/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0797
Epoch 17/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0796
Epoch 18/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0795
Epoch 19/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0793
Epoch 20/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0793
Epoch 21/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0792
Epoch 22/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0790
Epoch 23/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0789
Epoch 24/25
3959/3959 [==============================] - 0s 116us/step - loss: 0.0789
Epoch 25/25
3959/3959 [==============================] - 0s 121us/step - loss: 0.0789
mse kpca: 0.029294 (0.039042); mse simec: 0.031308 (0.040456)
correlation with linear kPCA       : 0.804652
correlation with linear kPCA (test): 0.953227
1000
Epoch 1/25
3959/3959 [==============================] - 1s 176us/step - loss: 0.0805
Epoch 2/25
3959/3959 [==============================] - 0s 118us/step - loss: 0.0755
Epoch 3/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0735
Epoch 4/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0724
Epoch 5/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0716 0s - loss:
Epoch 6/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0711
Epoch 7/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0706
Epoch 8/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0702
Epoch 9/25
3959/3959 [==============================] - 0s 117us/step - loss: 0.0699
Epoch 10/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0696
Epoch 11/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0694
Epoch 12/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0692
Epoch 13/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0690
Epoch 14/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0688
Epoch 15/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0688
Epoch 16/25
3959/3959 [==============================] - 0s 120us/step - loss: 0.0687
Epoch 17/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0685
Epoch 18/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0684
Epoch 19/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0683
Epoch 20/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0682
Epoch 21/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0682
Epoch 22/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0681
Epoch 23/25
3959/3959 [==============================] - 0s 123us/step - loss: 0.0680
Epoch 24/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0680
Epoch 25/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0679
mse kpca: 0.029294 (0.039042); mse simec: 0.031116 (0.040184)
correlation with linear kPCA       : 0.831625
correlation with linear kPCA (test): 0.958933
1500
Epoch 1/25
3959/3959 [==============================] - 1s 213us/step - loss: 0.0719
Epoch 2/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0675
Epoch 3/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0656
Epoch 4/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0644
Epoch 5/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0635
Epoch 6/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0629
Epoch 7/25
3959/3959 [==============================] - 1s 154us/step - loss: 0.0624
Epoch 8/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0620
Epoch 9/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0616
Epoch 10/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0613
Epoch 11/25
3959/3959 [==============================] - 1s 148us/step - loss: 0.0611
Epoch 12/25
3959/3959 [==============================] - 1s 146us/step - loss: 0.0609
Epoch 13/25
3959/3959 [==============================] - 1s 145us/step - loss: 0.0607
Epoch 14/25
3959/3959 [==============================] - 1s 145us/step - loss: 0.0606
Epoch 15/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0604
Epoch 16/25
3959/3959 [==============================] - 1s 150us/step - loss: 0.0603
Epoch 17/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0602
Epoch 18/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0601
Epoch 19/25
3959/3959 [==============================] - 1s 149us/step - loss: 0.0601
Epoch 20/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0600
Epoch 21/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0599
Epoch 22/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0599
Epoch 23/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0598
Epoch 24/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0597
Epoch 25/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0597
mse kpca: 0.029294 (0.039042); mse simec: 0.030551 (0.039632)
correlation with linear kPCA       : 0.907094
correlation with linear kPCA (test): 0.977151
2500
Epoch 1/25
3959/3959 [==============================] - 1s 331us/step - loss: 0.0620
Epoch 2/25
3959/3959 [==============================] - 1s 212us/step - loss: 0.0573
Epoch 3/25
3959/3959 [==============================] - 1s 219us/step - loss: 0.0554
Epoch 4/25
3959/3959 [==============================] - 1s 219us/step - loss: 0.0543
Epoch 5/25
3959/3959 [==============================] - 1s 215us/step - loss: 0.0536
Epoch 6/25
3959/3959 [==============================] - 1s 207us/step - loss: 0.0530
Epoch 7/25
3959/3959 [==============================] - 1s 216us/step - loss: 0.0526
Epoch 8/25
3959/3959 [==============================] - 1s 212us/step - loss: 0.0522
Epoch 9/25
3959/3959 [==============================] - 1s 209us/step - loss: 0.0519
Epoch 10/25
3959/3959 [==============================] - 1s 209us/step - loss: 0.0516
Epoch 11/25
3959/3959 [==============================] - 1s 210us/step - loss: 0.0514
Epoch 12/25
3959/3959 [==============================] - 1s 210us/step - loss: 0.0512
Epoch 13/25
3959/3959 [==============================] - 1s 212us/step - loss: 0.0511
Epoch 14/25
3959/3959 [==============================] - 1s 217us/step - loss: 0.0509
Epoch 15/25
3959/3959 [==============================] - 1s 213us/step - loss: 0.0508
Epoch 16/25
3959/3959 [==============================] - 1s 213us/step - loss: 0.0507
Epoch 17/25
3959/3959 [==============================] - 1s 213us/step - loss: 0.0506
Epoch 18/25
3959/3959 [==============================] - 1s 212us/step - loss: 0.0506
Epoch 19/25
3959/3959 [==============================] - 1s 212us/step - loss: 0.0505
Epoch 20/25
3959/3959 [==============================] - 1s 208us/step - loss: 0.0505
Epoch 21/25
3959/3959 [==============================] - 1s 204us/step - loss: 0.0504
Epoch 22/25
3959/3959 [==============================] - 1s 210us/step - loss: 0.0503
Epoch 23/25
3959/3959 [==============================] - 1s 210us/step - loss: 0.0503
Epoch 24/25
3959/3959 [==============================] - 1s 203us/step - loss: 0.0503
Epoch 25/25
3959/3959 [==============================] - 1s 210us/step - loss: 0.0502
mse kpca: 0.029294 (0.039042); mse simec: 0.030500 (0.039204)
correlation with linear kPCA       : 0.948699
correlation with linear kPCA (test): 0.980577
3959
Epoch 1/25
3959/3959 [==============================] - 2s 576us/step - loss: 0.0576
Epoch 2/25
3959/3959 [==============================] - 1s 348us/step - loss: 0.0524
Epoch 3/25
3959/3959 [==============================] - 1s 351us/step - loss: 0.0503
Epoch 4/25
3959/3959 [==============================] - 1s 354us/step - loss: 0.0491
Epoch 5/25
3959/3959 [==============================] - 1s 352us/step - loss: 0.0484
Epoch 6/25
3959/3959 [==============================] - 1s 349us/step - loss: 0.0478
Epoch 7/25
3959/3959 [==============================] - 1s 345us/step - loss: 0.0472
Epoch 8/25
3959/3959 [==============================] - 1s 348us/step - loss: 0.0468
Epoch 9/25
3959/3959 [==============================] - 1s 347us/step - loss: 0.0464
Epoch 10/25
3959/3959 [==============================] - 1s 350us/step - loss: 0.0462
Epoch 11/25
3959/3959 [==============================] - 1s 352us/step - loss: 0.0459
Epoch 12/25
3959/3959 [==============================] - 1s 340us/step - loss: 0.0458
Epoch 13/25
3959/3959 [==============================] - 1s 352us/step - loss: 0.0456
Epoch 14/25
3959/3959 [==============================] - 1s 350us/step - loss: 0.0454
Epoch 15/25
3959/3959 [==============================] - 1s 350us/step - loss: 0.0453
Epoch 16/25
3959/3959 [==============================] - 1s 348us/step - loss: 0.0452
Epoch 17/25
3959/3959 [==============================] - 1s 346us/step - loss: 0.0451
Epoch 18/25
3959/3959 [==============================] - 1s 350us/step - loss: 0.0450
Epoch 19/25
3959/3959 [==============================] - 1s 349us/step - loss: 0.0450
Epoch 20/25
3959/3959 [==============================] - 1s 348us/step - loss: 0.0449
Epoch 21/25
3959/3959 [==============================] - 1s 348us/step - loss: 0.0448
Epoch 22/25
3959/3959 [==============================] - 1s 353us/step - loss: 0.0448
Epoch 23/25
3959/3959 [==============================] - 1s 353us/step - loss: 0.0448
Epoch 24/25
3959/3959 [==============================] - 1s 353us/step - loss: 0.0447
Epoch 25/25
3959/3959 [==============================] - 1s 346us/step - loss: 0.0447
mse kpca: 0.029294 (0.039042); mse simec: 0.030432 (0.038991)
correlation with linear kPCA       : 0.974076
correlation with linear kPCA (test): 0.989799
targets= [100, 250, 500, 750, 1000, 1500, 2500, 3959]
mse_k= 0.0292939112009
mse_kt= 0.0390420772523
mse_simec= [0.037254581793760344, 0.034210729493566926, 0.032330674881625707, 0.031307974635231009, 0.031116453094023663, 0.030550919247532352, 0.030500423635552058, 0.03043234004361722]
mse_simec_test= [0.046163819654653639, 0.043276113054851573, 0.041130859806255374, 0.040456137221173069, 0.040183739830420166, 0.03963220006319474, 0.039203803514590345, 0.038991224502651238]

In [37]:
# check effect of missing target values
n_targets = 1000
np.random.seed(10)
mse_simec, mse_simec_test = [], []
kpca = KernelPCA(n_components=10, kernel='linear')
X_embed = kpca.fit_transform(X)
X_embed_test = kpca.transform(X_test)
mse_k = check_similarity_match(X_embed, K_lin)[0]
mse_kt = check_similarity_match(X_embed_test, K_lin_test)[0]
missing_targets = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
for m in missing_targets:
    print(m)
    K_lin_noisy = K_lin.copy()
    K_lin_noisy[np.random.rand(*K_lin_noisy.shape)<=m] = -100
    simec = SimilarityEncoder(X.shape[1], 10, n_targets, mask_value=-100, sparse_inputs=True, l2_reg_emb=0.00001, 
                              l2_reg_out=0.00000001, s_ll_reg=0.5, S_ll=K_lin_noisy[:n_targets,:n_targets],
                              opt=keras.optimizers.Adamax(lr=0.005))
    simec.fit(X, K_lin_noisy[:,:n_targets])
    X_embed = simec.transform(X)
    X_embed_test = simec.transform(X_test)
    mse = check_similarity_match(X_embed, K_lin)[0]
    mse_simec.append(mse)
    mse_t = check_similarity_match(X_embed_test, K_lin_test)[0]
    mse_simec_test.append(mse_t)
    print("mse kpca: %f (%f); mse simec: %f (%f)" % (mse_k, mse_kt, mse, mse_t))
keras.backend.clear_session()
colors = get_colors(10)
plt.figure();
plt.plot([0, missing_targets[-1]], [mse_k, mse_k], '--', linewidth=0.5, c=colors[8], label='kPCA');
plt.plot([0, missing_targets[-1]], [mse_kt, mse_kt], '--', linewidth=0.5, c=colors[6], label='kPCA (test)');
plt.plot(missing_targets, mse_simec, '-o', markersize=3, c=colors[8], label='SimEc');
plt.plot(missing_targets, mse_simec_test, '-o', markersize=3, c=colors[6], label='SimEc (test)');
plt.legend(loc=0);
plt.title('20 newsgroups (linear kernel)');
plt.xticks(missing_targets, missing_targets);
plt.xlabel('Fraction of Missing Targets')
plt.ylabel('Mean Squared Error of $\hat{S}$')
print("missing_targets=", missing_targets)
print("mse_k=", mse_k)
print("mse_kt=", mse_kt)
print("mse_simec=", mse_simec)
print("mse_simec_test=", mse_simec_test)
if savefigs: plt.savefig('fig_spectral_20news_lin_mse_missingt.pdf', dpi=300)


0.0
Epoch 1/25
3959/3959 [==============================] - 1s 211us/step - loss: 0.0801
Epoch 2/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0754
Epoch 3/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0733
Epoch 4/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0721
Epoch 5/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0713
Epoch 6/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0708
Epoch 7/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0703
Epoch 8/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0699
Epoch 9/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0696
Epoch 10/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0693
Epoch 11/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0691
Epoch 12/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0689
Epoch 13/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0688
Epoch 14/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0687
Epoch 15/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0685
Epoch 16/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0684
Epoch 17/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0683
Epoch 18/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0682
Epoch 19/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0681
Epoch 20/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0681
Epoch 21/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0680
Epoch 22/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0680
Epoch 23/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0679
Epoch 24/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0678
Epoch 25/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0678
mse kpca: 0.029294 (0.039042); mse simec: 0.031043 (0.040008)
0.1
Epoch 1/25
3959/3959 [==============================] - 1s 217us/step - loss: 0.0806
Epoch 2/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0765
Epoch 3/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0743
Epoch 4/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0729
Epoch 5/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0721
Epoch 6/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0715
Epoch 7/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0710
Epoch 8/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0706
Epoch 9/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0702
Epoch 10/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0699
Epoch 11/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0697
Epoch 12/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0694
Epoch 13/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0692
Epoch 14/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0690
Epoch 15/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0689
Epoch 16/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0688
Epoch 17/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0686
Epoch 18/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0685
Epoch 19/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0684
Epoch 20/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0683
Epoch 21/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0682
Epoch 22/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0682
Epoch 23/25
3959/3959 [==============================] - 0s 125us/step - loss: 0.0681
Epoch 24/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0680
Epoch 25/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0680
mse kpca: 0.029294 (0.039042); mse simec: 0.030993 (0.039992)
0.2
Epoch 1/25
3959/3959 [==============================] - 1s 227us/step - loss: 0.0809
Epoch 2/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0762
Epoch 3/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0742
Epoch 4/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0730
Epoch 5/25
3959/3959 [==============================] - 1s 126us/step - loss: 0.0722
Epoch 6/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0716
Epoch 7/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0711
Epoch 8/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0707
Epoch 9/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0703
Epoch 10/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0700
Epoch 11/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0698
Epoch 12/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0696
Epoch 13/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0694
Epoch 14/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0692
Epoch 15/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0691
Epoch 16/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0689
Epoch 17/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0688
Epoch 18/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0687
Epoch 19/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0685
Epoch 20/25
3959/3959 [==============================] - 0s 124us/step - loss: 0.0685
Epoch 21/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0684
Epoch 22/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0683
Epoch 23/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0682
Epoch 24/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0681
Epoch 25/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0681
mse kpca: 0.029294 (0.039042); mse simec: 0.031342 (0.040119)
0.3
Epoch 1/25
3959/3959 [==============================] - 1s 231us/step - loss: 0.0856
Epoch 2/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0805
Epoch 3/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0787
Epoch 4/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0775
Epoch 5/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0767
Epoch 6/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0761
Epoch 7/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0755
Epoch 8/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0750
Epoch 9/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0747
Epoch 10/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0743
Epoch 11/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0740
Epoch 12/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0738
Epoch 13/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0736
Epoch 14/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0733
Epoch 15/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0732
Epoch 16/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0730
Epoch 17/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0728
Epoch 18/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0727
Epoch 19/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0726
Epoch 20/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0724
Epoch 21/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0723
Epoch 22/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0722
Epoch 23/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0720
Epoch 24/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0719
Epoch 25/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0719
mse kpca: 0.029294 (0.039042); mse simec: 0.031498 (0.040430)
0.4
Epoch 1/25
3959/3959 [==============================] - 1s 244us/step - loss: 0.0857
Epoch 2/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0802
Epoch 3/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0782
Epoch 4/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0769
Epoch 5/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0760
Epoch 6/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0753
Epoch 7/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0748
Epoch 8/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0744
Epoch 9/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0739
Epoch 10/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0735
Epoch 11/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0732
Epoch 12/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0729
Epoch 13/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0726
Epoch 14/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0724
Epoch 15/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0722
Epoch 16/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0720
Epoch 17/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0718
Epoch 18/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0716
Epoch 19/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0715
Epoch 20/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0713
Epoch 21/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0712
Epoch 22/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0711
Epoch 23/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0709
Epoch 24/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0708
Epoch 25/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0707
mse kpca: 0.029294 (0.039042); mse simec: 0.031700 (0.040171)
0.5
Epoch 1/25
3959/3959 [==============================] - 1s 232us/step - loss: 0.0778
Epoch 2/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0732
Epoch 3/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0712
Epoch 4/25
3959/3959 [==============================] - 1s 144us/step - loss: 0.0700
Epoch 5/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0691
Epoch 6/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0685
Epoch 7/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0679
Epoch 8/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0675
Epoch 9/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0671
Epoch 10/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0668
Epoch 11/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0665
Epoch 12/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0662
Epoch 13/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0660
Epoch 14/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0658
Epoch 15/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0655
Epoch 16/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0653
Epoch 17/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0651
Epoch 18/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0650
Epoch 19/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0648
Epoch 20/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0647
Epoch 21/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0645
Epoch 22/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0643
Epoch 23/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0642
Epoch 24/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0641
Epoch 25/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0640
mse kpca: 0.029294 (0.039042); mse simec: 0.032366 (0.040350)
0.6
Epoch 1/25
3959/3959 [==============================] - 1s 252us/step - loss: 0.0798
Epoch 2/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0749
Epoch 3/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0728
Epoch 4/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0716
Epoch 5/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0707
Epoch 6/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0700
Epoch 7/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0693
Epoch 8/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0688
Epoch 9/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0684
Epoch 10/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0680
Epoch 11/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0677
Epoch 12/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0675
Epoch 13/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0672
Epoch 14/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0669
Epoch 15/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0667
Epoch 16/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0665
Epoch 17/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0663
Epoch 18/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0661
Epoch 19/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0659
Epoch 20/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0657
Epoch 21/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0655
Epoch 22/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0654
Epoch 23/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0652
Epoch 24/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0651
Epoch 25/25
3959/3959 [==============================] - 1s 140us/step - loss: 0.0649
mse kpca: 0.029294 (0.039042); mse simec: 0.033034 (0.040595)
0.7
Epoch 1/25
3959/3959 [==============================] - 1s 249us/step - loss: 0.0808
Epoch 2/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0754
Epoch 3/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0732
Epoch 4/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0718
Epoch 5/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0708
Epoch 6/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0701
Epoch 7/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0694
Epoch 8/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0688
Epoch 9/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0683
Epoch 10/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0678
Epoch 11/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0674
Epoch 12/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0670
Epoch 13/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0667
Epoch 14/25
3959/3959 [==============================] - 1s 143us/step - loss: 0.0663
Epoch 15/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0660
Epoch 16/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0658
Epoch 17/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0654
Epoch 18/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0652
Epoch 19/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0649
Epoch 20/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0647
Epoch 21/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0644
Epoch 22/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0642
Epoch 23/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0640
Epoch 24/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0637
Epoch 25/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0635
mse kpca: 0.029294 (0.039042); mse simec: 0.034620 (0.041208)
0.8
Epoch 1/25
3959/3959 [==============================] - 1s 245us/step - loss: 0.0718
Epoch 2/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0653
Epoch 3/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0628
Epoch 4/25
3959/3959 [==============================] - 1s 147us/step - loss: 0.0613
Epoch 5/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0601
Epoch 6/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0592
Epoch 7/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0583
Epoch 8/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0575
Epoch 9/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0568
Epoch 10/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0562
Epoch 11/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0557
Epoch 12/25
3959/3959 [==============================] - 1s 130us/step - loss: 0.0552
Epoch 13/25
3959/3959 [==============================] - 0s 126us/step - loss: 0.0547
Epoch 14/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0542
Epoch 15/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0537
Epoch 16/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0533
Epoch 17/25
3959/3959 [==============================] - 1s 138us/step - loss: 0.0529
Epoch 18/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0525
Epoch 19/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0521
Epoch 20/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0517
Epoch 21/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0513
Epoch 22/25
3959/3959 [==============================] - 1s 129us/step - loss: 0.0509
Epoch 23/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0505
Epoch 24/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0502
Epoch 25/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0498
mse kpca: 0.029294 (0.039042); mse simec: 0.037931 (0.041248)
0.9
Epoch 1/25
3959/3959 [==============================] - 1s 262us/step - loss: 0.0728
Epoch 2/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0645
Epoch 3/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0607
Epoch 4/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0581
Epoch 5/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0560
Epoch 6/25
3959/3959 [==============================] - 1s 134us/step - loss: 0.0542
Epoch 7/25
3959/3959 [==============================] - 1s 131us/step - loss: 0.0526
Epoch 8/25
3959/3959 [==============================] - 1s 142us/step - loss: 0.0512
Epoch 9/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0498
Epoch 10/25
3959/3959 [==============================] - 1s 146us/step - loss: 0.0486
Epoch 11/25
3959/3959 [==============================] - 1s 141us/step - loss: 0.0474
Epoch 12/25
3959/3959 [==============================] - 1s 136us/step - loss: 0.0463
Epoch 13/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0452
Epoch 14/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0442
Epoch 15/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0432
Epoch 16/25
3959/3959 [==============================] - 1s 133us/step - loss: 0.0422
Epoch 17/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0413
Epoch 18/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0404
Epoch 19/25
3959/3959 [==============================] - 1s 137us/step - loss: 0.0395
Epoch 20/25
3959/3959 [==============================] - 1s 135us/step - loss: 0.0386
Epoch 21/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0377
Epoch 22/25
3959/3959 [==============================] - 1s 139us/step - loss: 0.0369
Epoch 23/25
3959/3959 [==============================] - 1s 128us/step - loss: 0.0361
Epoch 24/25
3959/3959 [==============================] - 1s 127us/step - loss: 0.0353
Epoch 25/25
3959/3959 [==============================] - 1s 132us/step - loss: 0.0344
mse kpca: 0.029294 (0.039042); mse simec: 0.044163 (0.042434)
missing_targets= [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
mse_k= 0.0292939112009
mse_kt= 0.0390420772523
mse_simec= [0.031042699845836335, 0.030992940081091696, 0.031341634733539576, 0.031497855668136697, 0.031700429121834128, 0.032366231676765528, 0.033034217179345127, 0.03462030308718822, 0.037931151390251279, 0.044163236334731869]
mse_simec_test= [0.040007877715690081, 0.039991799604504934, 0.040119389749223903, 0.040430353781671952, 0.040171023216434482, 0.040350391488454089, 0.040595419100221554, 0.041207801108282031, 0.041248370552874065, 0.042433911384443537]

In [ ]: