Commit 83d61ff1 authored by gonciarz's avatar gonciarz

javaml is not used anymore

parent beb8ab28
......@@ -233,11 +233,6 @@
<artifactId>cmaes</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<version>0.1.7</version>
</dependency>
</dependencies>
<build>
......
9fee97b1b60eac370e349595ae8103ab
\ No newline at end of file
0257c25af0f9cbba9df72392f77079effc48888e
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<version>0.1.7</version>
</project>
718059452e4f135f5a90dbef5e3f2ae9
\ No newline at end of file
3934852f22068e2ea305fe2166b4ed87ab40b3b3
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<versioning>
<release>0.1.7</release>
<versions>
<version>0.1.7</version>
</versions>
<lastUpdated>20160906132602</lastUpdated>
</versioning>
</metadata>
8ba10406828460e0448bf0d8bd3dbabb
\ No newline at end of file
82a41485cdad4e57d239f6550e9732c7c075e1be
\ No newline at end of file
......@@ -22,12 +22,10 @@ import mosaic.core.psf.psf;
import mosaic.utils.ArrayOps;
import mosaic.utils.ArrayOps.MinMax;
import net.imglib2.type.numeric.real.DoubleType;
import net.sf.javaml.clustering.KMeans;
import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.DefaultDataset;
import net.sf.javaml.core.DenseInstance;
import net.sf.javaml.core.Instance;
import net.sf.javaml.tools.DatasetTools;
import weka.clusterers.SimpleKMeans;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
class AnalysePatch {
......@@ -465,44 +463,56 @@ class AnalysePatch {
cin = RSS.betaMLEin;
}
private void estimateIntensityClustering(double[][][] aValues, int aNumOfClasters, boolean aUpdateCout) {
final Dataset data = new DefaultDataset();
final double[] pixel = new double[1];
void estimateIntensityClustering(double[][][] aValues, int aNumOfClasters, boolean aUpdateCout) {
SimpleKMeans kmeans = new SimpleKMeans();
ArrayList<Attribute> attr = new ArrayList<>();
attr.add(new Attribute("pixelValue"));
Instances inst = new Instances("DataPoints", attr, 0);
Set<Double> distinctPixelValues = new HashSet<Double>();
for (int z = 0; z < iSizeOverZ; z++) {
for (int i = 0; i < iSizeOverX; i++) {
for (int j = 0; j < iSizeOverY; j++) {
if (iRegionMask[z][i][j] == 1) {
pixel[0] = aValues[z][i][j];
data.add(new DenseInstance(pixel));
distinctPixelValues.add(pixel[0]);
double value = aValues[z][i][j];
distinctPixelValues.add(value);
final DenseInstance iw = new DenseInstance(1, new double[] {value});
iw.setDataset(inst);
inst.add(iw);
}
}
}
}
logger.debug("Data size = " + data.size() + ", number of distinct values in data set = " + distinctPixelValues.size());
// KMeans is not working correctly if data size of number of distinct values in data size is smaller than requested
// number of clusters.
if (data.size() > aNumOfClasters && distinctPixelValues.size() >= aNumOfClasters) {
logger.debug("Data size = " + inst.size() + ", number of distinct values in data set = " + distinctPixelValues.size());
if (inst.size() >= aNumOfClasters && distinctPixelValues.size() >= aNumOfClasters) {
logger.debug("Running KMeans");
final Dataset[] dataSet = new KMeans(aNumOfClasters, 100).cluster(data);
int numOfClustersFound = dataSet.length;
final double[] levels = new double[numOfClustersFound];
for (int i = 0; i < numOfClustersFound; i++) {
final Instance inst = DatasetTools.average(dataSet[i]);
levels[i] = inst.value(0);
try {
kmeans.setNumClusters(aNumOfClasters);
kmeans.setMaxIterations(100);
kmeans.buildClusterer(inst);
Instances centroids = kmeans.getClusterCentroids();
int numOfClustersFound = kmeans.numberOfClusters();
final double[] levels = new double[numOfClustersFound];
for (int i = 0; i < numOfClustersFound; i++) {
levels[i] = centroids.instance(i).value(0);
}
Arrays.sort(levels);
final int inIndex = Math.min(2, numOfClustersFound - 1);
cin = Math.max(iNormalizedMinObjectIntensity, levels[inIndex]);
final int outFrontIndex = Math.max(inIndex - 1, 0);
cout_front = levels[outFrontIndex];
cout = (aUpdateCout) ? cout_front : levels[0];
logger.debug("Region: " + iInputRegion.iLabel + ", Cluster levels: " + Arrays.toString(levels));
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Something went wrong with clustering...");
}
Arrays.sort(levels);
final int inIndex = Math.min(2, numOfClustersFound - 1);
cin = Math.max(iNormalizedMinObjectIntensity, levels[inIndex]);
final int outFrontIndex = Math.max(inIndex - 1, 0);
cout_front = levels[outFrontIndex];
cout = (aUpdateCout) ? cout_front : levels[0];
logger.debug("Region: " + iInputRegion.iLabel + ", Cluster levels: " + Arrays.toString(levels));
}
else {
logger.debug("Data set too small or with not enough number of distinct values. Setting default values.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment