Difference between revisions of "Manual"
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= The Basics = | = The Basics = | ||
− | + | Efficient Java Matrix Library (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. | 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. | ||
Line 9: | Line 9: | ||
* [http://groups.google.com/group/efficient-java-matrix-library-discuss Message Board] | * [http://groups.google.com/group/efficient-java-matrix-library-discuss Message Board] | ||
− | EJML is compatible with Java 1. | + | EJML is compatible with Java 1.8 and beyond. |
== The Interfaces == | == The Interfaces == | ||
Line 29: | Line 29: | ||
multTransB(c,H,S); | multTransB(c,H,S); | ||
addEquals(S,R); | addEquals(S,R); | ||
− | if( !invert(S,S_inv) ) throw new RuntimeException("Invert failed"); | + | if( !invert(S,S_inv) ) |
+ | throw new RuntimeException("Invert failed"); | ||
multTransA(H,S_inv,d); | multTransA(H,S_inv,d); | ||
mult(P,d,K); | mult(P,d,K); | ||
Line 49: | Line 50: | ||
[[Performance|Comparison of Interface Runtime Performance]] | [[Performance|Comparison of Interface Runtime Performance]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Tutorials = | = Tutorials = | ||
* [[Matlab to EJML|Matlab to EJML]] | * [[Matlab to EJML|Matlab to EJML]] | ||
+ | * [[Tutorial Complex|Complex]] | ||
* [[Solving Linear Systems|Solving Linear Systems]] | * [[Solving Linear Systems|Solving Linear Systems]] | ||
* [[Matrix Decompositions|Matrix Decompositions]] | * [[Matrix Decompositions|Matrix Decompositions]] | ||
− | |||
− | |||
* [[Random matrices, Matrix Features, and Matrix Norms]] | * [[Random matrices, Matrix Features, and Matrix Norms]] | ||
* [[Extract and Insert|Extracting and Inserting submatrices and vectors]] | * [[Extract and Insert|Extracting and Inserting submatrices and vectors]] | ||
Line 78: | Line 70: | ||
|- | |- | ||
| [[Example Kalman Filter|Kalman Filter]] || X || X || X | | [[Example Kalman Filter|Kalman Filter]] || X || X || X | ||
+ | |- | ||
+ | | [[Example Sparse Matrices|Sparse Matrix Basics]] || X || || | ||
|- | |- | ||
| [[Example Levenberg-Marquardt|Levenberg-Marquardt]] || X || || | | [[Example Levenberg-Marquardt|Levenberg-Marquardt]] || X || || | ||
|- | |- | ||
− | | [[Example Principal Component Analysis|Principal Component Analysis]] || X || X || X | + | | [[Example Principal Component Analysis|Principal Component Analysis]] || X || || |
+ | |- | ||
+ | | [[Example Polynomial Fitting|Polynomial Fitting]] || X || || | ||
+ | |- | ||
+ | | [[Example Polynomial Roots|Polynomial Roots]] || X || || | ||
+ | |- | ||
+ | | [[Example Customizing Equations|Customizing Equations]] || || || X | ||
|- | |- | ||
− | | [[Example | + | | [[Example Customizing SimpleMatrix|Customizing SimpleMatrix]] || || X || |
|- | |- | ||
− | | [[Example | + | | [[Example Fixed Sized Matrices|Fixed Sized Matrices]] || X || || |
+ | |- | ||
+ | | [[Example Complex Math|Complex Math]] || X || || | ||
+ | |- | ||
+ | | [[Example Complex Matrices|Complex Matrices]] || X || || | ||
+ | |- | ||
+ | | [[Example Concurrent Operations|Concurrent Operations]] || X || || | ||
+ | |- | ||
+ | | [[Example Graph Paths|(GraphBLAS) Graph Paths]] || X || || | ||
+ | |- | ||
+ | | [[Example Masked Triangle Count|(GraphBLAS) Masked Triangle Count]] || X || || | ||
+ | |- | ||
+ | | [[Example Large Dense Matrices|Optimizing Large Dense]] || X || || | ||
|} | |} | ||
Line 92: | Line 104: | ||
Want to learn more about how EJML works to write more effective code and employ more advanced techniques? Understand where EJML's logo comes from? The following books are recommended reading and made EJML's early development possible. | Want to learn more about how EJML works to write more effective code and employ more advanced techniques? Understand where EJML's logo comes from? The following books are recommended reading and made EJML's early development possible. | ||
* Best introduction to the subject that balances clarity without sacrificing important implementation details: | * Best introduction to the subject that balances clarity without sacrificing important implementation details: | ||
− | ** | + | ** Fundamentals of Matrix Computations by David S. Watkins |
* Classic reference book that tersely covers hundreds of algorithms | * Classic reference book that tersely covers hundreds of algorithms | ||
− | ** | + | ** Matrix Computations by G. Golub and C. Van Loan |
+ | * Direct Methods for Sparse Linear Systems by Timothy A. Davis | ||
+ | ** Covers the sparse algorithms used in EJML | ||
* Popular book on linear algebra | * Popular book on linear algebra | ||
− | ** | + | ** Linear Algebra and Its Applications by Gilbert Strang |
− | |||
− | |||
− |
Latest revision as of 07:22, 7 July 2021
The Basics
Efficient Java Matrix Library (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.
EJML is compatible with Java 1.8 and beyond.
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
Tutorials
- Matlab to EJML
- Complex
- Solving Linear Systems
- Matrix Decompositions
- Random matrices, Matrix Features, and Matrix Norms
- Extracting and Inserting submatrices and vectors
- Matrix Input/Output
- Unit Testing
Example Code
The follow are code examples of common linear algebra problems intended to demonstrate different parts of EJML. In the table below it indicates which interface or interfaces the example uses.
Name | Procedural | SimpleMatrix | Equations |
---|---|---|---|
Kalman Filter | X | X | X |
Sparse Matrix Basics | X | ||
Levenberg-Marquardt | X | ||
Principal Component Analysis | X | ||
Polynomial Fitting | X | ||
Polynomial Roots | X | ||
Customizing Equations | X | ||
Customizing SimpleMatrix | X | ||
Fixed Sized Matrices | X | ||
Complex Math | X | ||
Complex Matrices | X | ||
Concurrent Operations | X | ||
(GraphBLAS) Graph Paths | X | ||
(GraphBLAS) Masked Triangle Count | X | ||
Optimizing Large Dense | X |
External References
Want to learn more about how EJML works to write more effective code and employ more advanced techniques? Understand where EJML's logo comes from? The following books are recommended reading and made EJML's early development possible.
- Best introduction to the subject that balances clarity without sacrificing important implementation details:
- Fundamentals of Matrix Computations by David S. Watkins
- Classic reference book that tersely covers hundreds of algorithms
- Matrix Computations by G. Golub and C. Van Loan
- Direct Methods for Sparse Linear Systems by Timothy A. Davis
- Covers the sparse algorithms used in EJML
- Popular book on linear algebra
- Linear Algebra and Its Applications by Gilbert Strang