org.openimaj.ml.clustering.random
Class RandomDoubleCluster

java.lang.Object
  extended by org.openimaj.ml.clustering.random.RandomDoubleCluster
All Implemented Interfaces:
Readable, ReadableASCII, ReadableBinary, ReadWriteable, Writeable, WriteableASCII, WriteableBinary, Cluster<RandomDoubleCluster,double[]>, ReadWriteableCluster
Direct Known Subclasses:
RandomSetDoubleCluster

public class RandomDoubleCluster
extends Object
implements Cluster<RandomDoubleCluster,double[]>

A simple (yet apparently quite effective) clustering technique trained used random data points. A configurable K number of data points are selected from the training data.

Author:
Jonathon Hare , Sina Samangooei

Field Summary
protected  double[][] clusterCenters
           
protected  int K
           
protected  DoubleNearestNeighbours nn
           
protected  Random random
           
protected  long seed
           
 
Fields inherited from interface org.openimaj.ml.clustering.ReadWriteableCluster
CLUSTER_HEADER
 
Constructor Summary
RandomDoubleCluster()
          Convinence function for reading saved centroids.
RandomDoubleCluster(int M)
          Creates a new random byte cluster used to create centroids with data containing M elements.
RandomDoubleCluster(int M, int K)
          Creates a new random byte cluster used to create K centroids with data containing M elements.
 
Method Summary
 String asciiHeader()
          Header for ascii input.
 byte[] binaryHeader()
          Header for binary input.
 double[][] getClusters()
          Utility function useful for testing.
 int getNDims()
          Get data dimensionality
 int getNumberClusters()
          Get the number of centers K
 void optimize(boolean exact)
          Prepare the cluster for pushing
 int push_one(double[] data)
          Project one datum to clusters
 int[] push_one(double[] data, int numNeighbours)
          Project one datum to clusters
 int[] push(double[][] data)
          Project data to clusters.
 int[][] push(double[][] data, int numNeighbours)
          Project data to clusters.
 void readASCII(Scanner br)
          Read internal state from in.
 void readBinary(DataInput in)
          Read internal state from in.
 void setSeed(long seed)
           
 String toString()
           
 int train(DataSource<double[]> data)
          Train clusters with a data source, can be more efficient
 int train(double[][] data)
          Train clusters
 void writeASCII(PrintWriter writer)
          Write the content of this as ascii to out.
 void writeBinary(DataOutput out)
          Write the content of this as binary to out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

K

protected int K

random

protected Random random

clusterCenters

protected double[][] clusterCenters

nn

protected DoubleNearestNeighbours nn

seed

protected long seed
Constructor Detail

RandomDoubleCluster

public RandomDoubleCluster(int M,
                           int K)
Creates a new random byte cluster used to create K centroids with data containing M elements.

Parameters:
M - number of elements in each data vector
K - number of centroids to be created

RandomDoubleCluster

public RandomDoubleCluster(int M)
Creates a new random byte cluster used to create centroids with data containing M elements. The number of clusters will be equal to the number of data points provided in training.

Parameters:
M -

RandomDoubleCluster

public RandomDoubleCluster()
Convinence function for reading saved centroids.

Method Detail

setSeed

public void setSeed(long seed)
Parameters:
seed - the seed for the Random object used to select random data points.

getNDims

public int getNDims()
Description copied from interface: Cluster
Get data dimensionality

Specified by:
getNDims in interface Cluster<RandomDoubleCluster,double[]>
Returns:
data dimensionality.

train

public int train(double[][] data)
Description copied from interface: Cluster
Train clusters

Specified by:
train in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - data.
Returns:
-1 if an overflow may have occurred.

train

public int train(DataSource<double[]> data)
Description copied from interface: Cluster
Train clusters with a data source, can be more efficient

Specified by:
train in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - data.
Returns:
-1 if an overflow may have occurred.

getNumberClusters

public int getNumberClusters()
Description copied from interface: Cluster
Get the number of centers K

Specified by:
getNumberClusters in interface Cluster<RandomDoubleCluster,double[]>
Returns:
number of centers K.

optimize

public void optimize(boolean exact)
Description copied from interface: Cluster
Prepare the cluster for pushing

Specified by:
optimize in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
exact - TODO

push

public int[] push(double[][] data)
Description copied from interface: Cluster
Project data to clusters.

Specified by:
push in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - data.
Returns:
The cluster indecies which the data was pushed to

push_one

public int push_one(double[] data)
Description copied from interface: Cluster
Project one datum to clusters

Specified by:
push_one in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - datum to project.
Returns:
the cluster index.

push

public int[][] push(double[][] data,
                    int numNeighbours)
Description copied from interface: Cluster
Project data to clusters.

Specified by:
push in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - data.
numNeighbours - number of neighboring clusters to return also. When set to 1 this is equivalent to Cluster#push(DATATYPE[])
Returns:
The centers and neighbours for the data

push_one

public int[] push_one(double[] data,
                      int numNeighbours)
Description copied from interface: Cluster
Project one datum to clusters

Specified by:
push_one in interface Cluster<RandomDoubleCluster,double[]>
Parameters:
data - datum to project.
numNeighbours - number of neighbouring clusters to return also. When set to 1 this is equivalent to Cluster.push_one(Object)
Returns:
the cluster index and the index of neighbours.

getClusters

public double[][] getClusters()
Description copied from interface: Cluster
Utility function useful for testing. The cluster must return something it considers to be it's cluster centroids. Different types of cluster will clearly return different data types here. This might (and often will be) null given that it often might not make any sense. It is a sign of a good cluster that can produce a set of centroids for itself.

Specified by:
getClusters in interface Cluster<RandomDoubleCluster,double[]>
Returns:
The cluster's centroids.

toString

public String toString()
Overrides:
toString in class Object

asciiHeader

public String asciiHeader()
Description copied from interface: ReadableASCII
Header for ascii input. Will be automatically read by IOUtils when using readASCII().

Specified by:
asciiHeader in interface ReadableASCII
Specified by:
asciiHeader in interface WriteableASCII
Returns:
header

binaryHeader

public byte[] binaryHeader()
Description copied from interface: ReadableBinary
Header for binary input. Will be automatically read by IOUtils when using readBinary().

Specified by:
binaryHeader in interface ReadableBinary
Specified by:
binaryHeader in interface WriteableBinary
Returns:
header

readASCII

public void readASCII(Scanner br)
               throws IOException
Description copied from interface: ReadableASCII
Read internal state from in.

Specified by:
readASCII in interface ReadableASCII
Parameters:
br - source to read from.
Throws:
IOException - an error reading input

readBinary

public void readBinary(DataInput in)
                throws IOException
Description copied from interface: ReadableBinary
Read internal state from in.

Specified by:
readBinary in interface ReadableBinary
Parameters:
in - source to read from.
Throws:
IOException - an error reading input

writeASCII

public void writeASCII(PrintWriter writer)
                throws IOException
Description copied from interface: WriteableASCII
Write the content of this as ascii to out.

Specified by:
writeASCII in interface WriteableASCII
Parameters:
writer - sink to write to
Throws:
IOException - an error writing to out

writeBinary

public void writeBinary(DataOutput out)
                 throws IOException
Description copied from interface: WriteableBinary
Write the content of this as binary to out.

Specified by:
writeBinary in interface WriteableBinary
Parameters:
out - sink to write to
Throws:
IOException - an error writing to out


Copyright © 2011 The University of Southampton. All Rights Reserved.