cc.mallet.types
Class MultiInstanceList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Instance>
              extended by cc.mallet.types.InstanceList
                  extended by cc.mallet.types.MultiInstanceList
All Implemented Interfaces:
AlphabetCarrying, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Instance>, java.util.Collection<Instance>, java.util.List<Instance>, java.util.RandomAccess

public class MultiInstanceList
extends InstanceList

An implementation of InstanceList that logically combines multiple instance lists so that they appear as one list without copying the original lists. This is useful when running cross-validation experiments with large data sets. Any operation that would modify the size of the list is not supported.

Author:
Michael Bond mbond@gmail.com
See Also:
InstanceList, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class cc.mallet.types.InstanceList
InstanceList.CrossValidationIterator
 
Field Summary
 
Fields inherited from class cc.mallet.types.InstanceList
TARGET_PROPERTY
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
MultiInstanceList(InstanceList[] lists)
          Constructs a MultiInstanceList with an array of InstanceList
MultiInstanceList(java.util.List<InstanceList> lists)
          Constructs a MultiInstanceList with a List of InstanceList
 
Method Summary
 boolean add(Instance instance)
          Appends the instance to this list without passing the instance through the InstanceList's pipe.
 boolean add(Instance instance, double instanceWeight)
          Appends the instance to this list without passing it through this InstanceList's pipe, assigning it the specified weight.
 void add(int index, Instance element)
           
 void clear()
           
 java.lang.Object clone()
           
 InstanceList cloneEmpty()
           
protected  InstanceList cloneEmptyInto(InstanceList ret)
           
 boolean contains(java.lang.Object elem)
           
 InstanceList.CrossValidationIterator crossValidationIterator(int nfolds)
           
 InstanceList.CrossValidationIterator crossValidationIterator(int nfolds, int seed)
           
 void ensureCapacity(int minCapacity)
           
 boolean equals(java.lang.Object o)
           
 Instance get(int index)
           
 int hashCode()
           
 int indexOf(java.lang.Object elem)
           
 boolean isEmpty()
           
 java.util.Iterator<Instance> iterator()
           
 int lastIndexOf(java.lang.Object elem)
           
 java.util.ListIterator<Instance> listIterator()
           
 java.util.ListIterator<Instance> listIterator(int index)
           
 boolean remove(Instance instance)
           
 Instance remove(int index)
           
 boolean remove(java.lang.Object o)
           
 Instance set(int index, Instance instance)
           
 void setInstance(int index, Instance instance)
          Replaces the Instance at position index with a new one.
 void setInstanceWeight(Instance instance, double weight)
           
 InstanceList shallowClone()
           
 void shuffle(java.util.Random r)
           
 int size()
           
 InstanceList[] split(double[] proportions)
           
 InstanceList[] split(java.util.Random r, double[] proportions)
          Shuffles the elements of this list among several smaller lists.
 InstanceList[] splitInOrder(double[] proportions)
          Chops this list into several sequential sublists.
 InstanceList[] splitInOrder(int[] counts)
           
 InstanceList[] splitInTwoByModulo(int m)
          Returns a pair of new lists such that the first list in the pair contains every mth element of this list, starting with the first.
 InstanceList subList(double proportion)
           
 InstanceList subList(int start, int end)
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 java.lang.String toString()
           
 void trimToSize()
           
 
Methods inherited from class cc.mallet.types.InstanceList
add, add, addAll, addAll, addThruPipe, addThruPipe, getAlphabet, getAlphabets, getDataAlphabet, getDataClass, getFeatureSelection, getInstanceWeight, getInstanceWeight, getPerLabelFeatureSelection, getPipe, getTargetAlphabet, getTargetClass, hideSomeLabels, hideSomeLabels, load, noisify, removeSources, removeTargets, sampleWithInstanceWeights, sampleWithReplacement, sampleWithWeights, save, setFeatureSelection, setInstanceWeight, setPerLabelFeatureSelection, setPipe, targetLabelDistribution, unhideAllLabels
 
Methods inherited from class java.util.ArrayList
removeRange
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, removeAll, retainAll
 

Constructor Detail

MultiInstanceList

public MultiInstanceList(InstanceList[] lists)
Constructs a MultiInstanceList with an array of InstanceList

Parameters:
lists - Array of InstanceList to logically combine

MultiInstanceList

public MultiInstanceList(java.util.List<InstanceList> lists)
Constructs a MultiInstanceList with a List of InstanceList

Parameters:
lists - List of InstanceList to logically combine
Method Detail

add

public boolean add(Instance instance,
                   double instanceWeight)
Description copied from class: InstanceList
Appends the instance to this list without passing it through this InstanceList's pipe, assigning it the specified weight.

Overrides:
add in class InstanceList
Returns:
true

add

public boolean add(Instance instance)
Description copied from class: InstanceList
Appends the instance to this list without passing the instance through the InstanceList's pipe. The alphabets of this Instance must match the alphabets of this InstanceList.

Specified by:
add in interface java.util.Collection<Instance>
Specified by:
add in interface java.util.List<Instance>
Overrides:
add in class InstanceList
Returns:
true

add

public void add(int index,
                Instance element)
Specified by:
add in interface java.util.List<Instance>
Overrides:
add in class InstanceList

clear

public void clear()
Specified by:
clear in interface java.util.Collection<Instance>
Specified by:
clear in interface java.util.List<Instance>
Overrides:
clear in class InstanceList

clone

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

cloneEmpty

public InstanceList cloneEmpty()
Overrides:
cloneEmpty in class InstanceList

cloneEmptyInto

protected InstanceList cloneEmptyInto(InstanceList ret)
Overrides:
cloneEmptyInto in class InstanceList

contains

public boolean contains(java.lang.Object elem)
Specified by:
contains in interface java.util.Collection<Instance>
Specified by:
contains in interface java.util.List<Instance>
Overrides:
contains in class java.util.ArrayList<Instance>

crossValidationIterator

public InstanceList.CrossValidationIterator crossValidationIterator(int nfolds,
                                                                    int seed)
Overrides:
crossValidationIterator in class InstanceList

crossValidationIterator

public InstanceList.CrossValidationIterator crossValidationIterator(int nfolds)
Overrides:
crossValidationIterator in class InstanceList

ensureCapacity

public void ensureCapacity(int minCapacity)
Overrides:
ensureCapacity in class java.util.ArrayList<Instance>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<Instance>
Specified by:
equals in interface java.util.List<Instance>
Overrides:
equals in class java.util.AbstractList<Instance>

get

public Instance get(int index)
Specified by:
get in interface java.util.List<Instance>
Overrides:
get in class java.util.ArrayList<Instance>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<Instance>
Specified by:
hashCode in interface java.util.List<Instance>
Overrides:
hashCode in class java.util.AbstractList<Instance>

indexOf

public int indexOf(java.lang.Object elem)
Specified by:
indexOf in interface java.util.List<Instance>
Overrides:
indexOf in class java.util.ArrayList<Instance>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<Instance>
Specified by:
isEmpty in interface java.util.List<Instance>
Overrides:
isEmpty in class java.util.ArrayList<Instance>

iterator

public java.util.Iterator<Instance> iterator()
Specified by:
iterator in interface java.lang.Iterable<Instance>
Specified by:
iterator in interface java.util.Collection<Instance>
Specified by:
iterator in interface java.util.List<Instance>
Overrides:
iterator in class java.util.AbstractList<Instance>

lastIndexOf

public int lastIndexOf(java.lang.Object elem)
Specified by:
lastIndexOf in interface java.util.List<Instance>
Overrides:
lastIndexOf in class java.util.ArrayList<Instance>

listIterator

public java.util.ListIterator<Instance> listIterator()
Specified by:
listIterator in interface java.util.List<Instance>
Overrides:
listIterator in class java.util.AbstractList<Instance>

listIterator

public java.util.ListIterator<Instance> listIterator(int index)
Specified by:
listIterator in interface java.util.List<Instance>
Overrides:
listIterator in class java.util.AbstractList<Instance>

remove

public boolean remove(Instance instance)
Overrides:
remove in class InstanceList

remove

public Instance remove(int index)
Specified by:
remove in interface java.util.List<Instance>
Overrides:
remove in class InstanceList

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<Instance>
Specified by:
remove in interface java.util.List<Instance>
Overrides:
remove in class java.util.ArrayList<Instance>

set

public Instance set(int index,
                    Instance instance)
Specified by:
set in interface java.util.List<Instance>
Overrides:
set in class InstanceList

setInstance

public void setInstance(int index,
                        Instance instance)
Description copied from class: InstanceList
Replaces the Instance at position index with a new one.

Overrides:
setInstance in class InstanceList

setInstanceWeight

public void setInstanceWeight(Instance instance,
                              double weight)
Overrides:
setInstanceWeight in class InstanceList

shallowClone

public InstanceList shallowClone()
Overrides:
shallowClone in class InstanceList

shuffle

public void shuffle(java.util.Random r)
Overrides:
shuffle in class InstanceList

size

public int size()
Specified by:
size in interface java.util.Collection<Instance>
Specified by:
size in interface java.util.List<Instance>
Overrides:
size in class java.util.ArrayList<Instance>

split

public InstanceList[] split(double[] proportions)
Overrides:
split in class InstanceList

split

public InstanceList[] split(java.util.Random r,
                            double[] proportions)
Description copied from class: InstanceList
Shuffles the elements of this list among several smaller lists.

Overrides:
split in class InstanceList
Parameters:
r - The source of randomness to use in shuffling.
proportions - A list of numbers (not necessarily summing to 1) which, when normalized, correspond to the proportion of elements in each returned sublist. This method (and all the split methods) do not transfer the Instance weights to the resulting InstanceLists.
Returns:
one InstanceList for each element of proportions

splitInOrder

public InstanceList[] splitInOrder(double[] proportions)
Description copied from class: InstanceList
Chops this list into several sequential sublists.

Overrides:
splitInOrder in class InstanceList
Parameters:
proportions - A list of numbers corresponding to the proportion of elements in each returned sublist. If not already normalized to sum to 1.0, it will be normalized here.
Returns:
one InstanceList for each element of proportions

splitInOrder

public InstanceList[] splitInOrder(int[] counts)
Overrides:
splitInOrder in class InstanceList

splitInTwoByModulo

public InstanceList[] splitInTwoByModulo(int m)
Description copied from class: InstanceList
Returns a pair of new lists such that the first list in the pair contains every mth element of this list, starting with the first. The second list contains all remaining elements.

Overrides:
splitInTwoByModulo in class InstanceList

subList

public InstanceList subList(double proportion)
Overrides:
subList in class InstanceList

subList

public InstanceList subList(int start,
                            int end)
Specified by:
subList in interface java.util.List<Instance>
Overrides:
subList in class InstanceList

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<Instance>
Specified by:
toArray in interface java.util.List<Instance>
Overrides:
toArray in class java.util.ArrayList<Instance>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<Instance>
Specified by:
toArray in interface java.util.List<Instance>
Overrides:
toArray in class java.util.ArrayList<Instance>

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<Instance>

trimToSize

public void trimToSize()
Overrides:
trimToSize in class java.util.ArrayList<Instance>