classifier
Class GroupMeans

java.lang.Object
  extended by classifier.GroupMeans
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class GroupMeans
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Many classification functions need the mean values of each parameter from a group of training data.

This class provides a set of functions which will get the means by group, and also return larger matrixes of the mean values repeated by a grouping index or repeated for a single group which can be used in classifier training and classifier application

Author:
Doug Gillespie
See Also:
Matrix, Serialized Form

Field Summary
private  Jama.Matrix groupMeans
           
private  int[] groupSize
           
private static long serialVersionUID
           
private  int[] uniqueGroups
           
 
Constructor Summary
GroupMeans(Jama.Matrix data, int[] group)
          Constructor works out the number of unique groups in group and then constructs a smaller matrix of means of each parameter by group.
 
Method Summary
 GroupMeans clone()
           
private  int getGroupIndex(int iD)
          The group parameter passed to the constructor can contain grouping values which may not start at 0 and may not be continuous.
private  int[] getGroupIndex(int[] iD)
          As getGroupIndex(iD) but for arrays.
static int getGroupIndex(int[] uniqueGroups, int iD)
          Gets the index of a group id (these will often be the same !)
static int[] getGroupIndex(int[] uniqueGroups, int[] iD)
          Gets the index of a group id (these will often be the same !)
 Jama.Matrix getGroupMeans()
           
 Jama.Matrix getGroupMeans(int[] groups)
          Create a matrix of means, repeated multiple times (e.g.
 Jama.Matrix getGroupMeans(int group, int n)
          Create a matrix of means for a single group.
 int[] getGroupSize()
           
 int getNumGroups()
           
 int[] getUniqueGroups()
          Get list of unique groups in the data
private  void makeGroupMeans(Jama.Matrix data, int[] group)
          Takes the raw training data, works out what gorups are present in group and works out the means for each group.
static int[] unique(int[] groups)
          Get a unique list of items in the training group
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

groupMeans

private Jama.Matrix groupMeans

uniqueGroups

private int[] uniqueGroups

groupSize

private int[] groupSize
Constructor Detail

GroupMeans

public GroupMeans(Jama.Matrix data,
                  int[] group)
Constructor works out the number of unique groups in group and then constructs a smaller matrix of means of each parameter by group.

Parameters:
data - matrix of training data
group - group indexes
Method Detail

getGroupMeans

public Jama.Matrix getGroupMeans()
Returns:
matrix of means by training group

getUniqueGroups

public int[] getUniqueGroups()
Get list of unique groups in the data

Returns:
list of unique groups in the data

getGroupSize

public int[] getGroupSize()
Returns:
the number of entries in each group.

getNumGroups

public int getNumGroups()
Returns:
The number of unique groups in the data

getGroupMeans

public Jama.Matrix getGroupMeans(int[] groups)
Create a matrix of means, repeated multiple times (e.g. so it can be subtracted off a set of training data).

Parameters:
groups - grouping to apply. Must contain only the same entries as in the group parameter passed to the constructor.
Returns:
matrix of grouped means.

getGroupMeans

public Jama.Matrix getGroupMeans(int group,
                                 int n)
Create a matrix of means for a single group.

Parameters:
group - index of group
n - number of rows of data to create
Returns:
matrix with n identical rows of group

makeGroupMeans

private void makeGroupMeans(Jama.Matrix data,
                            int[] group)
Takes the raw training data, works out what gorups are present in group and works out the means for each group.

Parameters:
data - training data Matrix
group - grouping variable

getGroupIndex

private int getGroupIndex(int iD)
The group parameter passed to the constructor can contain grouping values which may not start at 0 and may not be continuous.

Therefore, when constructing new means matrixes, it is necessary to use the index of each group parameter to get the right values out of the groupMeans matrix.

Parameters:
iD - group parameter
Returns:
group parameter index in unique list.

getGroupIndex

public static int getGroupIndex(int[] uniqueGroups,
                                int iD)
Gets the index of a group id (these will often be the same !)

Parameters:
uniqueGroups - list of unique groups (sorted)
iD - group ID to find
Returns:
index in group list.

getGroupIndex

private int[] getGroupIndex(int[] iD)
As getGroupIndex(iD) but for arrays.

The group parameter passed to the constructor can contain grouping values which may not start at 0 and may not be continuous.

Therefore, when constructing new means matrixes, it is necessary to use the index of each group parameter to get the right values out of the groupMeans matrix.

Parameters:
iD - group parameter
Returns:
group parameter index in unique list.

getGroupIndex

public static int[] getGroupIndex(int[] uniqueGroups,
                                  int[] iD)
Gets the index of a group id (these will often be the same !)

Parameters:
uniqueGroups - sorted list of unique groups
iD - list of group id's to find indexes of
Returns:
list of indexes.

unique

public static int[] unique(int[] groups)
Get a unique list of items in the training group

e.g. if group was {1, 9, 3, 1, 4, 9, 4} then the return value would be {1, 3, 4, 9}

Parameters:
groups - group data which will contain many instances of few different values.
Returns:
a shorter array of unique values sorted by size.

clone

public GroupMeans clone()
Overrides:
clone in class java.lang.Object