I’ve trained a model like this:

  
      github.com
  
  
    iarroyof/pytorch/blob/master/gauss_kernel.py 25
# -*- coding: utf-8 -*-
import torch
from torch.autograd import Variable
from pdb import set_trace as st

def kernel_product(w, x, mode = "gaussian", s = 0.1):
    w_i = torch.t(w).unsqueeze(1)
    x_j = x.unsqueeze(0)
    xmy = ((w_i - x_j)**2).sum(2)
    #st()
    if   mode == "gaussian" : K = torch.exp( - (torch.t(xmy) ** 2) / (s**2) )
    elif mode == "laplace"  : K = torch.exp( - torch.sqrt(torch.t(xmy) + (s**2)))
    elif mode == "energy"   : K = torch.pow(   torch.t(xmy) + (s**2), -.25 )

    return K


class MyReLU(torch.autograd.Function):
    """
    We can implement our own custom autograd Functions by subclassing


  This file has been truncated. show original