Skip to content

Instantly share code, notes, and snippets.

@emilemathieu
Last active April 11, 2017 13:29
Show Gist options
  • Save emilemathieu/026df8545b880e7814ddc081a55a0e70 to your computer and use it in GitHub Desktop.
Save emilemathieu/026df8545b880e7814ddc081a55a0e70 to your computer and use it in GitHub Desktop.
import numpy as np
class Kernel(object):
"""Collection of usual kernels"""
@staticmethod
def linear():
def f(x, y):
return np.inner(x, y)
return f
@staticmethod
def rbf(gamma):
def f(x, y):
exponent = - gamma * np.linalg.norm(x-y) ** 2
return np.exp(exponent)
return f
@staticmethod
def quadratic(offset=0.0, gamma=1.0):
def f(x, y):
return (gamma * (offset + np.dot(x, y)) ) ** 2
return f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment