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
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

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • Using Barcodes in iText 7
  • Java 23: What Developers Need to Know
  • Using Lombok Library With JDK 23
  • Java for AI

Trending

  • What the CrowdStrike Crash Exposed About the Future of Software Testing
  • Build Retrieval-Augmented Generation (RAG) With Milvus
  • Java 23: What Developers Need to Know
  • Boosting Efficiency: Implementing Natural Language Processing With AWS RDS Using CloudFormation
  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.3K 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
  • Java 23: What Developers Need to Know
  • Using Lombok Library With JDK 23
  • Java for AI

Partner Resources


Comments

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: