mulan.data
Class LabelSet

java.lang.Object
  extended by mulan.data.LabelSet
All Implemented Interfaces:
Serializable, Comparable<LabelSet>

public class LabelSet
extends Object
implements Serializable, Comparable<LabelSet>

Class that handles labelsets

Version:
$Revision: 0.03 $
Author:
Grigorios Tsoumakas, Robert Friberg
See Also:
Serialized Form

Field Summary
protected  int[] labelSet
          The set is represented internally as an array of integers.
 
Constructor Summary
LabelSet(double[] set)
          Initializes an object based on an array of doubles containing 0/1
 
Method Summary
 int compareTo(LabelSet o)
          Used for sorting collections of labelsets according to size
 boolean equals(Object obj)
           
static LabelSet fromBitString(String bits)
          Constructs a LabelSet object from a bitstring.
 ArrayList<LabelSet> getSubsets()
          Constructs all subsets of a labelset (apart from the empty one).
 int hammingDifference(LabelSet other)
          Calculates the Hamming Distance between the current labelset and another labelset.
 int hashCode()
           
static LabelSet intersection(LabelSet l1, LabelSet l2)
           
 int size()
          The number of set members.
 String toBitString()
          Constructs a bitstring from the current labelset.
 boolean[] toBooleanArray()
          Get an array representation of this set.
 double[] toDoubleArray()
          Get an array representation of this set.
 String toString()
          A comma-separated list of label names enclosed in curlies.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

labelSet

protected int[] labelSet
The set is represented internally as an array of integers. Weka uses doubles but we choose integers for fast comparisons. Observe that the set is immutable, once assigned by the constructor, no changes are possible.

Constructor Detail

LabelSet

public LabelSet(double[] set)
Initializes an object based on an array of doubles containing 0/1

Parameters:
set -
Method Detail

toString

public String toString()
A comma-separated list of label names enclosed in curlies.

Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

size

public int size()
The number of set members. Calculated on first call and cached for subsequent calls.

Returns:
The number of set members

toDoubleArray

public double[] toDoubleArray()
Get an array representation of this set.

Returns:
a copy of the underlying array.

toBooleanArray

public boolean[] toBooleanArray()
Get an array representation of this set.

Returns:
a copy of the underlying array.

hammingDifference

public int hammingDifference(LabelSet other)
Calculates the Hamming Distance between the current labelset and another labelset.

Parameters:
other - the other LabelSet object.
Returns:
the Hamming Distance.

toBitString

public String toBitString()
Constructs a bitstring from the current labelset.

Returns:
the bitstring.

fromBitString

public static LabelSet fromBitString(String bits)
                              throws Exception
Constructs a LabelSet object from a bitstring.

Parameters:
bits - the bitstring
Returns:
the labelset.
Throws:
Exception

getSubsets

public ArrayList<LabelSet> getSubsets()
                               throws Exception
Constructs all subsets of a labelset (apart from the empty one).

Returns:
an ArrayList of LabelSet objects with the subsets.
Throws:
Exception

intersection

public static LabelSet intersection(LabelSet l1,
                                    LabelSet l2)
Parameters:
l1 - a labelset
l2 - another labelset
Returns:
their interesection

compareTo

public int compareTo(LabelSet o)
Used for sorting collections of labelsets according to size

Specified by:
compareTo in interface Comparable<LabelSet>