### Get house example from JavaPlex examples Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Commented-out alternative to manually entering the house point cloud coordinates. Uses the JavaPlex example class. ```matlab %>> point_cloud = examples.PointCloudExamples.getHouseExample(); % ``` -------------------------------- ### Torus Witness Stream Setup Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Sets up parameters for the torus witness stream example: 10,000 points, 50 landmarks, max dimension 3, and 1000 divisions. ```matlab >> num_points = 10000; >> num_landmark_points = 50; >> max_dimension = 3; >> num_divisions = 1000; ``` -------------------------------- ### Change to tutorial_examples directory Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Changes the current Matlab directory to the tutorial examples folder. ```matlab >> cd tutorial_examples ``` -------------------------------- ### Verify Plex installation with Simplex.makePoint Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Execute this command in the Matlab command window after restarting Matlab to verify the installation. The expected output is shown. ```matlab >> Simplex.makePoint(1, 2) ans = <(2) 1> ``` -------------------------------- ### Commented example for sublevelset persistence Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex A commented example showing how to convert intervals to a matrix and compute a Betti vector using Plex.FilterInfinite. This is a placeholder for the sublevelset persistence example. ```matlab %>> java.lang.Runtime.getRuntime.maxMemory %ans = 130875392 % ``` -------------------------------- ### 2-Sphere Lazy Witness Stream Setup Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Sets up parameters for the 2-sphere lazy witness stream example: 1000 points, 50 landmarks, max dimension 3, nu=1, and 1000 divisions. ```matlab >> max_dimension = 3; >> num_points = 1000; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; ``` -------------------------------- ### Run JPlex with BeanShell Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/houseFig.pdf Starts the JPlex GUI from the command line. Requires a Java Virtual Machine and the jplex.jar file in the current directory or a subdirectory. ```shell java -cp plex.jar JPlex ``` -------------------------------- ### Get Betti numbers as list Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Prints the Betti numbers as a list with entries of the form k: Betti_k. For the house example, it returns {0: 1, 1: 1}. ```matlab >> betti_numbers_string = infinite_barcodes.getBettiNumbers() betti_numbers_string = {0: 1, 1: 1} ``` -------------------------------- ### Verify JPlex Installation Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Execute a simple command in the BeanShell prompt to confirm JPlex is working. Output is wrapped in '<<>>'. ```beanshell plex> Simplex.makePoint(1,2); ``` -------------------------------- ### Create house point cloud matrix in Matlab Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Manually enter the coordinates of the house example as a Matlab matrix. The output shows the resulting matrix. ```matlab >> point_cloud = [-1,0; 1,0; 1,2; -1,2; 0,3] point_cloud = -1 0 1 0 1 2 -1 2 0 3 ``` -------------------------------- ### Create Torus Witness Stream Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates the witness stream for the torus example and displays the number of simplices. ```matlab >> stream = api.Plex4.createWitnessStream(landmark_selector, max_dimension,... max_filtration_value, num_divisions); >> num_simplices = stream.getSize() num_simplices = 1164 % Generally close to 1200 ``` -------------------------------- ### Get Betti numbers from infinite intervals Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Retrieves infinite intervals and computes the Betti sequence. For the torus example, the output is [1, 2, 1]. ```matlab >> infinite_barcodes = intervals.getInfiniteIntervals(); >> betti_numbers_array = infinite_barcodes.getBettiSequence() betti_numbers_array 1 2 1 ``` -------------------------------- ### Build 9-sphere example Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Builds a 9-sphere by adding a 10-simplex, ensuring all faces, removing the 10-simplex, and finalizing the stream. The result is the boundary of a 10-simplex, homeomorphic to a 9-sphere. ```matlab >> dimension = 9; >> stream = api.Plex4.createExplicitSimplexStream(); >> stream.addElement(0:(dimension + 1)); >> stream.ensureAllFaces(); >> stream.removeElementIfPresent(0:(dimension + 1)); >> stream.finalizeStream(); ``` -------------------------------- ### Verify JPlex installation with Simplex.makePoint Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/houseFig.pdf Confirms JPlex is working by creating a point simplex. The output is wrapped in angle brackets, as shown. ```beanshell plex> Simplex.makePoint(1,2); <<(2) 1>> ``` -------------------------------- ### Create Torus Point Cloud and Landmark Selector Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates a random sphere product point cloud (torus) and a maxmin landmark selector for the torus witness stream example. ```matlab >> point_cloud = examples.PointCloudExamples.getRandomSphereProductPoints(num_points,... 1, 2); >> landmark_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Get Betti sequence as array Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Prints the Betti numbers at the largest filtration value as an array. For the house example, it returns [1, 1]. ```matlab >> betti_numbers_array = infinite_barcodes.getBettiSequence() betti_numbers_array = 1 1 ``` -------------------------------- ### Create figure eight point cloud with 1000 points Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates a point cloud of 1000 points from a figure eight using the JavaPlex example class. Used as the dataset for landmark selection examples. ```matlab >> point_cloud = examples.PointCloudExamples.getRandomFigure8Points(1000); ``` -------------------------------- ### Create 2-Sphere Point Cloud and Landmark Selector Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates a random sphere point cloud and a maxmin landmark selector for the 2-sphere lazy witness stream example. ```matlab >> point_cloud = examples.PointCloudExamples.getRandomSpherePoints(num_points,... max_dimension-1); >> landmark_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Compute intervals for house example Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Computes persistence intervals for the house stream. The output shows intervals for dimensions 1 and 0, including a Betti_1 interval [3.0, 7.0) and a Betti_0 interval [1.0, 2.0). ```matlab >> intervals = persistence.computeIntervals(stream) intervals Dimension: 1 [3.0, 7.0) [0.0, infinity) Dimension: 0 [1.0, 2.0) [0.0, infinity) ``` -------------------------------- ### Verify Javaplex installation Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Run this command to confirm Javaplex is working properly. The output should be the same except for the last several characters, which are the object's memory address. ```matlab >> api.Plex4.createExplicitSimplexStream() ans = edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream@513fd4 ``` -------------------------------- ### Set up lazy witness stream parameters in Matlab Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Initializes parameters for the lazy witness stream example: max_dimension=3, num_points=1000, num_landmark_points=50, nu=1, num_divisions=1000. Then generates a random sphere point cloud and selects landmarks using a max-min selector. ```matlab >> max_dimension = 3; >> num_points = 1000; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; >> point_cloud = examples.PointCloudExamples.getRandomSpherePoints(num_points, max_dimension - 1); >> landmark_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Set Java heap size in java.opts Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Create a file named java.opts in your MATLAB startup directory and include a line specifying the -Xmx value to set the maximum Java heap size. This example sets it to 128 megabytes. ```text -Xmx128m ``` -------------------------------- ### Plot barcodes for torus example Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Configures plot options and generates barcode plots, saving the output to ripsTorus.png. ```matlab >> options.filename = 'ripsTorus'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension-1; >> options.side_by_side = true; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Get point coordinates from metric space Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Returns the coordinates of a specific point. Points are indexed starting at 0. Shows output for points 0 and 2. ```matlab >> m_space.getPoint(0) ans = -1 0 >> m_space.getPoint(2) ans = 1 2 ``` -------------------------------- ### Java example: compute cohomology of a 2-sphere Source: https://github.com/appliedtopology/javaplex/wiki/Cohomology Constructs a 2-simplex (triangle) as a 2-sphere, dualizes the stream, and computes annotated cohomology intervals using a modular field of prime 13. The simplex order is reversed using Collections.reverseOrder. The output prints the cohomology basis for the 2-sphere. ```java import edu.stanford.math.plex4.api.Plex4; import edu.stanford.math.plex4.homology.barcodes.BarcodeCollection; import edu.stanford.math.*; import edu.stanford.math.plex4.homology.barcodes.AnnotatedBarcodeCollection; import edu.stanford.math.plex4.homology.chain_basis.Simplex; import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceAlgorithm; import edu.stanford.math.plex4.streams.derived.DualStream; import edu.stanford.math.plex4.autogen.homology.IntAbsoluteHomology; import edu.stanford.math.primitivelib.algebraic.impl.ModularIntField; import edu.stanford.math.plex4.homology.chain_basis.SimplexComparator; import java.util.*; import java.lang.*; import edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream; import edu.stanford.math.plex4.*; import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceBasisAlgorithm; public class CohomologyExample { public static void main(String[] args) { int prime=13; int d = 2; ExplicitSimplexStream stream = new ExplicitSimplexStream(); stream.addVertex(0); stream.addVertex(1); stream.addVertex(2); int[][] edges = {{0,1},{0,2},{1,2}}; for(int i = 0; i != edges.length; ++i){ stream.addElement(edges[i]); } stream.finalizeStream(); AbstractPersistenceBasisAlgorithm annotated_coalgorithm = new IntAbsoluteHomology(ModularIntField.getInstance(prime), Collections.reverseOrder(SimplexComparator.getInstance()), 0, d+1); DualStream costream = new DualStream(stream); AnnotatedBarcodeCollection annotated_cointervals = annotated_algorithm.computeAnnotatedIntervals(costream); System.out.println("\Cohomology basis for " + d + "-sphere:"); System.out.println(annotated_cointervals); } } ``` -------------------------------- ### Get modular simplicial algorithm for persistence Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates a persistence algorithm with Z/2Z coefficients for a given dimension. Used before computing intervals. ```matlab persistence = api.Plex4.getModularSimplicialAlgorithm(dimension + 1, 2); ``` -------------------------------- ### Build explicit simplex stream for house example Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Builds a simplicial complex representing a house with vertices and edges appearing at specified filtration values. The stream is finalized after adding all elements. ```matlab >> stream = api.Plex4.createExplicitSimplexStream(); >> stream.addVertex(1, 0); >> stream.addVertex(2, 0); >> stream.addVertex(3, 0); >> stream.addVertex(4, 0); >> stream.addVertex(5, 1); >> stream.addElement([1, 2], 0); >> stream.addElement([2, 3], 0); >> stream.addElement([3, 4], 0); >> stream.addElement([4, 1], 0); >> stream.addElement([3, 5], 2); >> stream.addElement([4, 5], 3); >> stream.addElement([3, 4, 5], 7); >> stream.finalizeStream(); ``` -------------------------------- ### Create an empty ExplicitStream Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/houseFig.pdf Instantiates an ExplicitStream object to build a filtered simplicial complex by hand. This is the first step in constructing the house example. ```beanshell plex> ExplicitStream house = new ExplicitStream(); ``` -------------------------------- ### Prime numbers example with k = 1 Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Builds the core subset of the 10 densest prime numbers less than or equal to 3571 using density parameter k = 1. The output shows the core subset contains many twin primes. ```matlab >> p = primes(3571)'; >> length(p) ans = 500 >> densities1 = kDensitySlow(p, 1); >> core1 = coreSubset(p, densities1, 10) core1 2 3 5 7 11 13 17 19 29 31 ``` -------------------------------- ### Prime numbers example with k = 50 Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Builds the core subset of the 10 densest prime numbers using density parameter k = 50. The output shows the densest points are slightly larger than the 25-th prime, which is 97. ```matlab >> densities50 = kDensitySlow(p, 50); >> core50 = coreSubset(p, densities50, 10) core50 113 127 109 131 107 137 139 157 149 151 ``` -------------------------------- ### Create Rips Stream and Compute Persistence Intervals Source: https://github.com/appliedtopology/javaplex/blob/master/src/cpp/PLEX3/man/rips.stream.Rd Loads point data from a CSV file, creates a RipsStream from the distance matrix, calculates persistence intervals, and uses FilterInfinite to get Betti numbers. ```R ## Load point data from a CSV file pointdata <- read.table("plex_torus_data.txt") ## Create the RipsStream from the distance matrix stream <- rips.stream(pointdata) ## Calculate persistence intervals from the RipsStream intervals <- persistence.intervals(stream) ## Use FilterInfinite to get Betti numbers filter.infinite(intervals) ``` -------------------------------- ### Define house point cloud coordinates Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Enter Euclidean coordinates for the house example as a Matlab matrix. The resulting point_cloud variable is used to create a metric space. ```matlab >> point_cloud = [-1,0; 1,0; 1,2;-1,2; 0,3] ``` -------------------------------- ### Compute and print intervals Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Computes and prints the persistence intervals. For the circle example, the output shows one interval in dimension 1 and one in dimension 0, giving Betti numbers Betti0 = 1 and Betti1 = 1. ```matlab >> intervals = persistence.computeIntervals(stream) intervals = Dimension: 1 [0.0, infinity) Dimension: 0 [0.0, infinity) ``` -------------------------------- ### Compute annotated intervals for house example Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Computes annotated intervals to obtain representative cycles for each barcode. The output shows cycles for each interval, e.g., [4,5] + [3,4] + -[3,5] for the [3.0, 7.0) interval. ```matlab >> intervals = persistence.computeAnnotatedIntervals(stream) intervals = Dimension: 1 [3.0, 7.0): [4,5] + [3,4] + -[3,5] [0.0, infinity): [1,4] + [2,3] + [1,2] + [3,4] Dimension: 0 [1.0, 2.0): -[3] + [5] [0.0, infinity): [1] ``` -------------------------------- ### Create ExplicitStream and add simplices for house example Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Builds a filtered simplicial complex representing a house. Vertices and edges on the square appear at value 0, the top vertex at 1, roof edges at 2 and 3, and the roof 2-simplex at 7. The stream is finalized before computing persistence. ```matlab >> stream = api.Plex4.createExplicitSimplexStream(); ``` ```matlab >> stream.addVertex(1, 0); ``` ```matlab >> stream.addVertex(2, 0); ``` ```matlab >> stream.addVertex(3, 0); ``` ```matlab >> stream.addVertex(4, 0); ``` ```matlab >> stream.addVertex(5, 1); ``` ```matlab >> stream.addElement([1, 2], 0); ``` ```matlab >> stream.addElement([2, 3], 0); ``` ```matlab >> stream.addElement([3, 4], 0); ``` ```matlab >> stream.addElement([4, 1], 0); ``` ```matlab >> stream.addElement([3, 5], 2); ``` ```matlab >> stream.addElement([4, 5], 3); ``` ```matlab >> stream.addElement([3, 4, 5], 7); ``` ```matlab >> stream.finalizeStream(); ``` -------------------------------- ### Get infinite intervals and Betti numbers Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Retrieves infinite intervals from the annotated intervals and prints Betti numbers as an array or a list. The output shows one infinite interval in each dimension 0 and 1. ```matlab >> infinite_barcodes = intervals.getInfiniteIntervals() infinite_barcodes = Dimension: 1 [0.0, infinity): [1,4] + [2,3] + [1,2] + [3,4] Dimension: 0 [0.0, infinity): [1] ``` ```matlab >> betti_numbers_array = infinite_barcodes.getBettiSequence() betti_numbers_array = 1 1 ``` ```matlab >> betti_numbers_string = infinite_barcodes.getBettiNumbers() betti_numbers_string = {0: 1, 1: 1} ``` -------------------------------- ### Check maximum Java heap size in Matlab Source: https://github.com/appliedtopology/javaplex/wiki/Troubleshooting Run this Matlab command to display the current maximum Java heap size in bytes. The output shows an example value of 130875392 bytes. ```matlab >> java.lang.Runtime.getRuntime.maxMemory ans = 130875392 ``` -------------------------------- ### Create witness stream and get size Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates the witness stream using the landmark selector, max dimension, max filtration value, and number of divisions. The stream size is generally close to 1200 simplices. ```matlab >> stream = api.Plex4.createWitnessStream(landmark_selector, max_dimension, max_filtration_value, num_divisions); >> num_simplices = stream.getSize() num_simplices = 1164 # Generally close to 1200 ``` -------------------------------- ### Create Euclidean metric space from point cloud coordinates Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Defines a point cloud matrix for a house shape and creates a Euclidean metric space using metric.impl.EuclideanMetricSpace. The matrix rows are point coordinates, and points are indexed starting at 0. ```matlab >> point_cloud = [-1,0; 1,0; 1,2; -1,2; 0,3] point_cloud = -1 0 1 0 1 2 -1 2 0 3 ``` ```matlab >> m_space = metric.impl.EuclideanMetricSpace(point_cloud); ``` -------------------------------- ### Get point coordinates from metric space Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Return the coordinates of a specific point. Points are indexed starting at 0. ```matlab >> m_space.getPoint(0) ans = -1 0 ``` ```matlab >> m_space.getPoint(2) ans = 1 2 ``` -------------------------------- ### Add plex.jar to Java class path and import package in startup.m Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Add these lines to your Matlab startup.m file to make Plex available. The path should be the directory where you placed plex.jar. ```matlab javaaddpath('/my/path/mydir/plex.jar'); import edu.stanford.math.plex.*; ``` -------------------------------- ### Get point coordinates from Euclidean metric space Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Retrieves coordinates of specific points using getPoint(index). Points are indexed starting at 0. ```matlab >> m_space.getPoint(0) ans -1 0 ``` ```matlab >> m_space.getPoint(2) ans 1 2 ``` -------------------------------- ### Set up witness stream parameters and point cloud Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Initializes parameters for a witness stream: 10,000 random points from the unit torus S^1 x S^1 in R^4, 50 sequential maxmin landmarks, max dimension 3, and 1000 divisions. Creates the point cloud and landmark selector. ```matlab >> num_points = 10000; >> num_landmark_points = 50; >> max_dimension = 3; >> num_divisions = 1000; >> point_cloud = examples.PointCloudExamples.getRandomSphereProductPoints(num_points, 1, 2); >> landmark_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Load torus point cloud and build Vietoris-Rips stream Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Loads pointsTorusGrid.mat, creates a Vietoris-Rips stream, computes intervals, and plots barcodes side by side. Requires being in tutorial_examples directory. ```matlab >> load pointsTorusGrid.mat >> point_cloud = pointsTorusGrid; >> size(point_cloud) ans = 400 4 # 400 points in dimension 4 >> stream = api.Plex4.createVietorisRipsStream(point_cloud, max_dimension, max_filtration_value, num_divisions); >> num_simplices = stream.getSize() num_simplices = 82479 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'ripsTorus'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> options.side_by_side = true; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Run explicit_simplex_example script Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Runs the Matlab script corresponding to this section, either by copying commands or executing the whole script. ```matlab >> explicit_simplex_example ``` -------------------------------- ### Create torus point cloud and maxmin landmark selector Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Sets up the point cloud of 10,000 random points from the unit torus in R^4 and creates a maxmin landmark selector with 50 landmarks. The variables num_points, num_landmark_points, max_dimension, and num_divisions are defined for subsequent steps. ```matlab >> num_points = 10000; >> num_landmark_points = 50; >> max_dimension = 3; >> num_divisions = 1000; >> point_cloud = examples.PointCloudExamples.getRandomSphereProductPoints(num_points, ... 1, 2); >> landmark_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Load Javaplex in Matlab Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Run this command in the Matlab command window after changing the current folder to the extracted matlab_examples directory. This loads the Javaplex library. ```matlab >> load_javaplex ``` -------------------------------- ### MATLAB session using Plex to compute persistence intervals Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm A toy MATLAB session showing creation of a Persistence object, a Torus, a RipsStream, and computing persistence intervals. The output shows the object references and the size of the stream. ```matlab >> p = Plex.Persistence() p = edu.stanford.math.plex.Persistence@11eea7f0 >> tor = Plex.Torus(20, 2) tor = edu.stanford.math.plex.Torus@1ae2b9e5 >> rc = Plex.RipsStream(0.053096, 0.530956, 3, tor) rc = edu.stanford.math.plex.RipsStream@675ee9e3 >> rc.size() ans = 4000 >> res = Plex.FilterInfinite(p.computeIntervals(rc)) res = BN{1, 2, 1} ``` -------------------------------- ### Get infinite intervals Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Retrieves only the infinite intervals from the computed intervals. The output shows the semi-infinite intervals for dimensions 1 and 0. ```matlab >> infinite_barcodes = intervals.getInfiniteIntervals() infinite_barcodes = Dimension: 1 [0.0, infinity): [1,4] + [2,3] + [1,2] + [3,4] Dimension: 0 [0.0, infinity): [1] ``` -------------------------------- ### Get random figure 8 points for exercise Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Generates 75 points randomly sampled from a figure 8 space for Exercise 9. ```matlab >> point_cloud = examples.PointCloudExamples.getRandomFigure8Points(75); ``` -------------------------------- ### Check Java launcher location with which java Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Use this command to verify that a Java launcher is available on a Linux system. The output is the path to the java executable. ```bash % which java ``` -------------------------------- ### Build a core subset with coreSubset.m Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Typical command to build a core subset from points and their density estimates. Output core is a numPoints x n matrix representing the numPoints densest points. ```matlab >> core = coreSubset(points, densities, numPoints); ``` -------------------------------- ### Load optical image patch data (k15) Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Loads the matrix pointsOpticalDct_k15 from the file pointsOpticalDct_k15.mat and displays its size. The matrix contains 15000 points in dimension 8, representing the dense core subset X(15,30). ```matlab >> load pointsOpticalDct_k15 >> size(pointsOpticalDct_k15) ans = 15000 8 # 15000 points in dimension 8 ``` -------------------------------- ### Create landmark selector and build lazy witness stream Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates a max-min landmark selector, computes the maximum distance from points to landmarks, and builds a lazy witness stream with the specified parameters. ```matlab landmark_selector = api.Plex4.createMaxMinSelector(pointsOpticalDct_k15,... num_landmark_points); R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.6554 max_filtration_value = R / 4; stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(),... landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); stream.finalizeStream() num_simplices = stream.getSize() num_simplices = 1570 ``` -------------------------------- ### Check Java version with java -version Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Use this command to check the version of Java available from the command line. The output shows the Java version and build details. ```bash % java -version Java version "1.5.0_08" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_08-b03, mixed mode) ``` -------------------------------- ### Load optical image patch data (k300) Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Loads the matrix pointsOpticalDct_k300 from the file pointsOpticalDct_k300.mat and displays its size. The matrix contains 15000 points in dimension 8, representing the dense core subset X(300,30). ```matlab >> load pointsOpticalDct_k300 >> size(pointsOpticalDct_k300) ans = 15000 8 # 15000 points in dimension 8 ``` -------------------------------- ### Load torus point cloud and check size Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Loads the pointsTorusGrid.mat file and displays the size of the point cloud matrix. ```matlab >> load pointsTorusGrid.mat >> point_cloud = pointsTorusGrid; >> size(point_cloud) ans = 400 4 % 400 points in dimension 4 ``` -------------------------------- ### Run WitnessComplexDemo Source: https://github.com/appliedtopology/javaplex/wiki/Interoperability Runs the compiled Java program with the current directory and javaplex.jar on the classpath. ```bash java -classpath .:javaplex.jar WitnessComplexDemo ``` -------------------------------- ### Add vertices and simplices for circle Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Adds three vertices and three edges to build a simplicial complex homeomorphic to a circle. All simplices get filtration value zero by default. finalizeStream must be called before using the complex. ```matlab >> stream.addVertex(0); >> stream.addVertex(1); >> stream.addVertex(2); >> stream.addElement([0, 1]); >> stream.addElement([0, 2]); >> stream.addElement([1, 2]); >> stream.finalizeStream(); ``` -------------------------------- ### Create random and maxmin landmark selectors Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates a random landmark selector and a sequential maxmin selector, each configured to pick 100 landmarks from the point cloud. The selectors are created using api.Plex4.createRandomSelector and api.Plex4.createMaxMinSelector. ```matlab >> num_landmark_points = 100; >> random_selector = api.Plex4.createRandomSelector(point_cloud, num_landmark_points); >> maxmin_selector = api.Plex4.createMaxMinSelector(point_cloud, num_landmark_points); ``` -------------------------------- ### Compute density estimates with kDensitySlow.m Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Typical command to compute density estimates 1/p_k for a Euclidean point cloud. Input points is an N x n matrix, k is the density estimate parameter, and output densities is a vertical vector of length N. ```matlab >> densities = kDensitySlow(points, k); ``` -------------------------------- ### Build lazy witness stream for k300 dataset Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Sets parameters and builds a lazy witness stream for the k300 dataset. It selects 50 maxmin landmarks, computes R, and constructs the stream with nu=1 and 1000 divisions. ```matlab >> max_dimension = 3; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; >> landmark_selector = api.Plex4.createMaxMinSelector(pointsOpticalDct_k300,... num_landmark_points); >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.5919 >> max_filtration_value = R / 4; >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(),... landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 2351 ``` -------------------------------- ### Build core subset with coreSubset.m Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Selects the numPoints densest points from a point cloud based on precomputed density estimates. Inputs points and densities are as in kDensitySlow, and output core is a numPoints x n matrix. ```matlab >> core = coreSubset(points, densities, numPoints); ``` -------------------------------- ### Create modular simplicial algorithm Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates an object to compute homology. First parameter 3 means dimensions 0, 1, and 2; second parameter 2 means Z/2Z coefficients (any prime allowed). ```matlab >> persistence = api.Plex4.getModularSimplicialAlgorithm(3, 2); ``` -------------------------------- ### Build Vietoris-Rips stream and compute persistence Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates a Vietoris-Rips stream from the point cloud and computes persistent homology intervals using the modular simplicial algorithm. ```matlab >> stream = api.Plex4.createVietorisRipsStream(point_cloud, max_dimension,... max_filtration_value, num_divisions); >> num_simplices = stream.getSize() num_simplices = 82479 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); ``` -------------------------------- ### Convert intervals to matrix and compute Betti vector Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Shows conversion of intervals to a matrix and computation of a Betti vector using Plex.FilterInfinite. The code is commented out. ```matlab intervalMatrix = interval2mat(intervals); %>> bettiVect = betti2vect(Plex.FilterInfinite(intervals)); % ``` -------------------------------- ### Compute Persistence Intervals Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Create a modular simplicial algorithm and compute persistence intervals for a stream. The output shows intervals with dimension and birth-death pairs. ```beanshell persistence = api.Plex4.getModularSimplicialAlgorithm(dimension + 1, 2); ``` ```beanshell intervals = persistence.computeIntervals(stream) ``` -------------------------------- ### Create lazy witness stream from cyclo-octane points Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Creates a max-min landmark selector and a lazy witness stream from the cyclo-octane points, then finalizes the stream and reports the number of simplices. ```Matlab >> landmark_selector = api.Plex4.createMaxMinSelector(pointsCycloOctane,... num_landmark_points); >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.8046 >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(),... landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 8025 ``` -------------------------------- ### Create ExplicitMetricSpace from distance matrix Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Creates a metric space from the house distance matrix using metric.impl.ExplicitMetricSpace. ```matlab >> m_space = metric.impl.ExplicitMetricSpace(distances); ``` -------------------------------- ### Import Javaplex package in Matlab Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Type this command in the Matlab command window to import the Javaplex package. This is required to access the Javaplex classes. ```matlab >> import edu.stanford.math.plex4.*; ``` -------------------------------- ### Load cyclo-octane points and check size Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Loads the pointsCycloOctane.mat file containing a 6040x24 matrix of sample points from the cyclo-octane conformation space. The size command confirms the dimensions. ```matlab >> load pointsCycloOctane.mat >> size(pointsCycloOctane) ans = 6040 24 # 6040 points in dimension 24 ``` -------------------------------- ### Compile WitnessComplexDemo.java Source: https://github.com/appliedtopology/javaplex/wiki/Interoperability Compiles the Java program using javac with javaplex.jar on the classpath. ```bash javac -classpath javaplex.jar WitnessComplexDemo.java ``` -------------------------------- ### Build lazy witness stream and compute persistence for X(300,30) Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Sets up parameters, selects 50 maxmin landmark points, builds a lazy witness stream with nu=1, computes persistence intervals, and plots barcodes. The output shows R=0.5919 and num_simplices=2351. The plot is saved to lazyOpticalDct-k300.png. ```matlab >> max_dimension = 3; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; >> landmark_selector = api.Plex4.createMaxMinSelector(pointsOpticalDct_k300, num_landmark_points); >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.5919 >> max_filtration_value = R / 4; >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(), landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 2351 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'lazyOpticalDct-k300'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Create maxmin selector for general metric space Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Shows how to select landmarks from a general metric space (m_space) using sequential maxmin. The selector is created with api.Plex4.createMaxMinSelector. ```matlab >> maxmin_selector = api.Plex4.createMaxMinSelector(m_space, num_landmark_points); ``` -------------------------------- ### Check Java VM used by Matlab with version -java Source: https://github.com/appliedtopology/javaplex/blob/master/doc_includes/overview_plex3.htm Execute this command in the Matlab command window to check the Java VM version used by Matlab. The output shows the Java version and VM details. ```matlab >> version -java ans = Java 1.5.0_04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode ``` -------------------------------- ### Compute persistent homology of optical image patches with lazy witness stream Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Sets up a lazy witness stream with max-min landmark selection, computes persistence intervals with the modular simplicial algorithm, and plots barcodes. The output shows R = 0.6554 and num_simplices = 1570, and saves the plot to lazyOpticalDct-k15.png. ```matlab >> max_dimension = 3; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; >> landmark_selector = api.Plex4.createMaxMinSelector(pointsOpticalDct_k15, num_landmark_points); >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.6554 >> max_filtration_value = R / 4; >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(), landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 1570 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'lazyOpticalDct-k15'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Compute persistent homology intervals with Z/2Z coefficients Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Uses getModularSimplicialAlgorithm with dimension 3 and modulus 2 to compute persistent homology intervals for the house stream. The output shows one Betti1 interval [3.0, 7.0) and two Betti0 intervals [1.0, 2.0) and [0.0, infinity). ```matlab >> persistence = api.Plex4.getModularSimplicialAlgorithm(3, 2); ``` ```matlab >> intervals = persistence.computeIntervals(stream) intervals = Dimension: 1 [3.0, 7.0) [0.0, infinity) Dimension: 0 [1.0, 2.0) [0.0, infinity) ``` -------------------------------- ### Create Vietoris-Rips stream from a metric space Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Builds a Vietoris-Rips stream from an explicit metric space m_space instead of a Euclidean point cloud. ```matlab >> stream = api.Plex4.createVietorisRipsStream(m_space, max_dimension, max_filtration_value, num_divisions); ``` -------------------------------- ### Compute and print persistence intervals Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Computes persistence intervals for a stream and displays them. The output shows intervals for dimensions 9 and 0, with Betti numbers Betti_0=1 and Betti_9=1. ```matlab >> intervals = persistence.computeIntervals(stream) intervals = Dimension: 9 [0.0, infinity) Dimension: 0 [0.0, infinity) ``` -------------------------------- ### Invoke Jython with JavaPlex on classpath Source: https://github.com/appliedtopology/javaplex/wiki/Interoperability Sets the CLASSPATH environment variable to include javaplex.jar before launching Jython. ```bash CLASSPATH=$CLASSPATH:/path/to/javaplex.jar jython ``` -------------------------------- ### Create Euclidean metric space from point cloud Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.pdf Create a metric space from a point cloud matrix. The i-th row of the input matrix lists the coordinates of the i-th point. ```matlab >> m_space = metric.impl.EuclideanMetricSpace(point_cloud); ``` -------------------------------- ### Build lazy witness stream and compute persistence for range data Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Sets up parameters, creates a maxmin landmark selector, builds a lazy witness stream, computes persistence intervals, and plots barcodes. The output shows R = 0.7759 and num_simplices = 12036. ```matlab >> max_dimension = 3; >> num_landmark_points = 50; >> nu = 1; >> num_divisions = 1000; >> landmark_selector = api.Plex4.createMaxMinSelector(pointsRange, num_landmark_points); >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.7759 # Generally close to 0.75 >> max_filtration_value = R / 3; >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(), landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 12036 # Generally between 10000 and 25000 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'lazyRange'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Compute persistence intervals and plot barcodes Source: https://github.com/appliedtopology/javaplex/blob/master/reports/javaplex_tutorial/javaplex_tutorial.tex Computes persistence intervals using the modular simplicial algorithm with max_dimension and prime 2, then plots barcodes with options for filename, max filtration value, and max dimension. The output file witnessTorus.png is saved to the current directory. ```matlab >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'witnessTorus'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Build lazy witness stream and compute persistence in Matlab Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Computes the max distance from points to landmarks (R), sets max_filtration_value to 2*R, creates a LazyWitnessStream, finalizes it, and computes persistent homology intervals with Z/2Z coefficients. Then plots barcodes and saves to lazySphere.png. ```matlab >> R = landmark_selector.getMaxDistanceFromPointsToLandmarks() R = 0.3841 # Generally close to 0.38 >> max_filtration_value = 2 * R; >> stream = streams.impl.LazyWitnessStream(landmark_selector.getUnderlyingMetricSpace(), landmark_selector, max_dimension, max_filtration_value, nu, num_divisions); >> stream.finalizeStream() >> num_simplices = stream.getSize() num_simplices = 56518 # Generally close to 50000 >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'lazySphere'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ``` -------------------------------- ### Compute persistence intervals and plot Betti barcodes Source: https://github.com/appliedtopology/javaplex/wiki/Tutorial Computes persistence intervals using the modular simplicial algorithm with max dimension 3 and prime 2. Plots barcodes with options for filename 'witnessTorus', max filtration value, and max dimension 2. Saves the plot to witnessTorus.png in the current directory. ```matlab >> persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2); >> intervals = persistence.computeIntervals(stream); >> options.filename = 'witnessTorus'; >> options.max_filtration_value = max_filtration_value; >> options.max_dimension = max_dimension - 1; >> plot_barcodes(intervals, options); ```