Package de.jungblut.clustering

Source Code of de.jungblut.clustering.DBSCANTest

package de.jungblut.clustering;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import de.jungblut.distance.EuclidianDistance;
import de.jungblut.math.DoubleVector;
import de.jungblut.math.dense.DenseDoubleVector;

public class DBSCANTest {

  @Test
  public void testDBSCAN() {
    ArrayList<DoubleVector> input = KMeansClusteringTest.getClusteringInput(10,
        10);
    // add some noise!
    input.add(new DenseDoubleVector(new double[] { 2000, 2000 }));

    EuclidianDistance measure = new EuclidianDistance();

    DBSCAN scan = new DBSCAN();
    ArrayList<DoubleVector>[] cluster = scan.cluster(input, measure, 5, 100);
    // we should just have a single connected cluster with all the points, but
    // the noise
    assertEquals(1, cluster.length);
    assertEquals(input.size() - 1, cluster[0].size());

    // check the noise
    List<DoubleVector> noise = scan.getNoise();
    assertEquals(1, noise.size());
    assertEquals(noise.get(0), input.get(input.size() - 1));
  }

}
TOP

Related Classes of de.jungblut.clustering.DBSCANTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.