Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local kernels #66

Open
6 tasks
briling opened this issue Jun 19, 2024 · 3 comments
Open
6 tasks

local kernels #66

briling opened this issue Jun 19, 2024 · 3 comments
Assignees

Comments

@briling
Copy link
Contributor

briling commented Jun 19, 2024

@briling briling self-assigned this Jun 19, 2024
@briling
Copy link
Contributor Author

briling commented Jun 19, 2024

@YAY-C @liam-o-marsh
Kernel names such as 'myL', 'myLfast', 'myG' are probably not very good, how would you guys replace them? (I would still keep the old ones as well for backward compatibility)

@liam-o-marsh
Copy link
Contributor

liam-o-marsh commented Jun 20, 2024

I'm not even sure what the code of 'myL' does, sorry.
what's the second argument in np.exp(K,K) for? (edit: nevermind the second K is for out)

@liam-o-marsh
Copy link
Contributor

follow-up: I tried to rewrite the custom laplacian kernel. Is there a place where it wouldn't behave like the old version?

def my_laplacian_kernel_old(X, Y, gamma):
  """ Compute Laplacian kernel between X and Y

  .. todo::
      Write the docstring
  """
  def cdist(X, Y):
    K = np.zeros((len(X),len(Y)))
    for i,x in enumerate(X):
      x = np.array([x] * len(Y))
      d = np.abs(x-Y)
      while len(d.shape)>1:
        d = np.sum(d, axis=1) # several axis available for np > 1.7.0  (TODO shall we move this)
      K[i,:] = d
    return K
  K = -gamma * cdist(X, Y)
  np.exp(K, K)
  return K

def my_laplacian_kernel(X, Y, gamma):
  """ Compute Laplacian kernel between X and Y

  .. todo::
      Write the docstring
  """

  assert X.shape[1:] == Y.shape[1:]
  innerdims = X.ndim-1
  transposer = tuple(range(1,X.ndim)) + (0,)
  K = np.tensordot(X, Y.transpose(*transposer), innerdims)
  K *= -gamma
  np.exp(K, out=K)
  return K   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants