shared
Class BagCounters

java.lang.Object
  |
  +--shared.BagCounters

public class BagCounters
extends java.lang.Object

The BagCounters class provides support for instance list counters. Counters are provided only for nominal attributes. It is an error to call counters with a non-nominal attribute. All counters are real-valued to provide instance weighting. Unlabelled lists are now supported.

It is assumed the list is labelled and the label must be of nominal type. All non-nominal attributes contain a NULL value, instead of an array of values.


Constructor Summary
BagCounters(BagCounters source)
          Copy constructor.
BagCounters(Schema aSchema)
          Constructor.
 
Method Summary
 void add_instance(Instance instance)
          Adds the given Instance to the counting bags.
 double attr_count(int attrNum, int attrVal)
          Return the value of the attribute counter.
 double[][] attr_counts()
          Returns the matrix of attribute counts.
 int attr_num_vals(int attrNum)
          Returns the number of attribute values that are actually found in the counted Instances for a specified attribute.
 void del_instance(Instance instance)
          Deleted the given Instance to the counting bags.
 void display(java.io.BufferedWriter stream)
          Displays this BagCounters to the specified output stream.
 double label_count(int labelVal)
          Returns the count of a specific label.
 double[] label_counts()
          Returns the array of counting bags.
 int label_num_vals()
          Returns the number of label values that are actually found in the counted Instances.
 java.lang.String toString()
          Convert the counter bag to a string.
protected  void update_counters(Instance instance, int delta)
          Update counters (either increment or decrement) according to the given labelled Instance.
 double val_count(int labelVal, int attrNum, int attrVal)
          Returns the value of a value counter.
 double[][][] value_counts()
          Returns the 3D matrix of attribute value counting bags.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BagCounters

public BagCounters(Schema aSchema)
Constructor.
Parameters:
aSchema - Schema of the Instances for which counting will be done.

BagCounters

public BagCounters(BagCounters source)
Copy constructor.
Parameters:
source - The BagCounters to be copied.
Method Detail

add_instance

public void add_instance(Instance instance)
Adds the given Instance to the counting bags. The Instance's weight is taken into account.
Parameters:
instance - The Instance to be added. The Instance should be labelled.

del_instance

public void del_instance(Instance instance)
Deleted the given Instance to the counting bags. The Instance's weight is taken into account.
Parameters:
instance - The Instance to be deleted. The Instance should be labelled.

label_counts

public double[] label_counts()
Returns the array of counting bags.
Returns:
The label counting bags.

value_counts

public double[][][] value_counts()
Returns the 3D matrix of attribute value counting bags.
Returns:
The attribute value counting bags.

attr_count

public double attr_count(int attrNum,
                         int attrVal)
Return the value of the attribute counter.
Parameters:
attrNum - The number of the attribute for which a count is requested.
attrVal - The number of the value of the attribute for which a count is requested.
Returns:
The number of occurances of a specific value for a specific attribute.

attr_counts

public double[][] attr_counts()
Returns the matrix of attribute counts.
Returns:
The matrix of attribute counts.

label_num_vals

public int label_num_vals()
Returns the number of label values that are actually found in the counted Instances.
Returns:
The number of label values that have been found.

attr_num_vals

public int attr_num_vals(int attrNum)
Returns the number of attribute values that are actually found in the counted Instances for a specified attribute.
Parameters:
attrNum - The number of the attribute to be checked.
Returns:
The number of attribute values found for an attribute.

label_count

public double label_count(int labelVal)
Returns the count of a specific label.
Parameters:
labelVal - The specific value to be checked.
Returns:
The count of a specific label.

update_counters

protected void update_counters(Instance instance,
                               int delta)
Update counters (either increment or decrement) according to the given labelled Instance. We assume the label is Nominal here (checked in the constructor). Update_instance is for use by add_instance and del_instance. Update counters takes Instance weight into account during addition and deletion.
Parameters:
instance - The Instance to be added/deleted from the BagCounters.
delta - Indicates whether given Instance is to be added or deleted. 1 indicates addition. -1 indicates deletion.

display

public void display(java.io.BufferedWriter stream)
Displays this BagCounters to the specified output stream.
Parameters:
stream - The output stream to be written to.

toString

public java.lang.String toString()
Convert the counter bag to a string.
Overrides:
toString in class java.lang.Object
Returns:
A string containing the displayed output.

val_count

public double val_count(int labelVal,
                        int attrNum,
                        int attrVal)
Returns the value of a value counter.
Parameters:
labelVal - The value of the label classification for which counters are requested.
attrNum - The number of the attribute for which counters are requested.
attrVal - The number of the value of the attribute for which counters are requested.
Returns:
The number of values a specified attribute and label value has.