Andrew's code - reincarnated edited this page Aug 31, 2014 · 1 revision


JavaPlex can be called from any Java-based system. Below we show some examples.


As in the load_javaplex.m file in the matlab examples, one may use the following:

import edu.stanford.math.plex4.*;


Similarly, from Jython one may use the following:


CLASSPATH=$CLASSPATH:/path/to/javaplex.jar jython

Loading JavaPlex:

from edu.stanford.math.plex4 import *


The following example shows how to run from Java.

In a folder of your choice, download the file javaplex-4.1.0.jar. In the same folder, create a file named with the following contents:

import edu.stanford.math.plex4.api.Plex4;
import edu.stanford.math.plex4.examples.PointCloudExamples;
import edu.stanford.math.plex4.homology.barcodes.BarcodeCollection;
import edu.stanford.math.plex4.homology.chain_basis.Simplex;
import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceAlgorithm;
import edu.stanford.math.plex4.metric.impl.EuclideanMetricSpace;
import edu.stanford.math.plex4.metric.landmark.LandmarkSelector;
import edu.stanford.math.plex4.metric.landmark.MaxMinLandmarkSelector;
import edu.stanford.math.plex4.streams.impl.LazyWitnessStream;

public class WitnessComplexDemo {

	public static void main(String[] args) {
		int n = 10000;
		int d = 2;
		int numLandmarkPoints = 50;
		double maxDistance = 0.1;
		double[][] points = PointCloudExamples.getRandomSpherePoints(n, d);
		EuclideanMetricSpace metricSpace = new EuclideanMetricSpace(points);
		LandmarkSelector<double[]> landmarkSelector = new MaxMinLandmarkSelector<double[]>(metricSpace, numLandmarkPoints);
		LazyWitnessStream<double[]> stream = new LazyWitnessStream<double[]>(metricSpace, landmarkSelector, d + 1, maxDistance, 20);
		System.out.println("Number of simpleces in complex: " + stream.getSize());
		AbstractPersistenceAlgorithm<Simplex> algorithm = Plex4.getDefaultSimplicialAlgorithm(d + 1);
		BarcodeCollection<Double> intervals = algorithm.computeIntervals(stream);
		System.out.println("\nBarcodes for " + d + "-sphere:");

To compile the program, execute:

javac -classpath javaplex-4.1.0.jar

To run it, execute:

java -classpath .:javaplex-4.1.0.jar WitnessComplexDemo

Alternatively, one may use an IDE such as Eclipse and import the necessary jar files.


The Processing IDE and language, focused for producing programmatic art and graphics, works on a Java basis and can access arbitrary Java libraries. With a thin wrapper with some metadata, Java libraries can be packaged as plugins for Processing, making them even easier to use.

As of version 4.1.0, JavaPlex includes a Processing library plugin. Install it where Processing expects its plugin files, and you can import and use JavaPlex primitives - as demonstrated in the Java section above - from your Processing sketch. We also include an example sketch in the JavaPlex distribution demonstrating how to use JavaPlex form Processing.


JavaPlex can be used from the Mathematica computer algebra system by using the J/Link connection layer. Here is an example computation in Mathematica:

Plex4 = LoadJavaClass["edu.stanford.math.plex4.api.Plex4"]
sq = Plex4`createEuclideanMetricSpace[{{1, 0}, {1, 1}, {0, 0}, {0, 1}}]
vr = Plex4`createVietorisRipsStream[sq, 2, 2.0]
pers = Plex4`getDefaultSimplicialAlgorithm[2]
ints = pers@computeIntervals[vr]
intit = ints@iterator[]
For[ intit = ints@iterator[],
         int = intit@next[],
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.