-
-
Save bopjesvla/c888b98b801ff9d900b2890b0709e7e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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