Diving into Breeze
Let's get started. We will work in the Scala console, but a program similar to this example is available in BreezeDemo.scala
in the examples corresponding to this chapter. Create a build.sbt
file with the following lines:
scalaVersion := "2.11.7" libraryDependencies ++= Seq( "org.scalanlp" %% "breeze" % "0.11.2", "org.scalanlp" %% "breeze-viz" % "0.11.2", "org.scalanlp" %% "breeze-natives" % "0.11.2" )
Start an sbt
console:
$ sbt console scala> import breeze.linalg._ import breeze.linalg._ scala> import breeze.plot._ import breeze.plot._ scala> import breeze.numerics._ import breeze.numerics._
Let's start by plotting a sigmoid curve, . We will first generate the data using Breeze. Recall that the linspace
method creates a vector of doubles, uniformly distributed between two values:
scala> val x = linspace(-4.0, 4.0, 200) x: DenseVector[Double] = DenseVector(-4.0, -3.959798... scala> val fx = sigmoid(x) fx: DenseVector[Double] = DenseVector(0.0179862099620915...