Manual

From Efficient Java Matrix Library
Revision as of 16:03, 21 March 2015 by Peter (talk | contribs) (Created page with "= The Basics = What exactly is Efficient Java Matrix Library (EJML)? EJML is a Java library for performing standard linear algebra operations on dense matrices. Typically t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Basics

What exactly is Efficient Java Matrix Library (EJML)? EJML is a Java library for performing standard linear algebra operations on dense matrices. Typically the list of standard operations is divided up unto basic (addition, subtraction, multiplication, ...etc), decompositions (LU, QR, SVD, ... etc), and solving linear systems. A complete list of its core functionality can be found on the Capabilities page.

This manual describes how to use and develop an application using EJML. Other questions, like how to build or include it in your project, is provided in the list below. If you have a question which isn't answered or is confusion feel free to post a question on the message board! Instructions on how to use EJML is primarily done in this manual through example, see below. The examples are selected from common real-world problems, such as Kalman filters. Some times the same example is provided in three different formats using one of the three interfaces provided in EJML to help you understand the differences.

The Interfaces

A primary design goal of EJML was to provide users the capability to write both highly optimized code and easy to read/write code. Since it's hard to do this with a single API BoofCV provides three different ways to interact with it.

  • Procedural: You have full access to all of EJML's capabilities, can select individual algorithms, and almost complete control over memory. The downside is it feels a bit like you're programming in assembly and it's tedious to have that much control over memory.
  • SimpleMatrix: An object oriented API that allows you to connect multiple operations together using a flow strategy, which is much easier to read and write. Limited subset of operations are supported and memory is constantly created and destroyed.
  • Equations: Is a symbolic interface that allows you to manipulate matrices in a similar manor to Matlab/Octave. Can be precompiled and won't declare new memory if the input size doesn't change. It's a bit of a black box and the compiler isn't smart enough to pick the most efficient functions.

Example of compute the Kalman gain "K"

Procedural

mult(H,P,c);
multTransB(c,H,S);
addEquals(S,R);
if( !invert(S,S_inv) ) throw new RuntimeException("Invert failed");
multTransA(H,S_inv,d);
mult(P,d,K);

SimpleMatrix

SimpleMatrix S = H.mult(P).mult(H.transpose()).plus(R);
SimpleMatrix K = P.mult(H.transpose().mult(S.invert()));

Equations

eq.process("K = P*H'*inv( H*P*H' + R )");

It's hard to say which interface is the best. If you are dealing with small matrices and need to write highly optimized code then Procedural is the way to go. For large matrices it doesn't really matter which one you use since the overhead is insignificant compared to the matrix operations. If you want to write something quickly then SimpleMatrix or Equations is the way to go. For those of you who are concerned about performance, I recommend coding it up first using SimpleMatrix or Equations then benchmarking to see if that code is a bottleneck. Much easier to debug that way.

Comparison of Interface Runtime Performance

Example Code

Tutorials

External References