Skip to content

Instantly share code, notes, and snippets.

@tarlanahad
Created January 9, 2020 09:57
Show Gist options
  • Save tarlanahad/01f98d322ec282ee55f5f35772695bb3 to your computer and use it in GitHub Desktop.
Save tarlanahad/01f98d322ec282ee55f5f35772695bb3 to your computer and use it in GitHub Desktop.
class RBF:
def __init__(self, X, y, tX, ty, num_of_classes,
k, std_from_clusters=True):
self.X = X
self.y = y
self.tX = tX
self.ty = ty
self.number_of_classes = num_of_classes
self.k = k
self.std_from_clusters = std_from_clusters
def convert_to_one_hot(self, x, num_of_classes):
arr = np.zeros((len(x), num_of_classes))
for i in range(len(x)):
c = int(x[i])
arr[i][c] = 1
return arr
def rbf(self, x, c, s):
distance = get_distance(x, c)
return 1 / np.exp(-distance / s ** 2)
def rbf_list(self, X, centroids, std_list):
RBF_list = []
for x in X:
RBF_list.append([self.rbf(x, c, s) for (c, s) in zip(centroids, std_list)])
return np.array(RBF_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment