DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Using Barcodes in iText 7
  • Using Java Class Extension Library for Data-Oriented Programming - Part 2
  • Using Java Class Extension Library for Data-Oriented Programming
  • Java 23: What Developers Need to Know

Trending

  • Understanding and Mitigating IP Spoofing Attacks
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Using Python Libraries in Java
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  1. DZone
  2. Coding
  3. Java
  4. Introduction to Efficient Java Matrix Library (EJML)

Introduction to Efficient Java Matrix Library (EJML)

By 
Peter Abeles user avatar
Peter Abeles
·
Apr. 12, 11 · News
Likes (0)
Comment
Save
Tweet
Share
6.6K Views

Join the DZone community and get the full member experience.

Join For Free

Linear algebra is a commonly used area of mathematics with a wide range of applications in various engineering and scientific fields. Examples of applications include line fitting, Kalman filters, face recognition, financial software, and numerical optimization to name a few. Many computer libraries have been developed for linear algebra. One of the better known would be LAPACK, which was originally programmed in Fortran.

EJML Logo

Introducing Efficient Java Matrix Library

The following article provides a brief introduction to one of the newer linear algebra libraries for Java, Efficient Java Matrix Library (EJML), a free open source library.  EJML is a linear algebra library for dense real matrices.  EJML's design goals are; 1) to be as computationally and memory efficient as possible for both small and large matrices, and 2) to be accessible to both novices and experts. These goals are accomplished by dynamically selecting the best algorithms to use at runtime and through a thoughtfully designed clean API. Providing good documentation, code examples, and constant benchmarking for speed, memory, and stability are also priorities.

The following functionality is provided:

  • Basic Operators (addition, multiplication, ... )
  • Matrix Manipulation (extract, insert, combine, ... )
  • Linear Solvers (linear, least squares, incremental, ... )
  • Decompositions (LU, QR, Cholesky, SVD, Eigenvalue, ...)
  • Matrix Features (rank, symmetric, definitiveness, ... )
  • Random Matrices (covariance, orthogonal, symmetric, ... )
  • Different Internal Formats (row-major, block)
  • Unit Testing
EJML can be downloaded from its website at: http://ejml.org/

Application Programming Interface

There are three primary ways to interact with EJML, 1) a simple to use object oriented interface, 2) procedural interface that provides greater control over memory and algorithms, 3) an expert interface that directly access specialized algorithms that is abstracted away using the first two. To see a practical comparison of these three interfaces take a look at the Kalman filter example provided at EJML's website. There each interface is used to code up a functionally identical Kalman filter:

Here are three code sniplets showing the Kalman gain being computed:

Simple:

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

Procedural:

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

Specialized:

if( !solver.setA(S) )
throw new RuntimeException("Invert failed");
solver.invert(S_inv);
MatrixMatrixMult.multTransA_small(H,S_inv,d);
MatrixMatrixMult.mult_small(P,d,K);

The full examples are available at: http://ejml.org/wiki/index.php?title=Example_Kalman_Filter

Going beyond the basics, there are easy to use yet powerful Java interfaces for solving linear systems and matrix decompositions. These provide much more control over the type of algorithm used, what it computes, how much memory is used, and remove as much of the drudgery as possible. DecompositionFactory and LinearSolverFactory are provided for creating these solvers and decompositions. By using the factory the best most update algorithm will be automatically selected.  EJML offer many different decomposition algorithms, even within the same family. For instance, there are four QR decompositions provided, each of which is catered towards a different sized matrix. Different factories hide much of these detail from the end user.

 

Who is using EJML?

Even though EJML is a fairly new library it has already been picked up by several opensource projects:

  • goGPS: http://code.google.com/p/gogps/
  • Set Visualiser: http://www-edc.eng.cam.ac.uk/tools/set_visualiser/
  • Universal Java Matrix Library (UJML): http://www.ujmp.org/
  • Scalalab: http://code.google.com/p/scalalab/
  • Java Content Based Image Retrieval (JCBIR): http://code.google.com/p/jcbir/
  • JquantLib (Will be added): http://www.jquantlib.org/

Performance and Benchmarks

What about speed, stability, and correctness? Constant benchmarking for speed and stability is a core part of EJML's development. It has many internal benchmarks and also uses Java Matrix Benchmark (JMatBench)[1] (http://code.google.com/p/java-matrix-benchmark/) to compare its performance against other libraries. At the time of this writing there are a total of 551 unit tests that test basic correctness of almost all the functions in EJML.

For runtime performance EJML is one of the fastest single threaded libraries. When compared against multi-threaded libraries on systems with several cores/CPU's it still competitive for many operations, despite its disadvantage of being single threaded. It has one of the lowest memory footprints [2].   A brief summary of EJML's performance relative to other libraries is shown below.

  • Runtime performance is measured on a Core i7M620 system.  (2 cores with 4 threads)
  • Performance varies significantly by system.
  • This processor was choosen because it is the most modern system benchmarked. 
  • Click here to get a explaination of the plots shown below.
Performance on Corei7M620


Memory Benchmark

[1] Both EJML and JMatBench are developed by the same author.

[2] Memory usage is highly dependent on the operation being used and the parameters passed to it. JMatBench only tests a few operations, but at least it shows attention is being paid to memory usage.

 

Library Matrix (protocol) Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Using Barcodes in iText 7
  • Using Java Class Extension Library for Data-Oriented Programming - Part 2
  • Using Java Class Extension Library for Data-Oriented Programming
  • Java 23: What Developers Need to Know

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!