diff --git a/.classpath b/.classpath
index 29836c6..0e623b8 100644
--- a/.classpath
+++ b/.classpath
@@ -1,9 +1,9 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/edu/uc/rphash/RPHash.java b/src/main/java/edu/uc/rphash/RPHash.java
index e62b867..b0ed7be 100644
--- a/src/main/java/edu/uc/rphash/RPHash.java
+++ b/src/main/java/edu/uc/rphash/RPHash.java
@@ -22,11 +22,11 @@
import edu.uc.rphash.decoders.DepthProbingLSH;
import edu.uc.rphash.decoders.Dn;
import edu.uc.rphash.decoders.E8;
-import edu.uc.rphash.decoders.Golay;
+
import edu.uc.rphash.decoders.Leech;
import edu.uc.rphash.decoders.MultiDecoder;
import edu.uc.rphash.decoders.OriginDecoder;
-import edu.uc.rphash.decoders.PsdLSH;
+
import edu.uc.rphash.decoders.Spherical;
import edu.uc.rphash.projections.DBFriendlyProjection;
import edu.uc.rphash.projections.FJLTProjection;
@@ -34,13 +34,13 @@
import edu.uc.rphash.projections.NoProjection;
import edu.uc.rphash.projections.SVDProjection;
import edu.uc.rphash.tests.StatTests;
-import edu.uc.rphash.tests.clusterers.AdaptiveMeanShift;
+
import edu.uc.rphash.tests.clusterers.Agglomerative3;
import edu.uc.rphash.tests.clusterers.DummyClusterer;
import edu.uc.rphash.tests.clusterers.DBScan;
import edu.uc.rphash.tests.clusterers.KMeans2;
import edu.uc.rphash.tests.clusterers.KMeansPlusPlus;
-import edu.uc.rphash.tests.clusterers.LloydIterativeKmeans;
+
import edu.uc.rphash.tests.clusterers.MultiKMPP;
import edu.uc.rphash.tests.clusterers.StreamingKmeans;
import edu.uc.rphash.tests.clusterers.StreamingKmeans2;
@@ -51,17 +51,26 @@
public class RPHash {
static String[] clusteringmethods = { "simple", "streaming", "multiproj",
- "kmeans", "pkmeans","kmeansplusplus", "streamingkmeans", "adaptive","dummy" };
+ "kmeans", "pkmeans","kmeansplusplus", "streamingkmeans", "adaptive","dummy" ,"twrp" , "twrpbisect", "twrpbest", "twrpmergetree", "twrpbest_afterpruning",
+ "twrpbest_cov","twrpbest_meanvariance" };
+
static String[] offlineclusteringmethods = { "singlelink", "completelink",
"averagelink", "kmeans", "adaptivemeanshift", "kmpp", "multikmpp" , "dbscan", "none" };
+
static String[] projectionmethods = { "dbf", "fjlt", "rp", "svd", "noproj" };
+
static String[] ops = { "numprojections", "innerdecodermultiplier",
"numblur", "randomseed", "hashmod", "parallel", "streamduration",
"raw", "decayrate", "dimparameter", "decodertype",
"offlineclusterer", "runs", "normalize", "projection" };
+
static String[] decoders = { "dn", "e8", "golay", "multie8", "leech",
"multileech", "sphere", "levypstable", "cauchypstable",
"gaussianpstable", "adaptive", "origin" };
+
+ static String[] twrp_options = { "cutoff", "randomvector" };
+
+
public static void main(String[] args) throws NumberFormatException,
IOException, InterruptedException {
@@ -95,6 +104,12 @@ public static void main(String[] args) throws NumberFormatException,
System.out.print(s + " ,");
System.out.print("]\n");
+ System.out.print("\t twrp_options" + "\t:[");
+ for (String s : twrp_options)
+ System.out.print(s + " ,");
+ System.out.print("]\n");
+
+
System.exit(0);
}
@@ -114,6 +129,9 @@ public static void main(String[] args) throws NumberFormatException,
matched |= keyword.equals(match);
for (String match : decoders)
matched |= keyword.equals(match);
+ for (String match : twrp_options)
+ matched |= keyword.equals(match);
+
if (!matched)
unmatchedkeywords.add(keyword);
}
@@ -503,6 +521,20 @@ public static List runConfigs(List untaggedArgs,
o.setNormalize(Boolean.parseBoolean(taggedArgs.get("normalize")));
so.setNormalize(Boolean.parseBoolean(taggedArgs.get("normalize")));
}
+
+
+ if (taggedArgs.containsKey("cutoff")) {
+ o.setCutoff(Integer.parseInt(taggedArgs.get("cutoff")));
+ so.setCutoff(Integer.parseInt(taggedArgs.get("cutoff")));
+ }
+
+
+ if (taggedArgs.containsKey("randomvector")) {
+ o.setRandomVector(Boolean.parseBoolean(taggedArgs.get("randomvector")));
+ so.setRandomVector(Boolean.parseBoolean(taggedArgs.get("randomvector")));
+ }
+
+
if (taggedArgs.containsKey("projection")) {
switch (taggedArgs.get("projection")) {
@@ -552,11 +584,7 @@ public static List runConfigs(List untaggedArgs,
so.setDecoderType(new E8(2f));
break;
}
- case "golay": {
- o.setDecoderType(new Golay());
- so.setDecoderType(new Golay());
- break;
- }
+
case "multie8": {
o.setDecoderType(new MultiDecoder(
o.getInnerDecoderMultiplier() * 8, new E8(2f)));
@@ -576,23 +604,9 @@ public static List runConfigs(List untaggedArgs,
.getInnerDecoderMultiplier() * 24, new Leech()));
break;
}
- case "levypstable": {
- o.setDecoderType(new PsdLSH(PsdLSH.LEVY, o.getDimparameter()));
- so.setDecoderType(new PsdLSH(PsdLSH.LEVY, o.getDimparameter()));
- break;
- }
- case "cauchypstable": {
- o.setDecoderType(new PsdLSH(PsdLSH.CAUCHY, o.getDimparameter()));
- so.setDecoderType(new PsdLSH(PsdLSH.CAUCHY, o.getDimparameter()));
- break;
- }
- case "gaussianpstable": {
- o.setDecoderType(new PsdLSH(PsdLSH.GAUSSIAN, o
- .getDimparameter()));
- so.setDecoderType(new PsdLSH(PsdLSH.GAUSSIAN, o
- .getDimparameter()));
- break;
- }
+
+
+
case "sphere": {// pad to ~32 bits
// int ctsofsphere =
// (int)(Math.log(o.getDimparameter()*2)/Math.log(2.0)) /2;
@@ -659,13 +673,7 @@ public static List runConfigs(List untaggedArgs,
o.setOfflineClusterer(new KMeansPlusPlus());
so.setOfflineClusterer(new KMeansPlusPlus());
break;
- case "adaptivemeanshift": {
-
- o.setOfflineClusterer(new AdaptiveMeanShift());
- so.setOfflineClusterer(new AdaptiveMeanShift());
-
- break;
- }
+
case "kmpp": {
o.setOfflineClusterer(new KMeansPlusPlus());
@@ -727,11 +735,7 @@ public static List runConfigs(List untaggedArgs,
runitems.add(new KMeans2(k, o.getRawData()));
break;
}
- case "pkmeans":
- runitems.add(new LloydIterativeKmeans(k, o.getRawData(), o
- .getNumProjections()));
- break;
-
+
case "kmeansplusplus":
runitems.add(new KMeansPlusPlus(o.getRawData(), k));
break;
@@ -743,14 +747,50 @@ public static List runConfigs(List untaggedArgs,
runitems.add(new StreamingKmeans2(o));
break;
}
- case "adaptivemeanshift": {
- runitems.add(new AdaptiveMeanShift());
- break;
- }
+
case "adaptive": {
runitems.add(new RPHashAdaptive2Pass(o));
break;
}
+
+ case "twrp": {
+ runitems.add(new TWRPv2(o));
+ break;
+ }
+
+ case "twrpmergetree": {
+ runitems.add(new TWRPv3(o));
+ break;
+ }
+
+ case "twrpbisect": {
+ runitems.add(new TWRPv4(o));
+ break;
+ }
+
+ case "twrpbest": {
+ runitems.add(new TWRPv5_WCSS(o));
+ break;
+ }
+
+ case "twrpbest_afterpruning": {
+ runitems.add(new TWRPv6_WCSS2(o));
+ break;
+ }
+
+ case "twrpbest_cov": {
+ runitems.add(new TWRPv6_COV(o));
+ break;
+ }
+
+ case "twrpbest_meanvariance": {
+ runitems.add(new TWRPv6_meanVariance(o));
+ break;
+ }
+
+
+
+
case "dummy": {
runitems.add(new DummyClusterer(so));
break;
diff --git a/src/main/java/edu/uc/rphash/RPHashAdaptive2Pass.java b/src/main/java/edu/uc/rphash/RPHashAdaptive2Pass.java
index 013ea27..927bf7f 100644
--- a/src/main/java/edu/uc/rphash/RPHashAdaptive2Pass.java
+++ b/src/main/java/edu/uc/rphash/RPHashAdaptive2Pass.java
@@ -1,8 +1,10 @@
package edu.uc.rphash;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@@ -16,11 +18,12 @@
import edu.uc.rphash.tests.StatTests;
import edu.uc.rphash.tests.clusterers.Agglomerative3;
import edu.uc.rphash.tests.generators.GenerateData;
+import edu.uc.rphash.util.VectorUtil;
public class RPHashAdaptive2Pass implements Clusterer, Runnable {
- boolean znorm = true;
+ boolean znorm = false;
private int counter;
@@ -63,17 +66,21 @@ float[] medoid(List X) {
//float[] rngvec; the range vector is moot if incoming data has been normalized
//post normalization it should all be zero centered, with variance 1
-
/*
* super simple hash algorithm, reminiscient of pstable lsh
*/
+ // xt is the projected vector and x is the original vector , rngvec is the randomly generated vector of projected dim.
+
public long hashvec(float[] xt, float[] x,
HashMap> IDAndCent, HashMap> IDAndLabel,int ct) {
- long s = 1;//fixes leading 0's bug
+ long s = 1; //fixes leading 0's bug
for (int i = 0; i < xt.length; i++) {
- s <<= 1;
+// s <<= 1;
+ s = s << 1 ; // left shift the bits of s by 1.
if (xt[i] > rngvec[i])
- s += 1;
+// s += 1;
+ s= s+1;
+
if (IDAndCent.containsKey(s)) {
IDAndLabel.get(s).add(ct);
IDAndCent.get(s).add(x);
@@ -143,16 +150,17 @@ public List> findDensityModes() {
projector.init();
int ct = 0;
- if(znorm == true){
- float[] variance = StatTests.varianceCol(so.getRawData());
- float[] mean = StatTests.meanCols(so.getRawData());
- // #process data by adding to the counter
- for (float[] x : so.getRawData())
- {
- addtocounter(x, projector, IDAndCent,IDAndID,ct++,mean,variance);
- }
- }
- else
+// if(znorm == true){
+// float[] variance = StatTests.varianceCol(so.getRawData());
+// float[] mean = StatTests.meanCols(so.getRawData());
+// // #process data by adding to the counter
+// for (float[] x : so.getRawData())
+// {
+// addtocounter(x, projector, IDAndCent,IDAndID,ct++,mean,variance);
+// }
+// }
+//
+// else
{
for (float[] x : so.getRawData())
@@ -161,6 +169,24 @@ public List> findDensityModes() {
}
}
+
+// for (Long name: IDAndCent.keySet()){
+//
+// String key =name.toString();
+// // String value = IDAndCent.get(name).toString() ;
+// // String value1 = Arrays.toString(value.toString());
+// System.out.println(key ) ;//+ " " + value);
+//}
+
+ System.out.println("NumberOfMicroClustersBeforePruning = "+ IDAndCent.size());
+// for (Long name: IDAndID.keySet()){
+// String key =name.toString();
+// String value = IDAndID.get(name).toString();
+// System.out.println(key + " " + value);
+//
+//
+//}
+
// next we want to prune the tree by parent count comparison
// follows breadthfirst search
HashMap denseSetOfIDandCount = new HashMap();
@@ -197,9 +223,11 @@ public List> findDensityModes() {
List sortedIDList= new ArrayList<>();
// sort and limit the list
- stream.sorted(Entry. comparingByValue().reversed()).limit(so.getk()*4)
+ stream.sorted(Entry. comparingByValue().reversed()).limit(so.getk()*6)
.forEachOrdered(x -> sortedIDList.add(x.getKey()));
+ System.out.println("NumberOfMicroClustersAfterPruning = "+ sortedIDList.size());
+
// compute centroids
HashMap> estcents = new HashMap<>();
@@ -207,12 +235,16 @@ public List> findDensityModes() {
{
estcents.put(sortedIDList.get(i), IDAndCent.get(sortedIDList.get(i)));
}
+
+
// System.out.println();
// for (int i =0; i(estcents.values());
@@ -229,12 +261,14 @@ public void run() {
Listcentroids = new ArrayList<>();
List weights =new ArrayList<>();
- int k = clustermembers.size()>200+so.getk()?200+so.getk():clustermembers.size();
+ // int k = clustermembers.size()>200+so.getk()?200+so.getk():clustermembers.size();
+ int k = clustermembers.size();
for(int i=0;i centroids = null;
- private RPHashObject so;
- int threads = 4;
-
- public RPHashAdaptive2PassParallel(RPHashObject so) {
- this.threads = 4;
- this.so = so;
- }
-
- public RPHashAdaptive2PassParallel(List data, int k, int processors) {
- this.threads = processors;
- so = new SimpleArrayReader(data, k);
- }
-
- public List getCentroids(RPHashObject so) {
- this.so = so;
- return getCentroids();
- }
-
- @Override
- public List getCentroids() {
- if (centroids == null)
- run();
- return centroids;
- }
-
- /*
- * X - set of vectors compute the medoid of a vector set
- */
- float[] medoid(List X) {
- float[] ret = X.get(0);
- for (int i = 1; i < X.size(); i++) {
- for (int j = 0; j < ret.length; j++) {
- ret[j] += X.get(i)[j];
- }
- }
- for (int j = 0; j < ret.length; j++) {
- ret[j] = ret[j] / ((float) X.size());
- }
- return ret;
- }
-
- // float[] rngvec; the range vector is moot if incoming data has been
- // normalized
- // post normalization it should all be zero centered, with variance 1
-
- /*
- * super simple hash algorithm, reminiscient of pstable lsh
- */
- public long hashvec(float[] xt, float[] x,
- Map> IDAndCent,
- Map> IDAndLabel, int ct) {
- long s = 1;// fixes leading 0's bug
- for (int i = 0; i < xt.length; i++) {
- s <<= 1;
- if (xt[i] > rngvec[i])
- s += 1;
- if (IDAndCent.containsKey(s)) {
- if (IDAndLabel.get(s) != null)
- IDAndLabel.get(s).add(ct);
- if (IDAndCent.get(s) != null)
- IDAndCent.get(s).add(x);
- } else {
- ArrayList xlist = new ArrayList<>();
- xlist.add(x);
- IDAndCent.put(s, xlist);
- ArrayList idlist = new ArrayList<>();
- idlist.add(ct);
- IDAndLabel.put(s, idlist);
- }
- }
- return s;
- }
-
- /*
- * x - input vector IDAndCount - ID->count map IDAndCent - ID->centroid
- * vector map
- *
- * hash the projected vector x and update the hash to centroid and counts
- * maps
- */
- void addtocounter(float[] x, Projector p,
- Map> IDAndCent,
- Map> IDandID, int ct) {
- float[] xt = p.project(x);
-
- hashvec(xt, x, IDAndCent, IDandID, ct);
- }
-
- /*
- * X - data set k - canonical k in k-means l - clustering sub-space Compute
- * density mode via iterative deepening hash counting
- */
- public Collection> findDensityModes()
- throws InterruptedException, ExecutionException {
-
- // #create projector matrixs
- Projector projector = so.getProjectionType();
- projector.setOrigDim(so.getdim());
- projector.setProjectedDim(so.getDimparameter());
- projector.setRandomSeed(so.getRandomSeed());
- projector.init();
-
- // int ct = 1;
-
- List dat = so.getRawData();
-
- //this counter gets shared
- AtomicInteger ct = new AtomicInteger(0);
-
- ForkJoinPool executor = new ForkJoinPool(this.threads);
-
- int chunksize = dat.size() / this.threads;
-
- //This is the array of essentially thread objets that process in parallel
- ArrayList>>> gather = new ArrayList<>(this.threads);
-
- for (int i = 0; i < this.threads; i++) {
-
- int chunk = chunksize* i;
- gather.add(executor.submit(new Callable