Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     """Base class for LIBSVM Kernels has no parameters
     """
     Kernel.__init__(self, *args, **kwargs)
     self.compute()
Exemplo n.º 2
0
    def as_ls(self):
        return self

    def as_raw_np(self):
        raise ValueError, 'LibSVM calculates kernels internally; they ' +\
              'cannot be converted to Numpy'

# Conversion methods
def _as_ls(kernel):
    raise NotImplemented, 'LibSVM calculates kernels internally; they ' +\
          'cannot be converted from Numpy'
def _as_raw_ls(kernel):
    raise NotImplemented, 'LibSVM calculates kernels internally; they ' +\
          'cannot be converted from Numpy'
Kernel.add_conversion('ls', _as_ls, _as_raw_ls)

class LinearLSKernel(LSKernel):
    """A simple Linear kernel: K(a,b) = a*b.T"""
    __kernel_type__ = _svmc.LINEAR
    __kernel_name__ = 'linear'


class RbfLSKernel(LSKernel):
    """Radial Basis Function kernel (aka Gaussian):
    K(a,b) = exp(-gamma*||a-b||**2)
    """
    __kernel_type__ = _svmc.RBF
    __kernel_name__ = 'rbf'
    gamma = Parameter(1, doc='Gamma multiplying paramater for Rbf')
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     """Base class for LIBSVM Kernels has no parameters
     """
     Kernel.__init__(self, *args, **kwargs)
     self.compute()
Exemplo n.º 4
0
        raise ValueError('LibSVM calculates kernels internally; they ' +\
              'cannot be converted to Numpy')


# Conversion methods
def _as_ls(kernel):
    raise NotImplementedError('LibSVM calculates kernels internally; '
                              'they cannot be converted from Numpy')


def _as_raw_ls(kernel):
    raise NotImplementedError('LibSVM calculates kernels internally; they '
                              'cannot be converted from Numpy')


Kernel.add_conversion('ls', _as_ls, _as_raw_ls)


class LinearLSKernel(LSKernel):
    """A simple Linear kernel: K(a,b) = a*b.T"""
    __kernel_type__ = _svmc.LINEAR
    __kernel_name__ = 'linear'


class RbfLSKernel(LSKernel):
    """Radial Basis Function kernel (aka Gaussian):
    K(a,b) = exp(-gamma*||a-b||**2)
    """
    __kernel_type__ = _svmc.RBF
    __kernel_name__ = 'rbf'
    gamma = Parameter(1, doc='Gamma multiplying paramater for Rbf')
Exemplo n.º 5
0
Arquivo: sg.py Projeto: Anhmike/PyMVPA
                  'Converting data of shape %s into shogun RealFeatures'
                  % (data.shape,))
        res = RealFeatures(data.astype(float).T)
        if __debug__:
            debug('KRN_SG', 'Done converting data')

        return res

# Conversion methods
def _as_raw_sg(kernel):
    """Converts directly to a Shogun kernel"""
    return sgk.CustomKernel(kernel.as_raw_np())
def _as_sg(kernel):
    """Converts this kernel to a Shogun-based representation"""
    return PrecomputedSGKernel(matrix=kernel.as_raw_np())
Kernel.add_conversion('sg', _as_sg, _as_raw_sg)


class _BasicSGKernel(SGKernel):
    """Abstract class which can handle most shogun kernel types

    Subclasses can specify new kernels using the following declarations:

      - __kernel_cls__ = Shogun kernel class
      - __kp_order__ = Tuple which specifies the order of kernel params.
        If there is only one kernel param, this is not necessary
    """

    __TODO__ = """
    - Think either normalizer_* should not become proper Parameter.
    """
Exemplo n.º 6
0
        return res


# Conversion methods
def _as_raw_sg(kernel):
    """Converts directly to a Shogun kernel"""
    return sgk.CustomKernel(kernel.as_raw_np())


def _as_sg(kernel):
    """Converts this kernel to a Shogun-based representation"""
    return PrecomputedSGKernel(matrix=kernel.as_raw_np())


Kernel.add_conversion('sg', _as_sg, _as_raw_sg)


class _BasicSGKernel(SGKernel):
    """Abstract class which can handle most shogun kernel types

    Subclasses can specify new kernels using the following declarations:

      - __kernel_cls__ = Shogun kernel class
      - __kp_order__ = Tuple which specifies the order of kernel params.
        If there is only one kernel param, this is not necessary
    """

    __TODO__ = """
    - Think either normalizer_* should not become proper Parameter.
    """