Skip to content
Permalink
Browse files

Fixed some bugs.

  • Loading branch information
Andrew Lawson Andrew Lawson
Andrew Lawson authored and Andrew Lawson committed Nov 30, 2014
1 parent 28418f2 commit 26a52593f61b9c9b331f8dfd68f153abfa372661
Showing with 16 additions and 15 deletions.
  1. +16 −15 geometric_separators.pde
@@ -120,6 +120,7 @@ void mousePressed() {

// Get geometric median
PVector getGeometricMedian(ArrayList<PVector> input) {
System.out.println("Geometric median...");
if (input.size() == 0) {
return null;
}
@@ -135,24 +136,25 @@ PVector getGeometricMedian(ArrayList<PVector> input) {
}

// Sample input points into sets of 4
ArrayList<Set<PVector>> samplePoints(ArrayList<PVector> input) {
ArrayList<Set> setList = new ArrayList<Set<PVector>>();
Set<PVector> pointSet = new Set<PVector>();
ArrayList<HashSet<PVector>> samplePoints(ArrayList<PVector> input) {
ArrayList<HashSet<PVector>> setList = new ArrayList<HashSet<PVector>>();
HashSet<PVector> pointSet = new HashSet<PVector>();
// While there are still points, split into sets
while (input.size() > 0) {
int rnd = new Random().nextInt();
int index = (rnd * (input.size()));
while (input.size() > 1) {
System.out.println("Sampling...");
double rnd = new Random().nextDouble();
int index = (int)(rnd * 10) % input.size();
// Add to set
pointSet.add(input.get(index));
// Create new set on max size
if (pointSet.size() == 4) {
setList.add(pointSet);
pointSet = new Set<PVector>();
pointSet = new HashSet<PVector>();
}
}
// Add most recent unempty set to list
if (pointSet.size() > 0) {
setList.add(pointSet)
setList.add(pointSet);
}
return setList;
}
@@ -161,23 +163,22 @@ ArrayList<Set<PVector>> samplePoints(ArrayList<PVector> input) {
PVector approxCenterpoint(ArrayList<PVector> input) {
if (input.size() == 0) {
System.out.println("You don't have any input points!");
return null;
}
else {
// Algorithm
// Repeat 1 - 3 until one point remains and return that point
while (input.size > 1) {
while (input.size() > 1) {
// 1. Sample points into groups of 4
ArrayList<Set<PVector>> setList = samplePoints(input);
ArrayList<HashSet<PVector>> setList = samplePoints(input);
// 2. Compute radon point of each group (geometric median)
ArrayList<PVector> radonList = new ArrayList<PVector>();
for (Set<PVector> set : setList) {
for (HashSet<PVector> set : setList) {
PVector radonPoint = getGeometricMedian(input);
else {
radonList.add(radonPoint);
}
radonList.add(radonPoint);
// 3. Set input to be new radon points
input = radonList;
}
input = radonList;
}
return input.get(0);
}

0 comments on commit 26a5259

Please sign in to comment.
You can’t perform that action at this time.