BIJ API

bijnum
Class BIJknn

java.lang.Object
  |
  +--bijnum.BIJknn

public class BIJknn
extends java.lang.Object

k Nearest Neighborhood (brute-force) implementation. Copyright (c) 1999-2003, Michael Abramoff. All rights reserved.


Field Summary
 float[] classset
          The classification for each element in the dataset, a 1xM vector.
 float[][] dataset
          The dataset, a MxN matrix of N-dimensional vectors.
static int inserts
           
protected  float[] kDistances
          Some variables that I do not want to allocate for every element.
protected  int[] kIndices
           
 int n
          The numbe rof different classes in classset.
 
Constructor Summary
BIJknn(float[][] dataset, float[] classset, int n)
           
 
Method Summary
 void classify(float[] classification, float[][] unknown, int k)
          Find the classification of all M (N dimensional) vectors unknown in the dataset.
 void clean()
          Cleans the dataset using Wilson's pruning algorithm.
protected static float distance(float[] a, float[] b)
          Return the distance according to some Minkowski metric.
 void search(int[] kIndices, float[] kDistances, float[] v, int k)
          Find the k-nearest neighbors of vector v (N dimensional) in dataset and put indices in kIndices, distances in kDistances.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inserts

public static int inserts

dataset

public float[][] dataset
The dataset, a MxN matrix of N-dimensional vectors.

classset

public float[] classset
The classification for each element in the dataset, a 1xM vector.

n

public int n
The numbe rof different classes in classset.

kDistances

protected float[] kDistances
Some variables that I do not want to allocate for every element.

kIndices

protected int[] kIndices
Constructor Detail

BIJknn

public BIJknn(float[][] dataset,
              float[] classset,
              int n)
Method Detail

classify

public void classify(float[] classification,
                     float[][] unknown,
                     int k)
Find the classification of all M (N dimensional) vectors unknown in the dataset.
Parameters:
classification - a float[][] array that will contain the nearest neighbor classificiations for all elements in unknown.
unknown - a MxN matrix of M vectors to be classified in the dataset.
k - the number of neighbors to use for classification modifies classification

search

public void search(int[] kIndices,
                   float[] kDistances,
                   float[] v,
                   int k)
Find the k-nearest neighbors of vector v (N dimensional) in dataset and put indices in kIndices, distances in kDistances.
Parameters:
kIndices - a int[] of length k that will contain the indices to the k closest neighbors of v
kDistances - a float[] of length k that will contain the distances to the k closest neighbors of v.
v - the vector to classify
k - the number of neighbors to use for classification

clean

public void clean()
Cleans the dataset using Wilson's pruning algorithm. Classifies each point in the dataset (k=3) and removes it if its class is not the same as the classification by its k neighbors.

distance

protected static float distance(float[] a,
                                float[] b)
Return the distance according to some Minkowski metric. This implements Euclidean distance. To save time, the POWER(1/k) is not performed.
Parameters:
a - a float[] vector containing a point
b - a float[] vector containing another point.
Returns:
the Minkowski distance between a and b.

BIJ API

Submit a bug or feature

Copyright (c) 1997-2003 Michael Abramoff
Licensing available. All Rights Reserved.