private ByteKMeans newByteKMeans(int K) { KMeansConfiguration<ByteNearestNeighbours, byte[]> newConf = conf.clone(); newConf.setK(K); return new ByteKMeans(newConf); } }
/** * Convenience method to quickly create an exact {@link ByteKMeans}. All * parameters other than the number of clusters are set * at their defaults, but can be manipulated through the configuration * returned by {@link #getConfiguration()}. * <p> * Euclidean distance is used to measure the distance between points. * * @param K * the number of clusters * @return a {@link ByteKMeans} instance configured for exact k-means */ public static ByteKMeans createExact(int K) { final KMeansConfiguration<ByteNearestNeighbours, byte[]> conf = new KMeansConfiguration<ByteNearestNeighbours, byte[]>(K, new ByteNearestNeighboursExact.Factory()); return new ByteKMeans(conf); }
/** * Convenience method to quickly create an approximate {@link ByteKMeans} * using an ensemble of KD-Trees to perform nearest-neighbour lookup. All * parameters other than the number of clusters are set * at their defaults, but can be manipulated through the configuration * returned by {@link #getConfiguration()}. * <p> * Euclidean distance is used to measure the distance between points. * * @param K * the number of clusters * @return a {@link ByteKMeans} instance configured for approximate k-means * using an ensemble of KD-Trees */ public static ByteKMeans createKDTreeEnsemble(int K) { final KMeansConfiguration<ByteNearestNeighbours, byte[]> conf = new KMeansConfiguration<ByteNearestNeighbours, byte[]>(K, new ByteNearestNeighboursKDTree.Factory()); return new ByteKMeans(conf); }
/** * Convenience method to quickly create an exact {@link ByteKMeans}. All * parameters other than the number of clusters and number * of iterations are set at their defaults, but can be manipulated through * the configuration returned by {@link #getConfiguration()}. * <p> * Euclidean distance is used to measure the distance between points. * * @param K * the number of clusters * @param niters * maximum number of iterations * @return a {@link ByteKMeans} instance configured for exact k-means */ public static ByteKMeans createExact(int K, int niters) { final KMeansConfiguration<ByteNearestNeighbours, byte[]> conf = new KMeansConfiguration<ByteNearestNeighbours, byte[]>(K, new ByteNearestNeighboursExact.Factory(), niters); return new ByteKMeans(conf); }
@Override public SpatialClusters<?> create(List<SampleBatch> batches) throws Exception { System.err.println("Constructing a FASTKMEANS cluster"); SpatialClusterer<?, ?> c = null; System.err.println("Constructing a fastkmeans worker: "); if (this.precision == Precision.BYTE) { final SampleBatchByteDataSource ds = new SampleBatchByteDataSource(batches); ds.setSeed(seed); c = new ByteKMeans(confByte(ds.numDimensions())); ((ByteKMeans) c).seed(seed); clusterInitOp.setClusterInit((ByteKMeans) c); return ((ByteKMeans) c).cluster(ds); } else { final SampleBatchIntDataSource ds = new SampleBatchIntDataSource(batches); ds.setSeed(seed); c = new IntKMeans(confInt(ds.numDimensions())); ((IntKMeans) c).seed(seed); return ((IntKMeans) c).cluster(ds); } }
@Override public SpatialClusters<?> create(byte[][] data) throws Exception { SpatialClusterer<?, ?> c = null; if (this.precision == Precision.BYTE) { c = new ByteKMeans(confByte(data[0].length)); ((ByteKMeans) c).seed(seed); if (clusterInitOp == null) clusterInitOp = clusterInit.getOptions(); clusterInitOp.setClusterInit((ByteKMeans) c); return ((ByteKMeans) c).cluster(data); } else { c = new IntKMeans(confInt(data[0].length)); ((IntKMeans) c).seed(seed); return ((IntKMeans) c).cluster(ByteArrayConverter.byteToInt(data)); } }