* extractMoments
* =============================================================================
*/
- public double[]
- extractMoments (double []data, int num_elts, int num_moments)
+ public float[]
+ extractMoments (float []data, int num_elts, int num_moments)
{
- double[] moments = new double[num_moments];
+ float[] moments = new float[num_moments];
for (int i = 0; i < num_elts; i++) {
moments[0] += data[i];
* =============================================================================
*/
public void
- zscoreTransform (double[][] data, /* in & out: [numObjects][numAttributes] */
+ zscoreTransform (float[][] data, /* in & out: [numObjects][numAttributes] */
int numObjects,
int numAttributes)
{
- double[] moments;
- double[] single_variable = new double[numObjects];
+ float[] moments;
+ float[] single_variable = new float[numObjects];
for (int i = 0; i < numAttributes; i++) {
for (int j = 0; j < numObjects; j++) {
single_variable[j] = data[j][i];
}
moments = extractMoments(single_variable, numObjects, 2);
- moments[1] = Math.sqrt((double)moments[1]);
+ moments[1] = (float) Math.sqrt((double)moments[1]);
for (int j = 0; j < numObjects; j++) {
data[j][i] = (data[j][i]-moments[0])/moments[1];
}
int nthreads, /* in: number of threads*/
int numObjects, /* number of input objects */
int numAttributes, /* size of attribute of each object */
- double[][] attributes, /* [numObjects][numAttributes] */
+ float[][] attributes, /* [numObjects][numAttributes] */
KMeans kms, /* KMeans class hold the inputs and outputs */
GlobalArgs args /* Global thread arguments */
)
int itime;
int nclusters;
- double[][] tmp_cluster_centres = null;
+ float[][] tmp_cluster_centres = null;
int[] membership = new int[numObjects];
Random randomPtr = new Random();
/* Find the cluster center id with min distance to pt */
for (i = 0; i < npts; i++) {
- double dist;
- dist = common_euclidDist2(pt, pts[i], nfeatures); /* no need square root */
+ float dist = common_euclidDist2(pt, pts[i], nfeatures); /* no need square root */
if ((dist / max_dist) < limit) {
max_dist = dist;
index = i;
/**
* List of attributes
**/
- public double[][] feature;
+ public float[][] feature;
/**
* Number of attributes per Object
/**
*
**/
- public double[][] clusters;
+ public float[][] clusters;
/**
/**
* New centers of the clusters [nclusters][nfeatures]
**/
- public double[][] new_centers;
+ public float[][] new_centers;
/**
*
**/
public long global_i;
- public double global_delta;
+ public float global_delta;
}
/**
* threshold until which kmeans cluster continues
**/
- double threshold;
+ float threshold;
/**
* thread id
/**
* Output: Cluster centers
**/
- double[][] cluster_centres;
+ float[][] cluster_centres;
public KMeans() {
max_nclusters = 13;
System.exit(0);
}
- double[][] buf;
- double[][] attributes;
+ float[][] buf;
+ float[][] attributes;
int numAttributes = 0;
int numObjects = 0;
System.out.println("numObjects= " + numObjects + " numAttributes= " + numAttributes);
/* Allocate new shared objects and read attributes of all objects */
- buf = new double[numObjects][numAttributes];
- attributes = new double[numObjects][numAttributes];
+ buf = new float[numObjects][numAttributes];
+ attributes = new float[numObjects][numAttributes];
KMeans.readFromFile(inputFile, kms.filename, buf, MAX_LINE_LENGTH);
System.out.println("Finished Reading from file ......");
* readFromFile()
* Read attributes from the input file into an array
**/
- public static void readFromFile(FileInputStream inputFile, String filename, double[][] buf, int MAX_LINE_LENGTH) {
+ public static void readFromFile(FileInputStream inputFile, String filename, float[][] buf, int MAX_LINE_LENGTH) {
inputFile = new FileInputStream(filename);
int j;
int i = 0;
}
/**
- * Convert a string into double
+ * Convert a string into float
**/
- public static double ByteToFloat (byte[] str, int offset, int length) {
- double left=0.0d;
- double right=0.0d;
+ public static float ByteToFloat (byte[] str, int offset, int length) {
+ float left=0.0d;
+ float right=0.0d;
int i;
for(i=0;i<length;i++) {
if (str[i+offset]=='.')
left=left*10+(str[i+offset]-'0');
}
i++; //skip past decimal point
- double multiplier=0.1d;
+ float multiplier=0.1d;
for(;i<length;i++) {
right+=multiplier*(str[i+offset]-'0');
multiplier*=0.1d;
*/
public static void work(int myId, GlobalArgs args) {
int CHUNK=3;
- double[][] feature = args.feature;
+ float[][] feature = args.feature;
int nfeatures = args.nfeatures;
int npoints = args.npoints;
int nclusters = args.nclusters;
int[] membership = args.membership;
- double[][] clusters = args.clusters;
+ float[][] clusters = args.clusters;
intwrapper[] new_centers_len = args.new_centers_len;
- double[][] new_centers = args.new_centers;
- double delta = 0.0;
+ float[][] new_centers = args.new_centers;
+ float delta = 0.0;
int index, start, stop;
start = myId * CHUNK;
* normal_exec
* =============================================================================
*/
- public double[][] normal_exec (
+ public float[][] normal_exec (
int nthreads,
- double[][] feature, /* in: [npoints][nfeatures] */
+ float[][] feature, /* in: [npoints][nfeatures] */
int nfeatures,
int npoints,
int nclusters,
- double threshold,
+ float threshold,
int[] membership,
Random randomPtr, /* out: [npoints] */
GlobalArgs args)
{
- double delta;
- double[][] clusters; /* out: [nclusters][nfeatures] */
+ float delta;
+ float[][] clusters; /* out: [nclusters][nfeatures] */
/* Allocate space for returning variable clusters[] */
- clusters = new double[nclusters][nfeatures];
+ clusters = new float[nclusters][nfeatures];
/* Randomly pick cluster centers */
for (int i = 0; i < nclusters; i++) {
*/
intwrapper[] new_centers_len = new intwrapper[nclusters];
- double[][] new_centers = new double[nclusters][nfeatures];
+ float[][] new_centers = new float[nclusters][nfeatures];
int loop = 0;
do {