Tutorial

Ok, so you are interested and want to see UJMP in action? And you have already checked out the source code from SVN or downloaded the package ujmp-complete.jar, right?

Well then, let’s get started!

1.1. Basic Demo

Try to start the main method in org.ujmp.gui.UJMP. You should get a new window on your screen visualizing a sample matrix. If you cannot see it, you should check your Java version and make sure, that you are using Sun’s JRE 6 or JDK 6.

Example Visualization in UJMP

The frame is split into three different parts: an editor for changing single cells of a matrix (right hand side), a 2D visualization of the whole content (bottom left) and other visualization methods, such as line plot (top left).
Positive values are displayed in green or yellow, while negative values are shown in red. Strings have different colors according to their hash code. Notice also that the panels are linked with each other, i.e. when you select a value (or a sub set of values) in the editor, the same value is highlighted in the visualization and vice versa.

1.2. Create Matrices

Everything working until here? OK, the next thing to do is to create your own matrices. Matrices in UJMP are created using the Factory Pattern. There are many different matrix implementations, like dense and sparse matrices stored in memory, on disk or in databases. The class MatrixFactory helps you to create the implementation you need for your task. Take a look at some examples:

// create an empty 10x10 matrix with double values:
Matrix m1 = MatrixFactory.dense(10, 10);
 
// create a sparse 10x10 matrix with double values:
Matrix m2 = MatrixFactory.sparse(10, 10);
 
// create a matrix where all entries are set to 1.0:
Matrix m3 = MatrixFactory.ones(10, 10);
 
// create a matrix where all entries are set to 3.14159:
Matrix m4 = MatrixFactory.fill(3.14159, 10, 10);
 
// create a matrix filled with random numbers (Gaussian distribution):
Matrix m5 = MatrixFactory.randn(10, 3);
 
// create a matrix filled with random numbers (uniform distribution):
Matrix m6 = MatrixFactory.rand(5, 5);
 
// create an "eye" matrix: [0,0]=1; [1,1]=1; [2,2]=1; [3,3]=1:
Matrix m7 = MatrixFactory.eye(4, 4);
 
// create an empty 0x0 matrix:
Matrix m0 = MatrixFactory.emptyMatrix();

Pretty much self-explanatory, right? But what was an eye matrix again? Let’s find out by looking at the content of this matrix:

System.out.println(m7);
// prints: 
//    1.0000    0.0000    0.0000    0.0000
//    0.0000    1.0000    0.0000    0.0000
//    0.0000    0.0000    1.0000    0.0000
//    0.0000    0.0000    0.0000    1.0000

You can see it even better using visualization:

m7.showGUI();

1.3. Import

Maybe you have your own CSV-file ready with some data or you can download an example file here: example.csv

In any case, the first step would be to import the data into UJMP as a Matrix:

File myDataFile = new File("example.csv");
Matrix myData = MatrixFactory.importFromFile(FileFormat.CSV, myDataFile);

That was easy, right? UJMP can import many CSV files without the need to specify parameters. Sometimes however, it might be necessary to provide more detailed information how the CSV file should be parsed. In this case, you can define column delimiter or line delimiter. You can also import data from text files (MatrixFactory.importFromFile(FileFormat.TXT)), Excel (MatrixFactory.importFromFile(FileFormat.XLS)), or other formats like BMP or WAV. In addition to that, you can use tables in JDBC databases (e.g. from MySQL or PostgreSQL) as a data source (MatrixFactory.importFromJDBC() or MatrixFactory.linkToJDBC() if you do not want to copy the data).

If your data type is not supported, you will have to convert the data yourself (and maybe send the converter to us, so we can integrate it into UJMP). Writing your own converter is not that difficult, as long as the source format is not too complicated. See section “Writing your own matrices” for further information.

1.4. Analyze

Fine, we have imported the data, now let’s take a first look at what exactly we have imported:

myData.showGUI();

As result, we obtain the following GUI:

Iris data set

Of course, you can perform standard matrix calculation very easily. For instance, it could happen that the imported data has interchanged x- and y-axis. To get the correct matrix, perform myData.transpose().

more text is coming soon…
Please take a look at the UJMP Forum in the meantime

  • del.icio.us
  • Google Bookmarks
  • MisterWong
  • Facebook
  • Digg
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
  • email
  • Print

Comments are closed.