2

Naive user wants to do a simple convolve in Scala Breeze:

import breeze.linalg._
import breeze.numerics._
import breeze.signal.support.{OverhangOpt, CanConvolve} // ??

val kernel = DenseVector(1.0, 2.0)
val data   = DenseVector(2.0, 3.0, 4.0, 5.0)
val out    = data.convolve(kernel)

Can someone write up a little example how to do this ?

kos
  • 51
  • 3

1 Answers1

3

You're on the right way already. Just make sure that you have the latest version of breeze, i.e. 0.6-SNAPSHOT. For example, use the following portions in your build.sbt:

libraryDependencies ++= Seq(
        "org.scalanlp" % "breeze_2.10" % "0.6-SNAPSHOT"
    )

resolvers ++= Seq(
        "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
        "Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
    )

There's no need to import stuff from breeze.signal.support, your original example will work just fine:

scala> import breeze.linalg._
import breeze.linalg._

scala> import breeze.signal._
import breeze.signal._

scala> convolve(DenseVector(1.0, 2.0), DenseVector(3.0, 4.0, 5.0, 6.0))
res1: breeze.linalg.DenseVector[Double] = DenseVector(10.0, 13.0, 16.0)
fotNelton
  • 3,844
  • 2
  • 24
  • 35
  • at least with breeze 2.1.0 the order of arguments has to be reversed, e.g., `convolve(DenseVector(3.0, 4.0, 5.0, 6.0), DenseVector(1.0, 2.0))`. – phdoerfler May 20 '23 at 08:27