-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to patterns + entropy tests
- Loading branch information
Kawa, Jakub
authored and
Kawa, Jakub
committed
Aug 22, 2017
1 parent
ea1f9f6
commit 2dc3b03
Showing
13 changed files
with
317 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.superzer0; | ||
|
||
import edu.stanford.math.plex4.homology.barcodes.Interval; | ||
|
||
import java.util.List; | ||
|
||
public class BarcodesEntropy { | ||
|
||
public static double computeDiagramEntropy(int maxFiltration, List<Interval<Double>> intervals) { | ||
|
||
double entropy = 0; | ||
double L = 0; | ||
for (Interval<Double> interval : intervals) { | ||
Double l = getLValueFromInterval(maxFiltration, interval); | ||
L += l; | ||
} | ||
|
||
for (Interval<Double> interval : intervals) { | ||
Double l = getLValueFromInterval(maxFiltration, interval); | ||
if (l == 0d) | ||
continue; | ||
|
||
double p = l / L; | ||
entropy += p * Math.log(p); | ||
} | ||
|
||
return entropy * -1; | ||
} | ||
|
||
private static Double getLValueFromInterval(double maxFiltration, Interval<Double> interval) { | ||
if (interval == null) | ||
return 0d; | ||
|
||
Double rightIndex; | ||
Double leftIndex; | ||
if (interval.isRightInfinite()) { | ||
rightIndex = maxFiltration; | ||
} else { | ||
rightIndex = interval.getEnd(); | ||
} | ||
|
||
if (interval.isLeftInfinite()) { | ||
leftIndex = 0d; | ||
} else { | ||
leftIndex = interval.getStart(); | ||
} | ||
|
||
return rightIndex - leftIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/github/superzer0/services/IIntervalsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.superzer0.services; | ||
|
||
import edu.stanford.math.plex4.homology.barcodes.BarcodeCollection; | ||
|
||
public interface IIntervalsAction { | ||
void run(ProcessingInputParams inputParams, BarcodeCollection<Double> computedIntervals); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/github/superzer0/services/IntervalsActionsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.superzer0.services; | ||
|
||
import com.github.superzer0.services.intervalsActions.SaveIntervalsAsText; | ||
import com.github.superzer0.services.intervalsActions.SaveIntervalsDiagrams; | ||
import com.github.superzer0.services.intervalsActions.SaveIntervalsEntropy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class IntervalsActionsFactory { | ||
|
||
public List<IIntervalsAction> getIntervalsActions() { | ||
List<IIntervalsAction> actions = new ArrayList<>(); | ||
actions.add(new SaveIntervalsAsText()); | ||
actions.add(new SaveIntervalsDiagrams()); | ||
actions.add(new SaveIntervalsEntropy()); | ||
return actions; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/superzer0/services/IoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.superzer0.services; | ||
|
||
import com.esotericsoftware.minlog.Log; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class IoService { | ||
|
||
public double[][] readPointsCloud(ProcessingInputParams processingInputParams) throws IOException { | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
return mapper.readValue( | ||
new File(processingInputParams.getPointsCloudFilePath().toString()), double[][].class); | ||
} | ||
|
||
public ProcessingInputParams getInputParams(String[] args) { | ||
if (args.length < 5) { | ||
Log.error("Not enough params"); | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
|
||
ProcessingInputParams inputParams = new ProcessingInputParams(); | ||
inputParams.setPointsCloudFilePath(args[0]); | ||
inputParams.setMaxDimension(args[1]); | ||
inputParams.setMaxFiltrationValue(args[2]); | ||
inputParams.setUseLandmarks(args[3]); | ||
inputParams.setMaxLandmarks(args[4]); | ||
inputParams.setOutputFolder(args[5]); | ||
|
||
Log.info("Input Params: " + inputParams.toString()); | ||
|
||
return inputParams; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.