Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawa, Jakub authored and Kawa, Jakub committed Aug 11, 2017
0 parents commit 664d2f3
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 0 deletions.
Binary file added libs/javaplex-4.2.5.jar
Binary file not shown.
104 changes: 104 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.superzer0.tda</groupId>
<artifactId>tdathesis</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Specification-Title>${project.name} Library</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Class-Path>libs/javaplex-4.2.5.jar</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>com.company.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
<finalName>tdathesis_${project.version}</finalName>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<workDirectory>${project.build.directory}/assembly/work</workDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>

<dependency>
<groupId>edu.stanford.math</groupId>
<artifactId>javaplex</artifactId>
<version>4.2.5</version>
<scope>system</scope>
<systemPath>C:/DEV/TDA.JAVA/javaplex-4.2.5.jar</systemPath>
</dependency>

<!-- https://mvnrepository.com/artifact/org.processing/core -->
<dependency>
<groupId>org.processing</groupId>
<artifactId>core</artifactId>
<version>3.2.3</version>
</dependency>


</dependencies>


</project>
31 changes: 31 additions & 0 deletions src/assembly/bin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>target/libs</directory>
<outputDirectory>libs</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
126 changes: 126 additions & 0 deletions src/main/java/com/github/superzer0/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.github.superzer0;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.math.plex4.api.Plex4;
import edu.stanford.math.plex4.bottleneck.BottleneckDistance;
import edu.stanford.math.plex4.examples.PointCloudExamples;
import edu.stanford.math.plex4.homology.barcodes.BarcodeCollection;
import edu.stanford.math.plex4.homology.barcodes.Interval;
import edu.stanford.math.plex4.homology.barcodes.PersistenceInvariantDescriptor;
import edu.stanford.math.plex4.homology.chain_basis.Simplex;
import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceAlgorithm;
import edu.stanford.math.plex4.io.BarcodeWriter;
import edu.stanford.math.plex4.io.DoubleArrayReaderWriter;
import edu.stanford.math.plex4.metric.impl.EuclideanMetricSpace;
import edu.stanford.math.plex4.metric.landmark.MaxMinLandmarkSelector;
import edu.stanford.math.plex4.streams.impl.VietorisRipsStream;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

public class Main {

private static final String DEFAULT_IMAGE_CAPTION = "Barcodes";
private static final String DEFAULT_HOMOLOGY_FILE_NAME = "persistent_homology_summary.txt";
private static final int DEFAULT_COUNT_LANDMARKS = 200;

public static void main(String[] args) throws IOException {

Path pointsCloudFilePath = Paths.get(args[0].replace("\"", ""));
int maxDimension = Integer.parseInt(args[1]);
int maxFiltrationValue = Integer.parseInt(args[2]);
boolean lazy = Boolean.parseBoolean(args[3]);
Path outputFolder = Paths.get(args[4].replace("\"", ""));

System.out.println("Points Cloud File Path: " + pointsCloudFilePath);
System.out.println("Max dimension: " + maxDimension);
System.out.println("Max Filtration Value: " + maxFiltrationValue);
System.out.println("Landmarks enabled: " + lazy);

ObjectMapper mapper = new ObjectMapper();

try {
double[][] points = mapper.readValue(new File(pointsCloudFilePath.toString()), double[][].class);

VietorisRipsStream<double[]> vietorisRipsStream;
if (lazy) {
int lazyPointsToProcess = getLazyPointCount(points.length);
MaxMinLandmarkSelector<double[]> minMaxSelector = Plex4.createMaxMinSelector(points, lazyPointsToProcess);
vietorisRipsStream = Plex4.createVietorisRipsStream(minMaxSelector, maxDimension, maxFiltrationValue, 100);
System.out.println("Lazy points to process: " + lazyPointsToProcess);
} else {
vietorisRipsStream = Plex4.createVietorisRipsStream(points, maxDimension, maxFiltrationValue, 100);
System.out.println("Points to process: " + points.length);
}


System.out.println("Starting computing intervals... ");
AbstractPersistenceAlgorithm<Simplex> modularSimplicialAlgorithm = Plex4.getModularSimplicialAlgorithm(maxDimension, 2);
BarcodeCollection<Double> computedIntervals = modularSimplicialAlgorithm.computeIntervals(vietorisRipsStream);
System.out.println("Computing intervals done.");

try {
System.out.println("Saving intervals as text with basic info...");
PrintWriter writer = new PrintWriter(Paths.get(outputFolder.toString(), DEFAULT_HOMOLOGY_FILE_NAME).toString(), "UTF-8");
writer.println(computedIntervals.getBettiNumbers());
writer.println(computedIntervals.toString());
writer.close();
} catch (IOException e) {
e.printStackTrace();
}

try {
System.out.println("Creating barcode plot... ");
createBarcodePlot(computedIntervals, maxFiltrationValue, outputFolder.toString());
} catch (IOException e) {
e.printStackTrace();
}

} catch (IOException e) {
e.printStackTrace();
}
}

private static <G> void createBarcodePlot(PersistenceInvariantDescriptor<Interval<Double>, G> collection,
double endPoint, String folderPath) throws IOException {
BarcodeWriter writer = BarcodeWriter.getInstance();

for (int dimension : collection.getDimensions()) {
String imageFilename = DEFAULT_IMAGE_CAPTION + "_" + dimension;
String fullFileName = imageFilename + "." + writer.getExtension();
String path = Paths.get(folderPath, fullFileName).toString();
writer.writeToFile(collection, dimension, endPoint, imageFilename, path);
}
}

private static int getLazyPointCount(int pointsNumber) {
if (pointsNumber > DEFAULT_COUNT_LANDMARKS)
return DEFAULT_COUNT_LANDMARKS;
else return pointsNumber;
}

private static void Example() throws IOException {

double[][] points = PointCloudExamples.getHouseExample();
EuclideanMetricSpace metricSpace = new EuclideanMetricSpace(points);
double[][] randomSpherePoints = PointCloudExamples.getRandomSpherePoints(1, 1);

DoubleArrayReaderWriter writer = DoubleArrayReaderWriter.getInstance();
writer.writeToFile(points, "houseExample.csv");

System.out.println(Arrays.toString(metricSpace.getPoint(0)));
System.out.println(Arrays.toString(metricSpace.getPoint(1)));
System.out.println(metricSpace.distance(metricSpace.getPoint(0), metricSpace.getPoint(1)));
VietorisRipsStream<double[]> vietorisRipsStream = Plex4.createVietorisRipsStream(points, 2, 4, 100);
AbstractPersistenceAlgorithm<Simplex> modularSimplicialAlgorithm = Plex4.getModularSimplicialAlgorithm(2, 2);
BarcodeCollection<Double> computeIntervals = modularSimplicialAlgorithm.computeIntervals(vietorisRipsStream);
System.out.println(BottleneckDistance.computeBottleneckDistance(computeIntervals.getIntervalsAtDimension(1), computeIntervals.getIntervalsAtDimension(0)));
}
}



28 changes: 28 additions & 0 deletions tdathesis.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
<orderEntry type="module-library">
<library name="Maven: edu.stanford.math:javaplex:4.2.5">
<CLASSES>
<root url="jar://$MODULE_DIR$/../TDA.JAVA/javaplex-4.2.5.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: org.processing:core:3.2.3" level="project" />
</component>
</module>

0 comments on commit 664d2f3

Please sign in to comment.