In [ ]:
import sys
print(sys.version)

In [ ]:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
import time

import pandas as pd
import seaborn as sns

In [ ]:
from scipy.spatial.distance import pdist

In [ ]:
import sys
sys.path.append('../code/')

In [ ]:
from rbf_kernel import RBFKernel
from scipy.spatial.distance import squareform

In [ ]:
#X = np.array([[5., 1, 2], [0., 1, 2], [1, 4, 6], [0, 2, 4], [1., 1, 1]])
X = np.array([[5., 1], [9., 1], [1, 4]])

In [ ]:
k = RBFKernel(X)

In [ ]:
k.sigma

In [ ]:
k.sigma is None

In [ ]:
k.transform_vector(X[0,:])

In [ ]:
class chickenchicken:
    def __init__(self, X, kernel=RBFKernel):
        self.kernel = kernel(X)

In [ ]:
c = chickenchicken(X)

In [ ]:
c.kernel

In [ ]:
k.transform(X)

In [ ]:
k.sigma = 0.0001

In [ ]:
k.transform(X)

In [ ]:
X

In [ ]:
np.concatenate((X, X))

In [ ]:
def so(X, sigma):
    # pdist to calculate the squared Euclidean distances for every pair of points
    # in the 100x2 dimensional dataset.
    sq_dists = pdist(X, 'sqeuclidean')

    # Variance of the Euclidean distance between all pairs of data points.
    variance = np.var(sq_dists)

    # squareform to converts the pairwise distances into a symmetric 100x100 matrix
    mat_sq_dists = squareform(sq_dists)

    # Compute the 100x100 kernel matrix
    K = np.exp(-1/(2*sigma**2) * mat_sq_dists)
    
    return K

In [ ]:
np.multiply(X, X)

In [ ]:
so(X, 4)

Old stuff from doing by hand


In [ ]:
X - X[0,:]

In [ ]:
np.linalg.norm(X - X[0,:], axis=1)

In [ ]:
np.linalg.norm(X - X[0,:], axis=1)/(-2.)/1**2

In [ ]:
np.exp(np.linalg.norm(X - X[0,:], axis=1)/(-2.)/1**2)

In [ ]:
np.sum(X, axis=0)

In [ ]:
pdist(X)

In [ ]:


In [ ]:
squareform(pdist(X))

In [ ]: