Beispiel #1
0
    def __init__(self, axis, fx, fxargs=None, uattrs=None, attrfx='merge'):
        """
        Parameters
        ----------
        axis : {'samples', 'features'}
        fx : callable
        fxargs : tuple
        uattrs : list
          List of attribute names to consider. All possible combinations
          of unique elements of these attributes are used to determine the
          sample groups to operate on.
        attrfx : callable
          Functor that is called with each sample attribute elements matching
          the respective samples group. By default the unique value is
          determined. If the content of the attribute is not uniform for a
          samples group a unique string representation is created.
          If `None`, attributes are not altered.
        """
        Mapper.__init__(self)

        if not axis in ['samples', 'features']:
            raise ValueError("%s `axis` arguments can only be 'samples' or "
                             "'features' (got: '%s')." % repr(axis))
        self.__axis = axis
        self.__uattrs = uattrs
        self.__fx = fx
        if not fxargs is None:
            self.__fxargs = fxargs
        else:
            self.__fxargs = ()
        if attrfx == 'merge':
            self.__attrfx = _uniquemerge2literal
        else:
            self.__attrfx = attrfx
Beispiel #2
0
    def __init__(self, polyord=1, chunks_attr=None, opt_regs=None, **kwargs):
        """
        Parameters
        ----------
        space : str or None
          If not None, a samples attribute of the same name is added to the
          mapped dataset that stores the coordinates of each sample in the
          space that is spanned by the polynomials. If an attribute of that
          name is already present in the input dataset its values are interpreted
          as sample coordinates in the space that should be spanned by the
          polynomials.
        """
        # keep param init for historical reasons
        self.params.chunks_attr = chunks_attr
        self.params.polyord = polyord
        self.params.opt_regs = opt_regs

        # things that come from train()
        self._polycoords = None
        self._regs = None

        # secret switch to perform in-place detrending
        self._secret_inplace_detrend = False

        # need to init last to prevent base class puking
        Mapper.__init__(self, **kwargs)
Beispiel #3
0
    def __init__(self, axis, fx, fxargs=None, uattrs=None, attrfx="merge"):
        """
        Parameters
        ----------
        axis : {'samples', 'features'}
        fx : callable
        fxargs : tuple
        uattrs : list
          List of attribute names to consider. All possible combinations
          of unique elements of these attributes are used to determine the
          sample groups to operate on.
        attrfx : callable
          Functor that is called with each sample attribute elements matching
          the respective samples group. By default the unique value is
          determined. If the content of the attribute is not uniform for a
          samples group a unique string representation is created.
          If `None`, attributes are not altered.
        """
        Mapper.__init__(self)

        if not axis in ["samples", "features"]:
            raise ValueError("%s `axis` arguments can only be 'samples' or " "'features' (got: '%s')." % repr(axis))
        self.__axis = axis
        self.__uattrs = uattrs
        self.__fx = fx
        if not fxargs is None:
            self.__fxargs = fxargs
        else:
            self.__fxargs = ()
        if attrfx == "merge":
            self.__attrfx = _uniquemerge2literal
        else:
            self.__attrfx = attrfx
Beispiel #4
0
    def __init__(self, chunks_attr=None, k=8, mode='arpack', random_state=None, n_init=10, **kwargs):
        """
	parameters
        __________
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual clustering within them.
        k : int or ndarray
          The number of clusters to form as well as the number of centroids to
          generate. If init initialization string is matrix, or if a ndarray
          is given instead, it is interpreted as initial cluster to use instead
        mode : {None, 'arpack' or 'amg'}
          The eigenvalue decomposition strategy to use. AMG requires pyamg
          to be installed. It can be faster on very large, sparse problems,
          but may also lead to instabilities.
	random_state: int seed, RandomState instance, or None (default)
          A pseudo random number generator used for the initialization
          of the lobpcg eigen vectors decomposition when mode == 'amg'
          and by the K-Means initialization.
        n_init : int
	  Number of iterations of the k-means algrithm to run. Note that this 
	  differs in meaning from the iters parameter to the kmeans function.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__k = k
        self.__mode = mode
        self.__random_state = random_state
	self.__n_init = n_init
Beispiel #5
0
    def __init__(self, selector=None, demean=True):
        """Initialize the ProjectionMapper

        Parameters
        ----------
        selector : None or list
          Which components (i.e. columns of the projection matrix)
          should be used for mapping. If `selector` is `None` all
          components are used. If a list is provided, all list
          elements are treated as component ids and the respective
          components are selected (all others are discarded).
        demean : bool
          Either data should be demeaned while computing
          projections and applied back while doing reverse()
        """
        Mapper.__init__(self)

        # by default we want to wipe the feature attributes out during mapping
        self._fa_filter = []

        self._selector = selector
        self._proj = None
        """Forward projection matrix."""
        self._recon = None
        """Reverse projection (reconstruction) matrix."""
        self._demean = demean
        """Flag whether to demean the to be projected data, prior to projection.
        """
        self._offset_in = None
        """Offset (most often just mean) in the input space"""
        self._offset_out = None
        """Offset (most often just mean) in the output space"""
Beispiel #6
0
    def __init__(self, params=None, param_est=None, chunks_attr="chunks", dtype="float64", **kwargs):
        """
        Parameters
        ----------
        params : None or tuple(mean, std) or dict
          Fixed Z-Scoring parameters (mean, standard deviation). If provided,
          no parameters are estimated from the data. It is possible to specify
          individual parameters for each chunk by passing a dictionary with the
          chunk ids as keys and the parameter tuples as values. If None,
          parameters will be estimated from the training data.
        param_est : None or tuple(attrname, attrvalues)
          Limits the choice of samples used for automatic parameter estimation
          to a specific subset identified by a set of a given sample attribute
          values.  The tuple should have the name of that sample
          attribute as the first element, and a sequence of attribute values
          as the second element. If None, all samples will be used for parameter
          estimation.
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual Z-scoring within them.
        dtype : Numpy dtype, optional
          Target dtype that is used for upcasting, in case integer data is to be
          Z-scored.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__params = params
        self.__param_est = param_est
        self.__params_dict = None
        self.__dtype = dtype

        # secret switch to perform in-place z-scoring
        self._secret_inplace_zscore = False
Beispiel #7
0
    def __init__(self, demean=True, **kwargs):
        """Initialize the ProjectionMapper

        Parameters
        ----------
        demean : bool
          Either data should be demeaned while computing
          projections and applied back while doing reverse()
        """
        Mapper.__init__(self, **kwargs)

        # by default we want to wipe the feature attributes out during mapping
        self._fa_filter = []

        self._proj = None
        """Forward projection matrix."""
        self._recon = None
        """Reverse projection (reconstruction) matrix."""
        self._demean = demean
        """Flag whether to demean the to be projected data, prior to projection.
        """
        self._offset_in = None
        """Offset (most often just mean) in the input space"""
        self._offset_out = None
        """Offset (most often just mean) in the output space"""
Beispiel #8
0
    def __init__(self, num, window=None, chunks_attr=None, position_attr=None,
                 attr_strategy='remove', **kwargs):
        """
        Parameters
        ----------
        num : int
          Number of output samples. If operating on chunks, this is the number
          of samples per chunk.
        window : str or float or tuple
          Passed to scipy.signal.resample
        chunks_attr : str or None
          If not None, this samples attribute defines chunks that will be
          resampled individually.
        position_attr : str
          A samples attribute with positional information that is passed
          to scipy.signal.resample. If not None, the output dataset will
          also contain a sample attribute of this name, with updated
          positional information (this is, however, only meaningful for
          equally spaced samples).
        attr_strategy : {'remove', 'sample', 'resample'}
          Strategy to process sample attributes during mapping. 'remove' will
          cause all sample attributes to be removed. 'sample' will pick orginal
          attribute values matching the new resampling frequency (e.g. every
          10th), and 'resample' will also apply the actual data resampling
          procedure to the attributes as well (which might not be possible, e.g.
          for literal attributes).
        """
        Mapper.__init__(self, **kwargs)

        self.__num = num
        self.__window_args = window
        self.__chunks_attr = chunks_attr
        self.__position_attr = position_attr
        self.__attr_strategy = attr_strategy
Beispiel #9
0
    def __init__(self, num, window=None, chunks_attr=None, position_attr=None,
                 attr_strategy='remove', **kwargs):
        """
        Parameters
        ----------
        num : int
          Number of output samples. If operating on chunks, this is the number
          of samples per chunk.
        window : str or float or tuple
          Passed to scipy.signal.resample
        chunks_attr : str or None
          If not None, this samples attribute defines chunks that will be
          resampled individually.
        position_attr : str
          A samples attribute with positional information that is passed
          to scipy.signal.resample. If not None, the output dataset will
          also contain a sample attribute of this name, with updated
          positional information (this is, however, only meaningful for
          equally spaced samples).
        attr_strategy : {'remove', 'sample', 'resample'}
          Strategy to process sample attributes during mapping. 'remove' will
          cause all sample attributes to be removed. 'sample' will pick orginal
          attribute values matching the new resampling frequency (e.g. every
          10th), and 'resample' will also apply the actual data resampling
          procedure to the attributes as well (which might not be possible, e.g.
          for literal attributes).
        """
        Mapper.__init__(self, **kwargs)

        self.__num = num
        self.__window_args = window
        self.__chunks_attr = chunks_attr
        self.__position_attr = position_attr
        self.__attr_strategy = attr_strategy
Beispiel #10
0
    def __init__(self, chunks_attr=None, k=8, mode="arpack", random_state=None, n_init=10, **kwargs):
        """
	parameters
        __________
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual clustering within them.
        k : int or ndarray
          The number of clusters to form as well as the number of centroids to
          generate. If init initialization string is matrix, or if a ndarray
          is given instead, it is interpreted as initial cluster to use instead
        mode : {None, 'arpack' or 'amg'}
          The eigenvalue decomposition strategy to use. AMG requires pyamg
          to be installed. It can be faster on very large, sparse problems,
          but may also lead to instabilities.
	random_state: int seed, RandomState instance, or None (default)
          A pseudo random number generator used for the initialization
          of the lobpcg eigen vectors decomposition when mode == 'amg'
          and by the K-Means initialization.
        n_init : int
	  Number of iterations of the k-means algrithm to run. Note that this 
	  differs in meaning from the iters parameter to the kmeans function.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__k = k
        self.__mode = mode
        self.__random_state = random_state
        self.__n_init = n_init
Beispiel #11
0
    def __init__(self, node, nodeargs=None, **kwargs):
        """
        Parameters
        ----------
        node : mdp.Node instance
          This node instance is taken as the pristine source of which a
          copy is made for actual processing upon each training attempt.
        nodeargs : dict
          Dictionary for additional arguments for all calls to the MDP
          node. The dictionary key's meaning is as follows:

          'train'
            Arguments for calls to `Node.train()`
          'stoptrain'
            Arguments for calls to `Node.stop_training()`
          'exec'
            Arguments for calls to `Node.execute()`
          'inv'
            Arguments for calls to `Node.inverse()`

          The value for each item is always a 2-tuple, consisting of a
          tuple (for the arguments), and a dictionary (for keyword
          arguments), i.e.  ((), {}). Both, tuple and dictionary have to be
          provided even if they are empty.
        inspace : see base class
        """
        # TODO: starting from MDP2.5 this check should become:
        # TODO:   if node.has_multiple_training_phases():      
        if not len(node._train_seq) == 1:
            raise ValueError("MDPNodeMapper does not support MDP nodes with "
                             "multiple training phases.")
        Mapper.__init__(self, **kwargs)
        self.__pristine_node = None
        self.node = node
        self.nodeargs = nodeargs
Beispiel #12
0
    def __init__(self, dim=1, wavelet='sym4', mode='per', maxlevel=None):
        """Initialize _WaveletMapper mapper

        Parameters
        ----------
        dim : int or tuple of int
          dimensions to work across (for now just scalar value, ie 1D
          transformation) is supported
        wavelet : str
          one from the families available withing pywt package
        mode : str
          periodization mode
        maxlevel : int or None
          number of levels to use. If None - automatically selected by pywt
        """
        Mapper.__init__(self)

        self._dim = dim
        """Dimension to work along"""

        self._maxlevel = maxlevel
        """Maximal level of decomposition. None for automatic"""

        if not wavelet in pywt.wavelist():
            raise ValueError("Unknown family of wavelets '%s'. Please use one " \
                  "available from the list %s" % (wavelet, pywt.wavelist()))
        self._wavelet = wavelet
        """Wavelet family to use"""

        if not mode in pywt.MODES.modes:
            raise ValueError("Unknown periodization mode '%s'. Please use one " \
                  "available from the list %s" % (mode, pywt.MODES.modes))
        self._mode = mode
        """Periodization mode"""
Beispiel #13
0
    def __init__(self, demean=True):
        """Initialize the ProjectionMapper

        Parameters
        ----------
        demean : bool
          Either data should be demeaned while computing
          projections and applied back while doing reverse()
        """
        Mapper.__init__(self)

        # by default we want to wipe the feature attributes out during mapping
        self._fa_filter = []

        self._proj = None
        """Forward projection matrix."""
        self._recon = None
        """Reverse projection (reconstruction) matrix."""
        self._demean = demean
        """Flag whether to demean the to be projected data, prior to projection.
        """
        self._offset_in = None
        """Offset (most often just mean) in the input space"""
        self._offset_out = None
        """Offset (most often just mean) in the output space"""
Beispiel #14
0
    def __init__(self, fx, train_as_1st=True, **kwargs):
        """
        Parameters
        ----------
        fx : callable
          Functor that is called with the two datasets upon forward-mapping.
        train_as_1st : bool
          If True, the training dataset is passed to the target callable as
          the first argument and the other dataset as the second argument.
          If False, it is vice versa.

        Examples
        --------
        >>> from mvpa2.mappers.fxy import FxyMapper
        >>> from mvpa2.datasets import Dataset
        >>> callable = lambda x,y: len(x) > len(y)
        >>> ds1 = Dataset(range(5))
        >>> ds2 = Dataset(range(3))
        >>> fxy = FxyMapper(callable)
        >>> fxy.train(ds1)
        >>> fxy(ds2).item()
        True
        >>> fxy = FxyMapper(callable, train_as_1st=False)
        >>> fxy.train(ds1)
        >>> fxy(ds2).item()
        False
        """
        Mapper.__init__(self, **kwargs)
        self._fx = fx
        self._train_as_1st = train_as_1st
        self._ds_train = None
Beispiel #15
0
    def __init__(self, chunks_attr=None, k=8, init='k-means++', n_init=10, **kwargs):
        """
	parameters
        __________
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual clustering within them.
        k : int or ndarray
          The number of clusters to form as well as the number of centroids to
          generate. If init initialization string is matrix, or if a ndarray
          is given instead, it is interpreted as initial cluster to use instead
        init : {k-means++, random, points, matrix}
          Method for initialization, defaults to k-means++:k-means++ :
          selects initial cluster centers for k-mean clustering in a smart way
	  to speed up convergence. See section Notes in k_init for more details.
          random: generate k centroids from a Gaussian with mean and variance 
	  estimated from the data.points: choose k observations (rows) at 
	  random from data for the initial centroids.matrix: interpret the k 
	  parameter as a k by M (or length k array for one-dimensional data) 
	  array of initial centroids.
        n_init : int
	  Number of iterations of the k-means algrithm to run. Note that this 
	  differs in meaning from the iters parameter to the kmeans function.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__k = k
        self.__init = init
        self.__n_init = n_init
Beispiel #16
0
    def __init__(self, polyord=1, chunks_attr=None, opt_regs=None, **kwargs):
        """
        Parameters
        ----------
        space : str or None
          If not None, a samples attribute of the same name is added to the
          mapped dataset that stores the coordinates of each sample in the
          space that is spanned by the polynomials. If an attribute of that
          name is already present in the input dataset its values are interpreted
          as sample coordinates in the space that should be spanned by the
          polynomials.
        """
        # keep param init for historical reasons
        self.params.chunks_attr = chunks_attr
        self.params.polyord = polyord
        self.params.opt_regs = opt_regs

        # things that come from train()
        self._polycoords = None
        self._regs = None

        # secret switch to perform in-place detrending
        self._secret_inplace_detrend = False

        # need to init last to prevent base class puking
        Mapper.__init__(self, **kwargs)
Beispiel #17
0
    def __init__(self, fx, train_as_1st=True, **kwargs):
        """
        Parameters
        ----------
        fx : callable
          Functor that is called with the two datasets upon forward-mapping.
        train_as_1st : bool
          If True, the training dataset is passed to the target callable as
          the first argument and the other dataset as the second argument.
          If False, it is vice versa.

        Examples
        --------
        >>> from mvpa2.mappers.fxy import FxyMapper
        >>> from mvpa2.datasets import Dataset
        >>> callable = lambda x,y: len(x) > len(y)
        >>> ds1 = Dataset(range(5))
        >>> ds2 = Dataset(range(3))
        >>> fxy = FxyMapper(callable)
        >>> fxy.train(ds1)
        >>> fxy(ds2).item()
        True
        >>> fxy = FxyMapper(callable, train_as_1st=False)
        >>> fxy.train(ds1)
        >>> fxy(ds2).item()
        False
        """
        Mapper.__init__(self, **kwargs)
        self._fx = fx
        self._train_as_1st = train_as_1st
        self._ds_train = None
Beispiel #18
0
    def __init__(self, kshape, niter, learning_rate=0.005,
                 iradius=None, distance_metric=None, initialization_func=None):
        """
        Parameters
        ----------
        kshape : (int, int)
            Shape of the internal Kohonen layer. Currently, only 2D Kohonen
            layers are supported, although the length of an axis might be set
            to 1.
        niter : int
            Number of iteration during network training.
        learning_rate : float
            Initial learning rate, which will continuously decreased during
            network training.
        iradius : float or None
            Initial radius of the Gaussian neighborhood kernel radius, which
            will continuously decreased during network training. If `None`
            (default) the radius is set equal to the longest edge of the
            Kohonen layer.
        distance_metric: callable or None
            Kernel distance metric between elements in Kohonen layer. If None
            then Euclidean distance is used. Otherwise it should be a 
            callable that accepts two input arguments x and y and returns
            the distance d through d=distance_metric(x,y)
        initialization_func: callable or None
            Initialization function to set self._K, that should take one 
            argument with training samples and return an numpy array. If None,
            then values in the returned array are taken from a standard normal 
            distribution.  
        """
        # init base class
        Mapper.__init__(self)

        self.kshape = np.array(kshape, dtype='int')

        if iradius is None:
            self.radius = self.kshape.max()
        else:
            self.radius = iradius

        if distance_metric is None:
            self.distance_metric = lambda x, y: (x ** 2 + y ** 2) ** 0.5
        else:
            self.distance_metric = distance_metric

        # learning rate
        self.lrate = learning_rate

        # number of training iterations
        self.niter = niter

        # precompute whatever can be done
        # scalar for decay of learning rate and radius across all iterations
        self.iter_scale = self.niter / np.log(self.radius)

        # the internal kohonen layer
        self._K = None
        self._dqd = None
        self._initialization_func = initialization_func
Beispiel #19
0
 def __init__(self, slicearg, **kwargs):
     """
     Parameters
     ----------
     slicearg
       Argument for slicing
     """
     Mapper.__init__(self, **kwargs)
     self._safe_assign_slicearg(slicearg)
Beispiel #20
0
 def __init__(self, slicearg, **kwargs):
     """
     Parameters
     ----------
     slicearg
       Argument for slicing
     """
     Mapper.__init__(self, **kwargs)
     self._safe_assign_slicearg(slicearg)
Beispiel #21
0
    def __init__(self, distmask=None, **kwargs):
        """
	    parameters
        ----------
        distmask :  ndarray-like matrix or sparse matrix, or a dataset.
            The distmask of voxels to present their neighbors. 
            Usually we do not set it.
        """
        Mapper.__init__(self, **kwargs)

        self.__distmask = distmask
Beispiel #22
0
    def __init__(self, distmask=None, **kwargs):
        """
	    parameters
        ----------
        distmask :  ndarray-like matrix or sparse matrix, or a dataset.
            The distmask of voxels to present their neighbors. 
            Usually we do not set it.
        """
        Mapper.__init__(self, **kwargs)

        self.__distmask = distmask
Beispiel #23
0
    def __init__(self,neighbor_shape, outsparse=True, **kwargs):
        """
	    Parameters
        ----------
        neighborhood :  .
        outsparse: bool
            whether to output sparse matrix. 
        """
        Mapper.__init__(self, **kwargs)
        
        self.__outsparse = outsparse
        self.__neighbor_shape = neighbor_shape
Beispiel #24
0
    def __init__(self,
                 axis,
                 fx,
                 fxargs=None,
                 uattrs=None,
                 attrfx='merge',
                 order='uattrs'):
        """
        Parameters
        ----------
        axis : {'samples', 'features'}
        fx : callable
        fxargs : tuple
          Passed as *args to ``fx``
        uattrs : list
          List of attribute names to consider. All possible combinations
          of unique elements of these attributes are used to determine the
          sample groups to operate on.
        attrfx : callable
          Functor that is called with each sample attribute elements matching
          the respective samples group. By default the unique value is
          determined. If the content of the attribute is not uniform for a
          samples group a unique string representation is created.
          If `None`, attributes are not altered.
        order : {'uattrs', 'occurrence', None}
          If which order groups should be merged together.  If `None` (default
          before 2.3.1), the order is imposed only by the order of
          `uattrs` as keys in the dictionary, thus can vary from run to run.
          If `'occurrence'`, groups will be ordered by the first occurrence
          of group samples in original dataset. If `'uattrs'`, groups will be
          sorted by the values of uattrs with follow-up attr having higher
          importance for ordering (e .g. `uattrs=['targets', 'chunks']` would
          order groups first by `chunks` and then by `targets` within each
          chunk).
        """
        Mapper.__init__(self)

        if not axis in ['samples', 'features']:
            raise ValueError("%s `axis` arguments can only be 'samples' or "
                             "'features' (got: '%s')." % repr(axis))
        self.__axis = axis
        self.__uattrs = uattrs
        self.__fx = fx
        if not fxargs is None:
            self.__fxargs = fxargs
        else:
            self.__fxargs = ()
        if attrfx == 'merge':
            self.__attrfx = _uniquemerge2literal
        else:
            self.__attrfx = attrfx
        assert (order in (None, 'uattrs', 'occurrence'))
        self.__order = order
    def __init__(self, metric='euclidean', **kwargs):
        """
	parameters
        __________
        metric : string or function
          The distance metric to use. The distance function can be 'braycurtis', 
         'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 
         'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 
         'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean',
         'sokalmichener', 'sokalsneath', 'sqeuclidean', 'yule'.
        """
        Mapper.__init__(self, **kwargs)

        self.__metric = metric
Beispiel #26
0
 def __init__(self, pos, **kwargs):
     """
     Parameters
     ----------
     pos : int
         Axis index to which the new axis is prepended. Negative indices are
         supported as well, but the new axis will be placed behind the given
         index. For example, a position of ``-1`` will cause an axis to be
         added behind the last axis. If ``pos`` is larger than the number of
         existing axes additional new axes will be created match the value of
         ``pos``.
     """
     Mapper.__init__(self, **kwargs)
     self._pos = pos
Beispiel #27
0
 def __init__(self, pos, **kwargs):
     """
     Parameters
     ----------
     pos : int
         Axis index to which the new axis is prepended. Negative indices are
         supported as well, but the new axis will be placed behind the given
         index. For example, a position of ``-1`` will cause an axis to be
         added behind the last axis. If ``pos`` is larger than the number of
         existing axes additional new axes will be created match the value of
         ``pos``.
     """
     Mapper.__init__(self, **kwargs)
     self._pos = pos
Beispiel #28
0
    def __init__(self, metric='euclidean', **kwargs):
        """
	parameters
        __________
        metric : string or function
          The distance metric to use. The distance function can be 'braycurtis', 
         'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 
         'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 
         'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean',
         'sokalmichener', 'sokalsneath', 'sqeuclidean', 'yule'.
        """
        Mapper.__init__(self, **kwargs)

        self.__metric = metric
Beispiel #29
0
    def __init__(self, axis, fx, fxargs=None, uattrs=None,
                 attrfx='merge', order='uattrs'):
        """
        Parameters
        ----------
        axis : {'samples', 'features'}
        fx : callable
        fxargs : tuple
          Passed as *args to ``fx``
        uattrs : list
          List of attribute names to consider. All possible combinations
          of unique elements of these attributes are used to determine the
          sample groups to operate on.
        attrfx : callable
          Functor that is called with each sample attribute elements matching
          the respective samples group. By default the unique value is
          determined. If the content of the attribute is not uniform for a
          samples group a unique string representation is created.
          If `None`, attributes are not altered.
        order : {'uattrs', 'occurrence', None}
          If which order groups should be merged together.  If `None` (default
          before 2.3.1), the order is imposed only by the order of
          `uattrs` as keys in the dictionary, thus can vary from run to run.
          If `'occurrence'`, groups will be ordered by the first occurrence
          of group samples in original dataset. If `'uattrs'`, groups will be
          sorted by the values of uattrs with follow-up attr having higher
          importance for ordering (e .g. `uattrs=['targets', 'chunks']` would
          order groups first by `chunks` and then by `targets` within each
          chunk).
        """
        Mapper.__init__(self)

        if not axis in ['samples', 'features']:
            raise ValueError("%s `axis` arguments can only be 'samples' or "
                             "'features' (got: '%s')." % repr(axis))
        self.__axis = axis
        self.__uattrs = uattrs
        self.__fx = fx
        if not fxargs is None:
            self.__fxargs = fxargs
        else:
            self.__fxargs = ()
        if attrfx == 'merge':
            self.__attrfx = _uniquemerge2literal
        else:
            self.__attrfx = attrfx
        assert(order in (None, 'uattrs', 'occurrence'))
        self.__order = order
Beispiel #30
0
    def __init__(self, b, a, **kwargs):
        """
        All constructor parameters are analogs of filtfilt() or are passed
        on to the Mapper base class.

        Parameters
        ----------
        b : (N,) array_like
            The numerator coefficient vector of the filter.
        a : (N,) array_like
            The denominator coefficient vector of the filter.  If a[0]
            is not 1, then both a and b are normalized by a[0].
        """
        Mapper.__init__(self, auto_train=True, **kwargs)
        self.__iir_num = b
        self.__iir_denom = a
Beispiel #31
0
    def __init__(self, b, a, **kwargs):
        """
        All constructor parameters are analogs of filtfilt() or are passed
        on to the Mapper base class.

        Parameters
        ----------
        b : (N,) array_like
            The numerator coefficient vector of the filter.
        a : (N,) array_like
            The denominator coefficient vector of the filter.  If a[0]
            is not 1, then both a and b are normalized by a[0].
        """
        Mapper.__init__(self, auto_train=True, **kwargs)
        self.__iir_num = b
        self.__iir_denom = a
Beispiel #32
0
    def __init__(self, polyord=1, chunks_attr=None, opt_regs=None, **kwargs):
        """
        Parameters
        ----------
        polyord : int or list, optional
          Order of the Legendre polynomial to remove from the data.  This
          will remove every polynomial up to and including the provided
          value.  For example, 3 will remove 0th, 1st, 2nd, and 3rd order
          polynomials from the data.  np.B.: The 0th polynomial is the
          baseline shift, the 1st is the linear trend.
          If you specify a single int and `chunks_attr` is not None, then this value
          is used for each chunk.  You can also specify a different polyord
          value for each chunk by providing a list or ndarray of polyord
          values the length of the number of chunks.
        chunks_attr : str or None
          If None, the whole dataset is detrended at once. Otherwise, the given
          samples attribute (given by its name) is used to define chunks of the
          dataset that are processed individually. In that case, all the samples
          within a chunk should be in contiguous order and the chunks should be
          sorted in order from low to high -- unless the dataset provides
          information about the coordinate of each sample in the space that
          should be spanned be the polynomials (see `inspace` argument).
        opt_regs : list or None
          Optional list of sample attribute names that should be used as
          additional regressors.  One example would be to regress out motion
          parameters.
        space : str or None
          If not None, a samples attribute of the same name is added to the
          mapped dataset that stores the coordinates of each sample in the
          space that is spanned by the polynomials. If an attribute of that
          name is already present in the input dataset its values are interpreted
          as sample coordinates in the space that should be spanned by the
          polynomials.
        """
        self.__chunks_attr = chunks_attr
        self.__polyord = polyord
        self.__opt_reg = opt_regs

        # things that come from train()
        self._polycoords = None
        self._regs = None

        # secret switch to perform in-place detrending
        self._secret_inplace_detrend = False

        # need to init last to prevent base class puking
        Mapper.__init__(self, **kwargs)
Beispiel #33
0
    def __init__(self, polyord=1, chunks_attr=None, opt_regs=None, **kwargs):
        """
        Parameters
        ----------
        polyord : int or list, optional
          Order of the Legendre polynomial to remove from the data.  This
          will remove every polynomial up to and including the provided
          value.  For example, 3 will remove 0th, 1st, 2nd, and 3rd order
          polynomials from the data.  np.B.: The 0th polynomial is the
          baseline shift, the 1st is the linear trend.
          If you specify a single int and `chunks_attr` is not None, then this value
          is used for each chunk.  You can also specify a different polyord
          value for each chunk by providing a list or ndarray of polyord
          values the length of the number of chunks.
        chunks_attr : str or None
          If None, the whole dataset is detrended at once. Otherwise, the given
          samples attribute (given by its name) is used to define chunks of the
          dataset that are processed individually. In that case, all the samples
          within a chunk should be in contiguous order and the chunks should be
          sorted in order from low to high -- unless the dataset provides
          information about the coordinate of each sample in the space that
          should be spanned be the polynomials (see `inspace` argument).
        opt_regs : list or None
          Optional list of sample attribute names that should be used as
          additional regressors.  One example would be to regress out motion
          parameters.
        space : str or None
          If not None, a samples attribute of the same name is added to the
          mapped dataset that stores the coordinates of each sample in the
          space that is spanned by the polynomials. If an attribute of that
          name is already present in the input dataset its values are interpreted
          as sample coordinates in the space that should be spanned by the
          polynomials.
        """
        self.__chunks_attr = chunks_attr
        self.__polyord = polyord
        self.__opt_reg = opt_regs

        # things that come from train()
        self._polycoords = None
        self._regs = None

        # secret switch to perform in-place detrending
        self._secret_inplace_detrend = False

        # need to init last to prevent base class puking
        Mapper.__init__(self, **kwargs)
Beispiel #34
0
    def __init__(self, transformer, **kwargs):
        """
        Parameters
        ----------
        transformer : sklearn.transformer instance
        space : str or None, optional
          If not None, a sample attribute of the given name will be extracted
          from the training dataset and passed to the sklearn transformer's
          ``fit()`` method as ``y`` argument.

        """
        # NOTE: trailing spaces in above docstring must not be pruned
        # for correct parsing

        Mapper.__init__(self, auto_train=False, **kwargs)
        self._transformer = None
        self._pristine_transformer = transformer
Beispiel #35
0
    def __init__(self, transformer, **kwargs):
        """
        Parameters
        ----------
        transformer : sklearn.transformer instance
        space : str or None, optional
          If not None, a sample attribute of the given name will be extracted
          from the training dataset and passed to the sklearn transformer's
          ``fit()`` method as ``y`` argument.

        """
        # NOTE: trailing spaces in above docstring must not be pruned
        # for correct parsing

        Mapper.__init__(self, auto_train=False, **kwargs)
        self._transformer = None
        self._pristine_transformer = transformer
Beispiel #36
0
 def __repr__(self):
     s = Mapper.__repr__(self).rstrip(' )')
     # beautify
     if not s[-1] == '(':
         s += ' '
     s += 'kshape=%s, niter=%i, learning_rate=%f, iradius=%f)' \
             % (str(tuple(self.kshape)), self.niter, self.lrate,
                self.radius)
     return s
Beispiel #37
0
 def __repr__(self):
     s = Mapper.__repr__(self).rstrip(' )')
     # beautify
     if not s[-1] == '(':
         s += ' '
     s += 'kshape=%s, niter=%i, learning_rate=%f, iradius=%f)' \
             % (str(tuple(self.kshape)), self.niter, self.lrate,
                self.radius)
     return s
Beispiel #38
0
 def __init__(self, shape=None, maxdims=None, **kwargs):
     """
     Parameters
     ----------
     shape : tuple
       The shape of a single sample. If this argument is given the mapper
       is going to be fully configured and no training is necessary anymore.
     maxdims : int or None
       The maximum number of dimensions to flatten (starting with the first).
       If None, all axes will be flattened.
     """
     # by default auto train
     kwargs['auto_train'] = kwargs.get('auto_train', True)
     Mapper.__init__(self, **kwargs)
     self._origshape = None         # pylint pacifier
     self.__maxdims = maxdims
     if not shape is None:
         self._train_with_shape(shape)
Beispiel #39
0
    def __init__(self, kshape, niter, learning_rate=0.005,
                 iradius=None):
        """
        Parameters
        ----------
        kshape : (int, int)
          Shape of the internal Kohonen layer. Currently, only 2D Kohonen
          layers are supported, although the length of an axis might be set
          to 1.
        niter : int
          Number of iteration during network training.
        learning_rate : float
          Initial learning rate, which will continuously decreased during
          network training.
        iradius : float or None
          Initial radius of the Gaussian neighborhood kernel radius, which
          will continuously decreased during network training. If `None`
          (default) the radius is set equal to the longest edge of the
          Kohonen layer.
        """
        # init base class
        Mapper.__init__(self)

        self.kshape = np.array(kshape, dtype='int')

        if iradius is None:
            self.radius = self.kshape.max()
        else:
            self.radius = iradius

        # learning rate
        self.lrate = learning_rate

        # number of training iterations
        self.niter = niter

        # precompute whatever can be done
        # scalar for decay of learning rate and radius across all iterations
        self.iter_scale = self.niter / np.log(self.radius)

        # the internal kohonen layer
        self._K = None
Beispiel #40
0
    def __init__(self, kshape, niter, learning_rate=0.005, iradius=None):
        """
        Parameters
        ----------
        kshape : (int, int)
          Shape of the internal Kohonen layer. Currently, only 2D Kohonen
          layers are supported, although the length of an axis might be set
          to 1.
        niter : int
          Number of iteration during network training.
        learning_rate : float
          Initial learning rate, which will continuously decreased during
          network training.
        iradius : float or None
          Initial radius of the Gaussian neighborhood kernel radius, which
          will continuously decreased during network training. If `None`
          (default) the radius is set equal to the longest edge of the
          Kohonen layer.
        """
        # init base class
        Mapper.__init__(self)

        self.kshape = np.array(kshape, dtype='int')

        if iradius is None:
            self.radius = self.kshape.max()
        else:
            self.radius = iradius

        # learning rate
        self.lrate = learning_rate

        # number of training iterations
        self.niter = niter

        # precompute whatever can be done
        # scalar for decay of learning rate and radius across all iterations
        self.iter_scale = self.niter / np.log(self.radius)

        # the internal kohonen layer
        self._K = None
Beispiel #41
0
    def __init__(self,
                 params=None,
                 param_est=None,
                 chunks_attr='chunks',
                 dtype='float64',
                 **kwargs):
        """
        Parameters
        ----------
        params : None or tuple(mean, std) or dict
          Fixed Z-Scoring parameters (mean, standard deviation). If provided,
          no parameters are estimated from the data. It is possible to specify
          individual parameters for each chunk by passing a dictionary with the
          chunk ids as keys and the parameter tuples as values. If None,
          parameters will be estimated from the training data.
        param_est : None or tuple(attrname, attrvalues)
          Limits the choice of samples used for automatic parameter estimation
          to a specific subset identified by a set of a given sample attribute
          values.  The tuple should have the name of that sample
          attribute as the first element, and a sequence of attribute values
          as the second element. If None, all samples will be used for parameter
          estimation.
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual Z-scoring within them.
        dtype : Numpy dtype, optional
          Target dtype that is used for upcasting, in case integer data is to be
          Z-scored.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__params = params
        self.__param_est = param_est
        self.__params_dict = None
        self.__dtype = dtype

        # secret switch to perform in-place z-scoring
        self._secret_inplace_zscore = False
Beispiel #42
0
    def __init__(self, startpoints, boxlength, offset=0, **kwargs):
        """
        Parameters
        ----------
        startpoints : sequence
          Index values along the first axis of 'data'.
        boxlength : int
          The number of elements after 'startpoint' along the first axis of
          'data' to be considered for the boxcar.
        offset : int
          The offset between the provided starting point and the actual start
          of the boxcar.
        """
        Mapper.__init__(self, **kwargs)
        self._outshape = None

        startpoints = np.asanyarray(startpoints)
        if np.issubdtype(startpoints.dtype, 'i'):
            self.startpoints = startpoints
        else:
            if __debug__:
                debug(
                    'MAP', "Boxcar: obtained startpoints are not of int type."
                    " Rounding and changing dtype")
            self.startpoints = np.asanyarray(np.round(startpoints), dtype='i')

        # Sanity checks
        if boxlength < 1:
            raise ValueError, "Boxlength lower than 1 makes no sense."
        if boxlength - int(boxlength) != 0:
            raise ValueError, "boxlength must be an integer value."

        self.boxlength = int(boxlength)
        self.offset = offset
        self.__selectors = None

        # build a list of list where each sublist contains the indexes of to be
        # averaged data elements
        self.__selectors = [ slice(i + offset, i + offset + boxlength) \
                             for i in startpoints ]
Beispiel #43
0
 def __init__(self, flow, node_arguments=None, **kwargs):
     """
     Parameters
     ----------
     flow : mdp.Flow instance
       This flow instance is taken as the pristine source of which a
       copy is made for actual processing upon each training attempt.
     node_arguments : tuple, list
       A tuple or a list the same length as the flow. Each item is a
       list of arguments for the training of the corresponding node in
       the flow. If a node does not require additional arguments, None
       can be provided instead. Keyword arguments are currently not
       supported by mdp.Flow.
     """
     if node_arguments is not None and len(node_arguments) != len(flow):
         raise ValueError("Length of node_arguments (%i) does not match the "
                          "number of nodes in the flow (%i)."
                          % (len(node_arguments), len(flow)))
     Mapper.__init__(self, **kwargs)
     self.__pristine_flow = None
     self.flow = flow
     self.node_arguments = node_arguments
Beispiel #44
0
 def __init__(self, regs, add_regs=None, **kwargs):
     """
     Parameters
     ----------
     regs : list
       Names of sample attributes to be extracted from an input dataset and
       used as design matrix columns.
     add_regs : tuple, optional
       Additional regressors to be used in the design matrix. Each tuple
       element is a 2-tuple: the first element is a literal label for the
       regressor, and the second element is a 1D array with the regressor
       values. The length of the array needs to match the length of any
       input dataset.
     """
     if not 'space' in kwargs:
         kwargs['space'] = 'regressor_names'
     # so far no separate training
     Mapper.__init__(self, auto_train=True, **kwargs)
     self.regs = list(regs)
     if add_regs is None:
         add_regs = tuple()
     self.add_regs = tuple(add_regs)
Beispiel #45
0
    def __init__(self, startpoints, boxlength, offset=0, **kwargs):
        """
        Parameters
        ----------
        startpoints : sequence
          Index values along the first axis of 'data'.
        boxlength : int
          The number of elements after 'startpoint' along the first axis of
          'data' to be considered for the boxcar.
        offset : int
          The offset between the provided starting point and the actual start
          of the boxcar.
        """
        Mapper.__init__(self, **kwargs)
        self._outshape = None

        startpoints = np.asanyarray(startpoints)
        if np.issubdtype(startpoints.dtype, 'i'):
            self.startpoints = startpoints
        else:
            if __debug__:
                debug('MAP', "Boxcar: obtained startpoints are not of int type."
                      " Rounding and changing dtype")
            self.startpoints = np.asanyarray(np.round(startpoints), dtype='i')

        # Sanity checks
        if boxlength < 1:
            raise ValueError, "Boxlength lower than 1 makes no sense."
        if boxlength - int(boxlength) != 0:
            raise ValueError, "boxlength must be an integer value."

        self.boxlength = int(boxlength)
        self.offset = offset
        self.__selectors = None

        # build a list of list where each sublist contains the indexes of to be
        # averaged data elements
        self.__selectors = [ slice(i + offset, i + offset + boxlength) \
                             for i in startpoints ]
Beispiel #46
0
 def __init__(self, regs, add_regs=None, **kwargs):
     """
     Parameters
     ----------
     regs : list
       Names of sample attributes to be extracted from an input dataset and
       used as design matrix columns.
     add_regs : tuple, optional
       Additional regressors to be used in the design matrix. Each tuple
       element is a 2-tuple: the first element is a literal label for the
       regressor, and the second element is a 1D array with the regressor
       values. The length of the array needs to match the length of any
       input dataset.
     """
     if not 'space' in kwargs:
         kwargs['space'] = 'regressor_names'
     # so far no separate training
     Mapper.__init__(self, auto_train=True, **kwargs)
     self.regs = list(regs)
     if add_regs is None:
         add_regs = tuple()
     self.add_regs = tuple(add_regs)
Beispiel #47
0
 def __init__(self, flow, node_arguments=None, **kwargs):
     """
     Parameters
     ----------
     flow : mdp.Flow instance
       This flow instance is taken as the pristine source of which a
       copy is made for actual processing upon each training attempt.
     node_arguments : tuple, list
       A tuple or a list the same length as the flow. Each item is a
       list of arguments for the training of the corresponding node in
       the flow. If a node does not require additional arguments, None
       can be provided instead. Keyword arguments are currently not
       supported by mdp.Flow.
     """
     if not node_arguments is None and len(node_arguments) != len(flow):
         raise ValueError("Length of node_arguments (%i) does not match the "
                          "number of nodes in the flow (%i)."
                          % (len(node_arguments), len(flow)))
     Mapper.__init__(self, **kwargs)
     self.__pristine_flow = None
     self.flow = flow
     self.node_arguments = node_arguments
Beispiel #48
0
    def __init__(self, node, nodeargs=None, **kwargs):
        """
        Parameters
        ----------
        node : mdp.Node instance
          This node instance is taken as the pristine source of which a
          copy is made for actual processing upon each training attempt.
        nodeargs : dict
          Dictionary for additional arguments for all calls to the MDP
          node. The dictionary key's meaning is as follows:
          
          'train'
            Arguments for calls to `Node.train()`
          'stoptrain'
            Arguments for calls to `Node.stop_training()`
          'exec'
            Arguments for calls to `Node.execute()`
          'inv'
            Arguments for calls to `Node.inverse()`
          
          The value for each item is always a 2-tuple, consisting of a
          tuple (for the arguments), and a dictionary (for keyword
          arguments), i.e.  ((), {}). Both, tuple and dictionary have to be
          provided even if they are empty.
        space : see base class
        """
        # NOTE: trailing spaces in above docstring must not be pruned
        # for correct parsing

        if (externals.versions['mdp'] >= (2, 5) \
                and node.has_multiple_training_phases()) \
            or not len(node._train_seq) == 1:
            raise ValueError("MDPNodeMapper does not support MDP nodes with "
                             "multiple training phases.")
        Mapper.__init__(self, **kwargs)
        self.__pristine_node = None
        self.node = node
        self.nodeargs = nodeargs
Beispiel #49
0
    def __init__(self, node, nodeargs=None, **kwargs):
        """
        Parameters
        ----------
        node : mdp.Node instance
          This node instance is taken as the pristine source of which a
          copy is made for actual processing upon each training attempt.
        nodeargs : dict
          Dictionary for additional arguments for all calls to the MDP
          node. The dictionary key's meaning is as follows:
          
          'train'
            Arguments for calls to `Node.train()`
          'stoptrain'
            Arguments for calls to `Node.stop_training()`
          'exec'
            Arguments for calls to `Node.execute()`
          'inv'
            Arguments for calls to `Node.inverse()`
          
          The value for each item is always a 2-tuple, consisting of a
          tuple (for the arguments), and a dictionary (for keyword
          arguments), i.e.  ((), {}). Both, tuple and dictionary have to be
          provided even if they are empty.
        space : see base class
        """
        # NOTE: trailing spaces in above docstring must not be pruned
        # for correct parsing

        if (externals.versions['mdp'] >= (2, 5) \
                and node.has_multiple_training_phases()) \
            or not len(node._train_seq) == 1:
            raise ValueError("MDPNodeMapper does not support MDP nodes with "
                             "multiple training phases.")
        Mapper.__init__(self, **kwargs)
        self.__pristine_node = None
        self.node = node
        self.nodeargs = nodeargs
Beispiel #50
0
    def __init__(self, dim=1, wavelet='sym4', mode=DEFAULT_MODE, maxlevel=None):
        """Initialize _WaveletMapper mapper

        Parameters
        ----------
        dim : int or tuple of int
          dimensions to work across (for now just scalar value, ie 1D
          transformation) is supported
        wavelet : str
          one from the families available withing pywt package
        mode : str
          periodization mode
        maxlevel : int or None
          number of levels to use. If None - automatically selected by pywt
        """
        Mapper.__init__(self)

        self._dim = dim
        """Dimension to work along"""

        self._maxlevel = maxlevel
        """Maximal level of decomposition. None for automatic"""

        if not wavelet in pywt.wavelist():
            raise ValueError, \
                  "Unknown family of wavelets '%s'. Please use one " \
                  "available from the list %s" % (wavelet, pywt.wavelist())
        self._wavelet = wavelet
        """Wavelet family to use"""

        if not mode in pywt.MODES.modes:
            raise ValueError, \
                  "Unknown periodization mode '%s'. Please use one " \
                  "available from the list %s" % (mode, pywt.MODES.modes)
        self._mode = mode
        """Periodization mode"""
Beispiel #51
0
    def __init__(self,
                 chunks_attr=None,
                 k=8,
                 init='k-means++',
                 n_init=10,
                 **kwargs):
        """
	parameters
        __________
        chunks_attr : str or None
          If provided, it specifies the name of a samples attribute in the
          training data, unique values of which will be used to identify chunks of
          samples, and to perform individual clustering within them.
        k : int or ndarray
          The number of clusters to form as well as the number of centroids to
          generate. If init initialization string is matrix, or if a ndarray
          is given instead, it is interpreted as initial cluster to use instead
        init : {k-means++, random, points, matrix}
          Method for initialization, defaults to k-means++:k-means++ :
          selects initial cluster centers for k-mean clustering in a smart way
	  to speed up convergence. See section Notes in k_init for more details.
          random: generate k centroids from a Gaussian with mean and variance 
	  estimated from the data.points: choose k observations (rows) at 
	  random from data for the initial centroids.matrix: interpret the k 
	  parameter as a k by M (or length k array for one-dimensional data) 
	  array of initial centroids.
        n_init : int
	  Number of iterations of the k-means algrithm to run. Note that this 
	  differs in meaning from the iters parameter to the kmeans function.
        """
        Mapper.__init__(self, **kwargs)

        self.__chunks_attr = chunks_attr
        self.__k = k
        self.__init = init
        self.__n_init = n_init
Beispiel #52
0
 def __init__(self, **kwargs):
     Mapper.__init__(self, **kwargs)
Beispiel #53
0
 def __init__(self, in_place=False, **kwargs):
     Mapper.__init__(self, **kwargs)
     self.in_place = in_place
Beispiel #54
0
 def __init__(self, slicearg, **kwargs):
     Mapper.__init__(self, **kwargs)
     self._safe_assign_slicearg(slicearg)
Beispiel #55
0
    def __init__(self,
                 kshape,
                 niter,
                 learning_rate=0.005,
                 iradius=None,
                 distance_metric=None,
                 initialization_func=None):
        """
        Parameters
        ----------
        kshape : (int, int)
            Shape of the internal Kohonen layer. Currently, only 2D Kohonen
            layers are supported, although the length of an axis might be set
            to 1.
        niter : int
            Number of iteration during network training.
        learning_rate : float
            Initial learning rate, which will continuously decreased during
            network training.
        iradius : float or None
            Initial radius of the Gaussian neighborhood kernel radius, which
            will continuously decreased during network training. If `None`
            (default) the radius is set equal to the longest edge of the
            Kohonen layer.
        distance_metric: callable or None
            Kernel distance metric between elements in Kohonen layer. If None
            then Euclidean distance is used. Otherwise it should be a 
            callable that accepts two input arguments x and y and returns
            the distance d through d=distance_metric(x,y)
        initialization_func: callable or None
            Initialization function to set self._K, that should take one 
            argument with training samples and return an numpy array. If None,
            then values in the returned array are taken from a standard normal 
            distribution.  
        """
        # init base class
        Mapper.__init__(self)

        self.kshape = np.array(kshape, dtype='int')

        if iradius is None:
            self.radius = self.kshape.max()
        else:
            self.radius = iradius

        if distance_metric is None:
            self.distance_metric = lambda x, y: (x**2 + y**2)**0.5
        else:
            self.distance_metric = distance_metric

        # learning rate
        self.lrate = learning_rate

        # number of training iterations
        self.niter = niter

        # precompute whatever can be done
        # scalar for decay of learning rate and radius across all iterations
        self.iter_scale = self.niter / np.log(self.radius)

        # the internal kohonen layer
        self._K = None
        self._dqd = None
        self._initialization_func = initialization_func

        # precompute necessary sizes for dqd (and later infl)
        self._dqdshape = np.array([
            self.kshape[0] / 2, self.kshape[1] / 2,
            np.ceil(self.kshape[0] / 2.).astype('int'),
            np.ceil(self.kshape[1] / 2.).astype('int')
        ])
Beispiel #56
0
 def __init__(self, slicearg, **kwargs):
     Mapper.__init__(self, **kwargs)
     self._safe_assign_slicearg(slicearg)
Beispiel #57
0
 def __init__(self, **kwargs):
     Mapper.__init__(self, **kwargs)