original_docstring:  Calculates the Victor-Purpura's (VP) distance. It is often denoted as
      :math:`D^{\\text{spike}}[q]`.
  
      It is defined as the minimal cost of transforming spike train `a` into
      spike train `b` by using the following operations:
  
          * Inserting or deleting a spike (cost 1.0).
          * Shifting a spike from :math:`t` to :math:`t'` (cost :math:`q \\cdot |t
            - t'|`).
  
      A detailed description can be found in
      *Victor, J. D., & Purpura, K. P. (1996). Nature and precision of temporal
      coding in visual cortex: a metric-space analysis. Journal of
      Neurophysiology.*
  
      Given the average number of spikes :math:`n` in a spike train and :math:`N`
      spike trains the run-time complexity of this function is
      :math:`O(N^2 n^2)` and :math:`O(N^2 + n^2)` memory will be needed.
  
      :param sequence trains: Sequence of :class:`neo.core.SpikeTrain` objects of
          which the distance will be calculated pairwise.
      :param q: Cost factor for spike shifts as inverse time scalar. If `kernel`
          is not `None`, `q` will be ignored.
      :type q: Quantity scalar
      :param kernel: Kernel to use in the calculation of the distance. If
          `kernel` is `None`, an unnormalized triangular kernel with a half width
          of `2.0/q` will be used.
      :type kernel: :class:`.signal_processing.Kernel`
      :param bool sort: Spike trains with sorted spike times will be needed for
          the calculation. You can set `sort` to `False` if you know that your
          spike trains are already sorted to decrease calculation time.
      :returns: Matrix containing the VP distance of all pairs of spike trains.
      :rtype: 2-D array
      
docstring: Calculates the Victor-Purpura's (VP) distance. It is often denoted as
docstring_tokens: Calculates the Victor - Purpura ' s ( VP ) distance . It is often denoted as
code: def victor_purpura_dist(trains, q=1.0 * pq.Hz, kernel=None, sort=True):
      """ Calculates the Victor-Purpura's (VP) distance. It is often denoted as
      :math:`D^{\\text{spike}}[q]`.
  
      It is defined as the minimal cost of transforming spike train `a` into
      spike train `b` by using the following operations:
  
          * Inserting or deleting a spike (cost 1.0).
          * Shifting a spike from :math:`t` to :math:`t'` (cost :math:`q \\cdot |t
            - t'|`).
  
      A detailed description can be found in
      *Victor, J. D., & Purpura, K. P. (1996). Nature and precision of temporal
      coding in visual cortex: a metric-space analysis. Journal of
      Neurophysiology.*
  
      Given the average number of spikes :math:`n` in a spike train and :math:`N`
      spike trains the run-time complexity of this function is
      :math:`O(N^2 n^2)` and :math:`O(N^2 + n^2)` memory will be needed.
  
      :param sequence trains: Sequence of :class:`neo.core.SpikeTrain` objects of
          which the distance will be calculated pairwise.
      :param q: Cost factor for spike shifts as inverse time scalar. If `kernel`
          is not `None`, `q` will be ignored.
      :type q: Quantity scalar
      :param kernel: Kernel to use in the calculation of the distance. If
          `kernel` is `None`, an unnormalized triangular kernel with a half width
          of `2.0/q` will be used.
      :type kernel: :class:`.signal_processing.Kernel`
      :param bool sort: Spike trains with sorted spike times will be needed for
          the calculation. You can set `sort` to `False` if you know that your
          spike trains are already sorted to decrease calculation time.
      :returns: Matrix containing the VP distance of all pairs of spike trains.
      :rtype: 2-D array
      """
  
      if kernel is None:
          if q == 0.0:
              num_spikes = sp.atleast_2d([st.size for st in trains])
              return sp.absolute(num_spikes.T - num_spikes)
          else:
              kernel = sigproc.TriangularKernel(2.0 / q, normalize=False)
  
      if sort:
          trains = [sp.sort(st.view(type=pq.Quantity)) for st in trains]
  
      def compute(i, j):
          if i == j:
              return 0.0
          else:
              return _victor_purpura_dist_for_trial_pair(
                  trains[i], trains[j], kernel)
  
      return _create_matrix_from_indexed_function(
          (len(trains), len(trains)), compute, kernel.is_symmetric())
code_tokens: def victor_purpura_dist ( trains , q = 1.0 * pq . Hz , kernel = None , sort = True ) : if kernel is None : if q == 0.0 : num_spikes = sp . atleast_2d ( [ st . size for st in trains ] ) return sp . absolute ( num_spikes . T - num_spikes ) else : kernel = sigproc . TriangularKernel ( 2.0 / q , normalize = False ) if sort : trains = [ sp . sort ( st . view ( type = pq . Quantity ) ) for st in trains ] def compute ( i , j ) : if i == j : return 0.0 else : return _victor_purpura_dist_for_trial_pair ( trains [ i ] , trains [ j ] , kernel ) return _create_matrix_from_indexed_function ( ( len ( trains ) , len ( trains ) ) , compute , kernel . is_symmetric ( ) )
short_docstring: Calculates the Victor-Purpura's (VP) distance.
short_docstring_tokens: Calculates the Victor - Purpura ' s ( VP ) distance .
comment: """ Calculates the Victor-Purpura's (VP) distance. It is often denoted as
      :math:`D^{\\text{spike}}[q]`.
  
      It is defined as the minimal cost of transforming spike train `a` into
      spike train `b` by using the following operations:
  
          * Inserting or deleting a spike (cost 1.0).
          * Shifting a spike from :math:`t` to :math:`t'` (cost :math:`q \\cdot |t
            - t'|`).
  
      A detailed description can be found in
      *Victor, J. D., & Purpura, K. P. (1996). Nature and precision of temporal
      coding in visual cortex: a metric-space analysis. Journal of
      Neurophysiology.*
  
      Given the average number of spikes :math:`n` in a spike train and :math:`N`
      spike trains the run-time complexity of this function is
      :math:`O(N^2 n^2)` and :math:`O(N^2 + n^2)` memory will be needed.
  
      :param sequence trains: Sequence of :class:`neo.core.SpikeTrain` objects of
          which the distance will be calculated pairwise.
      :param q: Cost factor for spike shifts as inverse time scalar. If `kernel`
          is not `None`, `q` will be ignored.
      :type q: Quantity scalar
      :param kernel: Kernel to use in the calculation of the distance. If
          `kernel` is `None`, an unnormalized triangular kernel with a half width
          of `2.0/q` will be used.
      :type kernel: :class:`.signal_processing.Kernel`
      :param bool sort: Spike trains with sorted spike times will be needed for
          the calculation. You can set `sort` to `False` if you know that your
          spike trains are already sorted to decrease calculation time.
      :returns: Matrix containing the VP distance of all pairs of spike trains.
      :rtype: 2-D array
      """