Scalala
Scalala has been superseded by dlwh/breeze. Scalala is a high performance numeric linear algebra library for Scala, with rich Matlab-like operators on vectors and matrices; a library of numerical routines; support for plotting.
How to do X * diag(Y)
in Scala Breeze? X
could be for example a CSCMatrix
and Y
could be a DenseVector
?
In MATLAB syntax, this would be:
X * spdiags(0, Y, N, N )
Or:
X .* repmat( Y', K, 0 )
In SciPy syntax, this would be a 'broadcast multiply':
Y * X
How to do X * diag(Y)
in Scala Breeze?
Source: (StackOverflow)
I am starting using scala
and I am interested in using the scalala
package for doing linear algebra computations. I successfully installed it through sbt
but I can't (or better don't know how) start the scalala console
. Can anyone point out the steps I have to take to make that possible?
Thanks a lot
P.S. I have read this quickstart guide but didn't help me.
[EDIT]
To be more clear I do not want to explicitly make includes with the standard scala
console in order scalala
to work.
Source: (StackOverflow)
How to solve a linear system of matrices in scala breeze? ie, I have Ax = b, where A is a matrix (usually positive definite), and x and b are vectors.
I can see that there is a cholesky decomposition available, but I couldn't seem to find a solver? (if it was matlab I could do x = b \ A. If it was scipy I could do x = A.solve(b) )
Source: (StackOverflow)
I want to read a tab-delimited text file into a Breeze DenseMatrix. I see in the ScalaDoc that this should be possible and there are a whole set of I/O classes, but I can't find any examples and it's hard to digest the ScalaDoc.
Can someone provide a simple read/write example?
Source: (StackOverflow)
I am new to Breeze (formerly Scalala), and can't figure out why the following simple program throws an exception. i am using Scala 2.9.2 and Breeze 0.1:
import breeze.linalg._
val m = DenseMatrix((3.0, 1.0, 2.0), (-2.0, 1.0, 3.0))
val n = mean(m, Axis._1)
It works as expected if I use a 2x2 or a 3x2 matrix, but a 2x3 matrix causes the following exception:
-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: C:\Users\daved\AppData\Local\Temp\jblas8588491482847885553jblas.dll: Can't find dependent libraries.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at breeze.linalg.package$$anon$1.apply$mcD$sp(package.scala:203)
at breeze.linalg.package$$anon$1.apply(package.scala:196)
at breeze.linalg.package$$anon$1.apply(package.scala:186)
at breeze.linalg.DenseVector.ureduce(DenseVector.scala:91)
at breeze.linalg.Tensor$$anon$1.apply(Tensor.scala:149)
at breeze.generic.UReduceable$class.apply$mcD$sp(URFunc.scala:56)
at breeze.linalg.Tensor$$anon$1.apply$mcD$sp(Tensor.scala:148)
at breeze.generic.URFunc$mcD$sp$class.apply$mcD$sp(URFunc.scala:32)
at breeze.linalg.package$$anon$1.apply$mcD$sp(package.scala:186)
at breeze.generic.URFunc$mcD$sp$$anonfun$apply$mcD$sp$1.apply(URFunc.scala:36)
at breeze.linalg.LowPriorityDenseMatrix1$$anon$17.apply(DenseMatrix.scala:444)
at breeze.linalg.LowPriorityDenseMatrix1$$anon$17.apply(DenseMatrix.scala:440)
at breeze.generic.URFunc$mcD$sp$class.apply$mcD$sp(URFunc.scala:36)
at breeze.linalg.package$$anon$1.apply$mcD$sp(package.scala:186)
at com.tennisedge.opencv.BreezePlay$delayedInit$body.apply(BreezePlay.scala:24)
Source: (StackOverflow)
With Scalala it was possible to perform element-wise operations on a Vector using a scalar operand. Say you have a Vector of random numbers between 0 and 1 and you want to subtract each value from 1:
import breeze.linalg._
val x = DenseVector.rand(5)
val y = 1d :- x //DOESN'T COMPILE: "value :- is not a member of Double"
Unlike Scalala, Breeze fails to compile with this approach. You can work around this by generating a Vector of ones but it just seems like there should be a better way.
val y = DenseVector.ones[Double](x.size) :- x
Another workaround would be to use the mapValues method which is a bit more readable:
val y = x mapValues { 1 - _ }
What is the proper way to accomplish this with Breeze?
Source: (StackOverflow)
Is there a generic way using Breeze to achieve what you can do using broadcasting in NumPy?
Specifically, if I have an operator I'd like to apply to two 3x4 matrices, I can apply that operation element-wise. However, what I have is a 3x4 matrix and a 3-element column vector. I'd like a function which produces a 3x4 matrix created from applying the operator to each element of the matrix with the element from the vector for the corresponding row.
So for a division:
2 4 6 / 2 3 = 1 2 3
3 6 9 1 2 3
If this isn't available. I'd be willing to look at implementing it.
Source: (StackOverflow)
I am a bit lost among all those available operators -- so is there easy way to insert a entire row/column (vector) into a matrix?
I started thinking about creating a vector, converting it to array, joining it with matrix converted into array, and creating new matrix based on such combined array, but it looks even uglier than it sounds.
Source: (StackOverflow)
I'd like to slice a sparse vector in scalala and get another sparse vector. A normal slice always gives a standard vector. Can I provide an implicit function for doing this while slicing and if so what would it look like?
As an example, I'd like to accomplish the following:
val v:SparseVectorRow[Double] = ...
val v2:SparseVectorRow[Double] = v(List(1,3,5))
Lastly, I'm using Scalala release 1.0.0.RC3-SNAPSHOT.
Thanks in advance.
Source: (StackOverflow)
I am trying to import Scalala into Eclipse.
I had tried using the sbt-eclipse plugin by adding the lines
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0-M2")
to my plugins.sbt
and I ran ./sbt update
from the root of the Scalala dir which is cloned from github,
I am getting the below error
==================================================
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.0.0-M2 (sbtVersion=0.11.0, scalaVersion=2.9.1)
[warn]
[error] {file:/home/tutysra/Scalala/project/plugins/}default-ffe360/*:update: sbt.ResolveException: unresolved dependency: com.typesafe.sbteclipse#sbteclipse-plugin;2.0.0-M2: not found
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? i
[warn] Ignoring load failure: no project loaded.
==================================================
Had anyone successfully built Scalala's source with Eclipse and can share the steps they followed?
I can also give IntelliJ a try if that is the preferred method and used by many devs.
If there are some tweaking necessary for running on IntelliJ please provide them as well.
Source: (StackOverflow)
I'm trying to implement the answer to this question: Can you recommend a charting library for Scala?
I've downloaded and compiled Scalala
from the git hub and placed the scalala_2.8.1-1.0.0.RC2-SNAPSHOT.jar
in my lib
folder (I'm using SBT to do my build). Here's the code:
import scalala.library.Plotting
object ScalalaTest extends Application
{
val x = Plotting.linspace(0,1);
}
I'm getting the following error:
[error] /src/main/scala/ScalalaTest.scala:6: value linspace is not a member of object scalala.library.Plotting
[error] val x = Plotting.linspace(0,1);
[error] ^
[error] one error found
It looks like my scala compiler recognizes the scalala
package but doesn't recognize members of Plotting
(I've tried others besides linspace
). This is strange because according to the Scalala API, linspace
is a member of Plotting
.
Source: (StackOverflow)
I am using the breeze.optimize
package of Scala Breeze, and it looks like Breeze ahs implemented its own logging library.
Is there a way to configure Breeze to use standard logging like log4j or slf4j so I can configure logging for optimizations the same way I do for everything else in my application?
Alternatively, how do I just turn off the logging messages. They are on by defaults and logging every iteration of a function minimization for me, which is generating a lot of log noise for me.
Wrapper for Apache Commons based ont he answer below:
import breeze.util.logging.Logger
import breeze.util.logging.Logger.Level
import org.apache.commons.logging.LogFactory
class BreezeCommonsLogger[T: ClassManifest] extends Logger {
private val log = LogFactory.getLog(classManifest[T].erasure)
def trace(f: => Any) { if (log.isTraceEnabled()) log.trace(f.toString) }
def debug(f: => Any) { if (log.isDebugEnabled()) log.debug(f.toString) }
def info(f: => Any) { if (log.isInfoEnabled()) log.info(f.toString) }
def warn(f: => Any) { if (log.isWarnEnabled()) log.warn(f.toString) }
def error(f: => Any) { if (log.isErrorEnabled()) log.error(f.toString) }
def fatal(f: => Any) { if (log.isFatalEnabled()) log.fatal(f.toString) }
def level_=(level: Level) {}
def level = Logger.NEVER
}
I was able to use this like:
val lbfgs = new LBFGS[Mat](maxIters, 5, tolerance) {
override val log = new BreezeCommonsLogger[LBFGS[Mat]]
}
Source: (StackOverflow)