The Universal Java Matrix Package (UJMP) is an open source Java library that provides sparse and dense matrix classes, as well as a large number of calculations for linear algebra like matrix multiplication or matrix inverse. Operations such as mean, correlation, standard deviation, replacement of missing values or the calculation of mutual information are supported, too.
The Universal Java Matrix Package provides various visualization methods, import and export filters for a large number of file formats, and even the possibility to link to JDBC databases. Multi-dimensional matrices as well as generic matrices with a specified object type are supported and very large matrices can be handled even when they do not fit into memory. Find out more and take a look at the feature list or compare it to other Java matrix libraries. We have also done a benchmark for matrix multiplication and matrix transposition which can be found here.
A central concept of UJMP is the separation of interfaces, abstract classes and their implementations, which makes it very easy to exchange the underlying data storage Thus, a matrix in our framework can be an array of values in main memory, a file on disk or a table in an SQL database. In fact, the actual storage implementation becomes secondary and UJMP can even integrate other matrix libraries such as Jama or Colt, making UJMP's visualization and import and export filters available to these libraries.
UJMP can decide to redirect calculations to other matrix libraries, depending on matrix size and computer hardware. UJMP uses multiple threads for calculations, which results in much better performance compared to JAMA or Colt on modern hardware.
UJMP also includes interfaces to Matlab, Octave and R, which makes it easy to perform calculations not available in Java.
UJMP is the mathematical back-end of the Java Data Mining Package (JDMP), which is our second open source Java project. While UJMP provides basic operations for processing matrices, JDMP concentrates on "higher-level" objects, such as Samples, DataSets and Algorithms for machine learning, e.g. clustering, classification and optimization. JDMP's central philosophy is that everything is a matrix (or can be converted into a matrix), which makes it possible to benefit a lot from UJMP's features. E.g. it becomes feasible to analyze data that does not fit into main memory, since UJMP can link to files on disk or databases. Like UJMP, also JDMP makes use of interfaces and abstract classes to allow for easy integration of other libraries like Weka or Mallet.
To find out if UJMP is the right choice for you, take a look at the feature list:
BigDecimalMatrix
, BigIntegerMatrix
, BooleanMatrix
, ByteMatrix
, DoubleMatrix
, FloatMatrix
, IntMatrix
, LongMatrix
, ObjectMatrix
, ShortMatrix
and StringMatrix
GenericMatrix<T>
to specify the object type that is stored.
Matrix.Factory.sparse(rows, columns, size3, size4, ...)
long
values for indices instead of int
.
Matrix.Factory.linkToJDBC(host, port, db, table, user, password)
CSVMatrix
or Matrix.Factory.linkToFile(Format.CSV, hugeCSVFile)
CachedMap
, RingBufferList
or SoftHashMap
which can be very helpful.
HashMap
.
Map
, List
or Set
can be used as UJMP matrices, which makes it easy to perform calculations. E.g. you can calculate sum, average or standard deviation of a list of values in an ArrayList
. Use this to convert it to a UJMP matrix:Matrix.Factory.linkToCollection(myArrayList)
myMatrix.showGUI()
to bring it on the screen. Take a look at the screenshots for examples.
Depending on your needs, you can either download jar packages of the latest release of UJMP, or check out the latest source code via SVN, if you want to stay on the edge.
The easiest way to get started with UJMP is to download ujmp-complete.jar from SourceForge.
This package contains ujmp-core, the main part of the Universal Java Matrix Package, as well as additional features such as visualization
and interfaces to other libraries, SQL databases, and a lot more. If you are new to this library, you should invoke the main()
method in org.ujmp.core.UJMP
to get a glimpse on UJMP:
java -jar ujmp-complete.jar
Then click on “Tools – UJMP Plugins” in the menu bar and see what third party libraries are supported. Chose the tool you want, add the necessary dependencies to the class path and restart UJMP.
The source code of UJMP is available via anonymous SVN from Sourceforge, and you can view the SVN repository in your web browser, if you like.
As you can see, there are many sub-projects in the repository, but probably you don’t need all of them.
You should check out ujmp-core and ujmp-gui first,
the other projects are needed only, if you want to use other libraries together with UJMP.
E.g. if you want to use JAMA, you would have to check out the ujmp-jama project.
If you use Maven for software development, you should also check
out the ujmp project, which provides the parent pom files for all sub-projects.
All projects provide a .project
file for Eclipse, which makes it easy to download them into this IDE.
Here is the command line instruction set to get the basic version of UJMP:
svn co https://svn.code.sf.net/p/ujmp/code/trunk/ujmp-core ujmp-core svn co https://svn.code.sf.net/p/ujmp/code/trunk/ujmp-gui ujmp-gui
If you use Maven, check out this project, too:
svn co https://svn.code.sf.net/p/ujmp/code/trunk/ujmp ujmp
Take a look at the following examples, this is the fastest way to learn about the Universal Java Matrix Package.
They are taken from ujmp-examples
freshly from SVN:
// create a TreeMatrix with Strings as elements TreeMatrix<String> treeMatrix = new DefaultTreeMatrix<String>(); // create data treeMatrix.setRoot("root"); treeMatrix.addChild("root", "child1"); treeMatrix.addChild("root", "child2"); treeMatrix.addChild("root", "child3"); treeMatrix.addChild("child1", "subChild11"); treeMatrix.addChild("child1", "subChild12"); treeMatrix.addChild("child1", "subChild13"); treeMatrix.addChild("child2", "subChild21"); treeMatrix.addChild("child3", "subChild31"); treeMatrix.addChild("child3", "subChild32"); treeMatrix.addChild("subChild12", "subSubChild121"); treeMatrix.addChild("subChild12", "subSubChild122"); treeMatrix.addChild("subSubChild122", "subSubSubChild1221"); // show on screen treeMatrix.showGUI();
// create a matrix from the Mandelbrot set Matrix m = new MandelbrotMatrix(); // show on screen m.showGUI();
// find all Excel files in one directory File[] files = new File("c:/temp/").listFiles(); // create matrix to store result Matrix result = Matrix.Factory.zeros(files.length, 2); // iterate over all files for (int i = 0; i < files.length; i++) { // import file as matrix Matrix m = Matrix.Factory.importFromFile(files[i]); // store file name in result matrix result.setAsString(files[i].getName(), i, 0); // search for "Invoice" if (m.containsString("Invoice")) // extract value at row 10 and column 3 and store in result result.setAsDouble(m.getAsDouble(10, 3), i, 1); } // display result on screen result.showGUI();
// create matrix with random values between 0 and 1 Matrix rand = Matrix.Factory.rand(100, 10); // create matrix with random values between -1 and - 1 Matrix randn = Matrix.Factory.randn(100, 10); // show on screen rand.showGUI(); randn.showGUI();
// create a GraphMatrix with Strings as nodes and Doubles as edges GraphMatrix<String, Double> graphMatrix = new DefaultGraphMatrix<String, Double>(); graphMatrix.setLabel("Interface Inheritance Graph"); // collect all matrix interfaces from UJMP Class<?>[] classArray = new Class[] { DenseMatrix.class, DenseMatrix2D.class, Matrix.class, Matrix2D.class, SparseMatrix.class, SparseMatrix2D.class, BigDecimalMatrix.class, BigDecimalMatrix2D.class, DenseBigDecimalMatrix.class, DenseBigDecimalMatrix2D.class, SparseBigDecimalMatrix.class, SparseBigDecimalMatrix2D.class, BigIntegerMatrix.class, BigIntegerMatrix2D.class, DenseBigIntegerMatrix.class, DenseBigIntegerMatrix2D.class, SparseBigIntegerMatrix.class, SparseBigIntegerMatrix2D.class, BooleanMatrix.class, BooleanMatrix2D.class, DenseBooleanMatrix.class, DenseBooleanMatrix2D.class, SparseBooleanMatrix.class, SparseBooleanMatrix2D.class, ByteArrayMatrix.class, ByteArrayMatrix2D.class, DenseByteArrayMatrix.class, DenseByteArrayMatrix2D.class, SparseByteArrayMatrix.class, SparseByteArrayMatrix2D.class, ByteMatrix.class, ByteMatrix2D.class, DenseByteMatrix.class, DenseByteMatrix2D.class, SparseByteMatrix.class, SparseByteMatrix2D.class, CharMatrix.class, CharMatrix2D.class, DenseCharMatrix.class, DenseCharMatrix2D.class, SparseCharMatrix.class, SparseCharMatrix2D.class, DoubleMatrix.class, DoubleMatrix2D.class, DenseDoubleMatrix.class, DenseDoubleMatrix2D.class, SparseDoubleMatrix.class, SparseDoubleMatrix2D.class, FloatMatrix.class, FloatMatrix2D.class, DenseFloatMatrix.class, DenseFloatMatrix2D.class, SparseFloatMatrix.class, SparseFloatMatrix2D.class, GenericMatrix.class, GenericMatrix2D.class, DenseGenericMatrix.class, DenseGenericMatrix2D.class, SparseGenericMatrix.class, SparseGenericMatrix2D.class, IntMatrix.class, IntMatrix2D.class, DenseIntMatrix.class, DenseIntMatrix2D.class, SparseIntMatrix.class, SparseIntMatrix2D.class, LongMatrix.class, LongMatrix2D.class, DenseLongMatrix.class, DenseLongMatrix2D.class, SparseLongMatrix.class, SparseLongMatrix2D.class, ObjectMatrix.class, ObjectMatrix2D.class, DenseObjectMatrix.class, DenseObjectMatrix2D.class, SparseObjectMatrix.class, SparseObjectMatrix2D.class, ShortMatrix.class, ShortMatrix2D.class, DenseShortMatrix.class, DenseShortMatrix2D.class, SparseShortMatrix.class, SparseShortMatrix2D.class, StringMatrix.class, StringMatrix2D.class, DenseStringMatrix.class, DenseStringMatrix2D.class, SparseStringMatrix.class, SparseStringMatrix2D.class }; // find out how interfaces extend one another for (Class<?> c1 : classArray) { for (Class<?> c2 : classArray) { if (c2.getSuperclass() == c1) { // add edge when class2 extends class1 graphMatrix.setEdge(1.0, c1.getSimpleName(), c2.getSimpleName()); } for (Class<?> c3 : c2.getInterfaces()) { if (c1 == c3) { // add edge when class2 implements class1 graphMatrix.setEdge(1.0, c1.getSimpleName(), c2.getSimpleName()); } } } } // show on screen graphMatrix.showGUI();
// create a matrix representing the local computer with its services Matrix localhost = Matrix.Factory.localhostMatrix(); // show on screen localhost.showGUI(); // double click on matrix entries to navigate and see how everything is // a matrix. Have fun exploring, but be careful when you change data!
// create a very large sparse matrix Matrix m = Matrix.Factory.sparse(ValueType.DOUBLE, 100000000, 100000000); // set some values to 1 for (int i = 0; i < 10000; i++) { m.setAsDouble(1, MathUtil.nextInteger(0, 100000), MathUtil.nextInteger(0, 100000)); } // show on screen m.showGUI();
// create matrix with 10 correlated columns, 100 rows, correlation 0.1 Matrix correlated = Matrix.Factory.correlatedColumns(100, 10, 0.1); // calculate similarity and store in new matrix, // ignore missing values if present Matrix similarity = correlated.cosineSimilarity(Ret.NEW, true); // show on screen correlated.showGUI(); similarity.showGUI();
// get an image InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("org/ujmp/examples/data/bigdata.jpg"); // load image into matrix. of course, this works with files, too. Matrix imageMatrix = new ImageMatrix(is); // show on screen imageMatrix.showGUI(); is.close();
// create matrix on disk in a temporary file DenseTiledFileDoubleMatrix2D m = new DenseTiledFileDoubleMatrix2D(8192, 8192); // fill an area with random values between -1 and 1 m.subMatrix(Ret.LINK, 1000, 1000, 2000, 2000).randn(Ret.ORIG); // fill an area with random values between 0 and 1 m.subMatrix(Ret.LINK, 4000, 7000, 6000, 8000).rand(Ret.ORIG); // set an area to a constant value of 10 m.subMatrix(Ret.LINK, 3000, 4000, 4000, 5000).fill(Ret.ORIG, 10); // let's see the result m.showGUI(); // Try to set the matrix size to larger values and see that you can // handle several gigabytes easily with UJMP. Don't forget to delete the // matrix in your temporary folder to save space
There are many matrix packages available for Java. If you are interested in alternative matrix packages, this table may be helpful.
UJMP | JAMA | Colt | Commons Math | EJML | Jampack | jblas | JLinAlg | JMathArray | JMatrices | JSci | JScience | la4j | Mantissa | MTJ | Ojalgo | Parallel Colt | Shared Scientific Toolbox | VecMath | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Latest Release | 0.2.5 2010-06-22 |
1.0.3 2012-12-09 |
1.2.0 2004-09-10 |
3.2 2013-04-06 |
0.2.4 2013-12-26 |
1999-02-24 |
1.2.3 2013-02-13 |
0.6 2009-09-23 |
2008-10-31 |
0.6 2004-05-10 |
1.5.2 2009-07-30 |
4.3.1 2007-10-04 |
0.4.9 2014-01-15 |
7.2 2007-10-07 |
1.0.1 2013-10-15 |
v35 2013-12-05 |
0.9.4 2010-03-21 |
1.11 |
1.5.2 |
License | LGPL | PD | CERN | Apache | Apache | BSD | BSD | LGPL | LGPL | BSD | Apache | BSD | LGPL | MIT | other | ||||
2D Matrix | |||||||||||||||||||
3D Matrix | |||||||||||||||||||
Multi-Dimensional Matrix | |||||||||||||||||||
Dense Matrix | |||||||||||||||||||
Sparse Matrix | |||||||||||||||||||
Iterator for all Entries | |||||||||||||||||||
Iterator for Non-Zero Entries | |||||||||||||||||||
Can Store Double Values | |||||||||||||||||||
Can Store Strings | |||||||||||||||||||
Can Store Objects | |||||||||||||||||||
Can Store Generics | |||||||||||||||||||
CSV Import/Export | |||||||||||||||||||
Binary Import/Export | |||||||||||||||||||
JDBC Import/Export | |||||||||||||||||||
Serializable | |||||||||||||||||||
Entries per Dimension | 2^{63}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 | 2^{31}-1 |
Max. Matrix Size | ~4000GB (Disk) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
~32GB (RAM) |
Supported in UJMP |
Project manager, UJMP core package, UJMP GUI package, interfaces to other libraries
Holger's Homepage
Strategical consultancy, marketing
Markus's Homepage
Core package, GUI package, test cases
Method for generalized matrix inversion
Rand's Homepage
Block matrix implementation and multiplication
Frode's LinkedIn Profile
You can use UJMP free of charge. However, if you like it, we would appreciate to receive a small donation from you. Please support open source software. Thank you very much!
Big Data Analytics • Data Mining • Machine Learning • Artificial Intelligence • Neural Networks