Skip to content

Commit

Permalink
Replicating and fixing 2nd bug reported in issue #68
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardRaff committed Nov 12, 2017
1 parent 0ef1558 commit 9234156
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
26 changes: 11 additions & 15 deletions JSAT/src/jsat/clustering/kmeans/NaiveKMeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.logging.Level;
import java.util.logging.Logger;
import jsat.DataSet;
Expand All @@ -23,8 +22,8 @@
import jsat.utils.FakeExecutor;
import jsat.utils.SystemInfo;
import jsat.utils.concurrent.AtomicDoubleArray;
import jsat.utils.concurrent.ParallelUtils;
import jsat.utils.random.RandomUtil;
import jsat.utils.random.XORWOW;

/**
* An implementation of Lloyd's K-Means clustering algorithm using the
Expand All @@ -40,13 +39,12 @@
public class NaiveKMeans extends KMeans
{

private static final long serialVersionUID = 6164910874898843069L;

private static final long serialVersionUID = 6164910874898843069L;

/**
* Creates a new naive k-Means cluster using
* {@link SeedSelection#KPP k-means++} for the
* seed selection and the {@link EuclideanDistance}
/**
* Creates a new naive k-Means cluster using
* {@link SeedSelection#KPP k-means++} for the seed selection and the
* {@link EuclideanDistance}
*/
public NaiveKMeans()
{
Expand Down Expand Up @@ -161,17 +159,17 @@ protected Vec[] initialValue()
}
};

final int N = dataSet.getSampleSize();
Arrays.fill(assignment, -1);
do
{
changes.set(0);
int extra = dataSet.getSampleSize() % SystemInfo.LogicalCores;
int start = 0;
final CountDownLatch latch = new CountDownLatch(SystemInfo.LogicalCores);
while(start < dataSet.getSampleSize())

for(int id = 0; id < SystemInfo.LogicalCores; id++)
{
final int s = start;
final int end = start + blockSize + (extra-- > 0 ? 1 : 0);
final int s = ParallelUtils.getStartBlock(N, id);
final int end = ParallelUtils.getEndBlock(N, id);
threadpool.submit(new Runnable()
{
@Override
Expand Down Expand Up @@ -220,8 +218,6 @@ public void run()
latch.countDown();
}
});

start = end;
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void tearDownClass() throws Exception
public void setUp()
{
DistanceMetric dm = new EuclideanDistance();
dgc = new DivisiveGlobalClusterer(new HamerlyKMeans(), new DaviesBouldinIndex(dm));
dgc = new DivisiveGlobalClusterer(new NaiveKMeans(), new DaviesBouldinIndex(dm));
}

@After
Expand Down

0 comments on commit 9234156

Please sign in to comment.