Skip to content

Instantly share code, notes, and snippets.

@bopjesvla
Created February 24, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bopjesvla/c888b98b801ff9d900b2890b0709e7e8 to your computer and use it in GitHub Desktop.
Save bopjesvla/c888b98b801ff9d900b2890b0709e7e8 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.spatial.distance import pdist
from scipy.linalg import pinv
def rbf_train(K, X, T):
# input:
# M x N training samples X
# 1 x N target outputs T
#
# output:
# K x M prototype vectors mu
# 1 x 1 scalar Gaussian with sigma
# K x 1 output weights w
[M,N] = X.shape
# select K datapoints at random
mu = np.random.shuffle(X.transpose())[0:K]
# compute global distance parameter
dmax = reduce(lambda acc, (mu1, mu2): max(acc, pdist(mu1, mu2)),
itertools.combinations(mu, 2))
sigma = dmax/((2*K)**.5)
# compute w
# Add your solution here.
return [mu, sigma, w]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment