## milk.core
Class Exemplar

    java.lang.Object
      |
      +--milk.core.Exemplar

All Implemented Interfaces:
  java.io.Serializable

public class Exemplar
extends java.lang.Object
implements java.io.Serializable

Class for handling an ordered set of weighted exemplars.

This class is not intended for reading directly from the Reader. Instead, the data should be pre-processed and then are tried to form an exemplar. The following members are still useful from the Instances class in the context of exemplar by using getInstances()
attribute(int)
attribute(String)
attributeStats(int)
attributeToDoubleArray(int)
checkForStringAttributes()
checkInstance(Instance)
classAttribute()
classIndex()
compactify()
delete()
delete(int)
deleteWithMissing(Attribute)
deleteWithMissing(int)
enumerateInstances()
firstInstance()
instance(int)
lastInstance()
meanOrMode(Attribute)
meanOrMode(int)
numAttributes()
numClasses()
numDistinctValues(Attribute)
numDistinctValues(int)
numInstances()
randomize(Random)
renameAttribute(Attribute, String)
renameAttribute(int, String)
renameAttributeValue(Attribute, String, String)
renameAttributeValue(int, int, String)
resample(Random)
resampleWithWeights(Random)
resampleWithWeights(Random, double[])
sort(Attribute)
sort(int)
stringFreeStructure()
sumOfWeights()
variance(Attribute)
variance(int) Typical usage is to read the instances from the Reader and try to feed it into into an array of Exemplars according to it's ID values

See Also:
  Serialized Form

Constructor Summary
`Exemplar(Exemplar exemplar)` Constructor to form an exemplar by copying from another exemplar
`Exemplar(Exemplar exemplar, int size)` Constructor creating an empty Exemplar with the same structure of the given exemplar and the given size
`Exemplar(weka.core.Instance inst, int id)` Constructor using one instance to form an exemplar
`Exemplar(weka.core.Instances dataset)` Constructor copying all instances and references to the header information from the given set of instances.
`Exemplar(weka.core.Instances dataset, int id)` Constructor creating an exemplar with the given dataset and the given ID index

Method Summary
`void` `add(weka.core.Instance instance)` Adds one instance to the end of the set.
`boolean` `checkInstance(weka.core.Instance instance)` Checks if the given instance is compatible with this Exemplar.
`weka.core.Attribute` `classAttribute()` Returns the class attribute.
`int` `classIndex()` Returns the class attribute's index.
`double` `classValue()` Returns the class value of this exemplar.
`void` `compactify()` Compactifies the set of instances in this exemplar
`void` `deleteAttributeAt(int position)` Deletes an attribute at the given position (0 to numAttributes() - 1).
`java.util.Enumeration` `enumerateAttributes()` Returns an enumeration of all the attributes.
`weka.core.Instances` `getInstances()` Returns the dataset in this exemplar
`weka.core.Attribute` `idAttribute()` Returns the ID attribute.
`int` `idIndex()` Returns the ID attribute's index.
`double` `idValue()` Returns the ID attribute's value.
`void` `insertAttributeAt(weka.core.Attribute att, int position)` Inserts an attribute at the given position (0 to numAttributes()) and sets all values to be missing.
`boolean` `isAllMissing(int attIndex)` Check whether the values of the specified attribute in this exemplar are all missing values
`static void` `main(java.lang.String[] args)` Main method for testing this class -- just prints out a set of Exemplars.
`double[]` `meanOrMode()` Returns the mean (mode) for all attributes (except ID and class) as a floating-point value.
`int` `numIds()` Returns the number of ID labels.
`void` `setClassValue(double cv)` Sets the class value of the exemplar
`void` `setWeight(double weight)` Sets the weight of the exemplar.
`java.lang.String` `toString()` Returns the exemplar as a string.
`double[]` `variance()` Computes the variances for all numeric attributes.
`double` `weight()` Returns the exemplar's weight.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Exemplar

    public Exemplar(weka.core.Instance inst,
                    int id)

  Constructor using one instance to form an exemplar

Parameters:
  `id` - the ID index

### Exemplar

    public Exemplar(Exemplar exemplar,
                    int size)

  Constructor creating an empty Exemplar with the same structure of the given exemplar and the given size

Parameters:
  `exemplar` - the given exemplar
  `size` - the given size

### Exemplar

    public Exemplar(Exemplar exemplar)

  Constructor to form an exemplar by copying from another exemplar

Parameters:
  `exemplar` - the copied exemplar

### Exemplar

    public Exemplar(weka.core.Instances dataset)
             throws java.lang.Exception

  Constructor copying all instances and references to the header information from the given set of instances. Set the attribute with first index as exemplar ID

Throws:
  `if` - the exemplar cannot be built properly
  `java.lang.Exception`

### Exemplar

    public Exemplar(weka.core.Instances dataset,
                    int id)
             throws java.lang.Exception

  Constructor creating an exemplar with the given dataset and the given ID index

Parameters:
  `id` - the index of the ID of the exemplar

Method Detail

### add

    public final void add(weka.core.Instance instance)

  Adds one instance to the end of the set. Shallow copies instance before it is added. Increases the size of the dataset if it is not large enough. Does not check if the instance is compatible with the dataset.

  Parameters:
    `instance` - the instance to be added

### checkInstance

    public final boolean checkInstance(weka.core.Instance instance)

  Checks if the given instance is compatible with this Exemplar.

  Returns:
    true if the instance is compatible with the exemplar

### classAttribute

    public final weka.core.Attribute classAttribute()

  Returns the class attribute.

  Returns:
    the class attribute
  Throws:
    `weka.core.UnassignedClassException` - if the class is not set

### classIndex

    public final int classIndex()

  Returns the class attribute's index. Returns negative number if it's undefined.

  Returns:
    the class index as an integer

### classValue

    public final double classValue()

  Returns the class value of this exemplar.

  Returns:
    the class value
  Throws:
    `weka.core.UnassignedClassException` - if the class is not set

### setClassValue

    public void setClassValue(double cv)

  Sets the class value of the exemplar

  Parameters:
    `cv` - the new class value

### compactify

    public final void compactify()

  Compactifies the set of instances in this exemplar

### deleteAttributeAt

    public void deleteAttributeAt(int position)
                           throws java.lang.IllegalArgumentException

  Deletes an attribute at the given position (0 to numAttributes() - 1). A deep copy of the attribute information is performed before the attribute is deleted.

  Throws:
    `java.lang.IllegalArgumentException` - if the given index is out of range or the class attribute is being deleted

### enumerateAttributes

    public java.util.Enumeration enumerateAttributes()

  Returns an enumeration of all the attributes.

  Returns:
    enumeration of all the attributes.

### getInstances

    public weka.core.Instances getInstances()

  Returns the dataset in this exemplar

  Returns:
    all the instances in the exemplar

### idAttribute

    public final weka.core.Attribute idAttribute()

  Returns the ID attribute.

  Returns:
    the ID attribute

### idIndex

    public final int idIndex()

  Returns the ID attribute's index.

  Returns:
    the ID index as an integer

### idValue

    public final double idValue()

  Returns the ID attribute's value.

  Returns:
    the ID value of this exemplar

### insertAttributeAt

    public void insertAttributeAt(weka.core.Attribute att,
                                  int position)

  Inserts an attribute at the given position (0 to numAttributes()) and sets all values to be missing. Shallow copies the attribute before it is inserted, and performs a deep copy of the existing attribute information.

  Parameters:
    `att` - the attribute to be inserted
  Throws:
    `java.lang.IllegalArgumentException` - if the given index is out of range

### meanOrMode

    public final double[] meanOrMode()

  Returns the mean (mode) for all attributes (except ID and class) as a floating-point value. Returns 0 if the attribute is neither nominal nor numeric. If all values are missing it returns zero.

  Returns:
    the mean or the mode of all attributes

### variance

    public final double[] variance()

  Computes the variances for all numeric attributes. For nominal attribute, the variance is set to -1

  Returns:
    the variances for all numeric attributes

### numIds

    public final int numIds()

  Returns the number of ID labels.

  Returns:
    the number of ID labels.

### setWeight

    public final void setWeight(double weight)

  Sets the weight of the exemplar.

  Parameters:
    `weight` - the weight

### toString

    public final java.lang.String toString()

  Returns the exemplar as a string. Strings are quoted if they contain whitespace characters, or if they are a question mark.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    the exemplar as a string

### weight

    public final double weight()

  Returns the exemplar's weight.

  Returns:
    the exemplar's weight as a double

### isAllMissing

    public final boolean isAllMissing(int attIndex)

  Check whether the values of the specified attribute in this exemplar are all missing values

  Parameters:
    `attIndex` - the specified attribute index
  Returns:
    whether values are all missing

### main

    public static void main(java.lang.String[] args)

  Main method for testing this class -- just prints out a set of Exemplars. Assume the ID index is 0.