tech.v3.datatype.convolve

Namespace for implementing various basic convolutions. Currently only 1d convolutions are supported.

convolve1d

(convolve1d data win options)(convolve1d data win)

Convolve a window across a signal. The only difference from correlate is the window is reversed and then correlate is called. See options for correlate, this has the same defaults.

Examples:

user> (require '[tech.v3.datatype.convolve :as dt-conv])
nil
user> (dt-conv/convolve1d [1, 2, 3], [0, 1, 0.5])
#array-buffer<float64>[5]
[0.000, 1.000, 2.500, 4.000, 1.500]
user> (dt-conv/convolve1d [1, 2, 3], [0, 1, 0.5] {:mode :same})
#array-buffer<float64>[3]
[1.000, 2.500, 4.000]
user> (dt-conv/convolve1d [1, 2, 3], [0, 1, 0.5] {:mode :valid})
#array-buffer<float64>[1]
[2.500]

correlate1d

(correlate1d data win {:keys [mode force-serial edge-mode stepsize algorithm], :or {mode :full, edge-mode :zero, stepsize 1}, :as options})(correlate1d data win)

Convolve window over data. Window must be smaller than data. Returns result in :float64 space. Convolutions outside the valid space of data are supplied zeros to match numpy conventions.

Options:

  • :mode - defaults to :full - one of:
    • :full - Result size is ndata + 2 * (nwin - 1)
    • :same - Result size is ndata
    • :valid - Result size is ndata - nwin + 1
  • :edge-mode - defaults to :zero- one of:
    • :zero - pad zero
    • :clamp - Clamp to edge values.
    • :nearest - Same as clamp, python compat.
    • :reflect - reflect the data - abcddcba|abcd|dcbaabcd
    • :wrap - wrap data repeating - abcdabcd|abcd|abcdabcd
    • number - pad with constant number.
  • :force-serial - For serial execution of the naive convolution. Unnecessary except for profiling and comparison purposes.
  • :stepsize - Defaults to 1, this steps across the input data in stepsize increments. :fft alorithm cannot be used if stepsize is not 1.
  • :algorithm - :naive, :auto, or :fft. Defaults to :auto which will choose either :naive or :fft depending on input data size.

gaussian1d

(gaussian1d data sigma {:keys [truncate mode edge-mode], :or {truncate 4, mode :same, edge-mode :reflect}, :as options})(gaussian1d data window-len)

1-D Gaussian filter.

data : convertible to reader. sigma : scalar - standard deviation for Gaussian kernel. See :truncate for how this relates to window width.

Options:

  • :mode - defaults to :same, see options for correlate1d.
  • :edge-mode - defaults to :reflect, see options for correlate1d.
  • :truncate - Defaults to 4. Truncate the filter at this many standard deviations. Convolution window is equal to (long (+ (* truncate sigma) 0.5))