Package weka.core
Class InstancesView
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<weka.core.Instance>
-
- weka.core.Instances
-
- weka.core.InstancesView
-
- All Implemented Interfaces:
Serializable,Iterable<weka.core.Instance>,Collection<weka.core.Instance>,List<weka.core.Instance>,weka.core.RevisionHandler
public class InstancesView extends weka.core.InstancesPresents a view of an Instances object. Rows can be limited.- Version:
- $Revision$
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected weka.core.Instancesm_Datasetthe underlying dataset.protected gnu.trove.list.TIntListm_Rowsthe rows to use.-
Fields inherited from class weka.core.Instances
ARFF_DATA, ARFF_RELATION, FILE_EXTENSION, m_Attributes, m_ClassIndex, m_Instances, m_Lines, m_NamesToAttributeIndices, m_RelationName, SERIALIZED_OBJ_FILE_EXTENSION
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description InstancesView(weka.core.Instances dataset, int[] rows)Initializes the dataset.InstancesView(weka.core.Instances dataset, int fromRow, int toRow)Initializes the dataset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, weka.core.Instance instance)Adds one instance at the given position in the list.booleanadd(weka.core.Instance instance)Adds one instance to the end of the set.weka.core.AttributeStatsattributeStats(int index)Calculates summary statistics on the values that appear in this set of instances for a specified attribute.voidcompactify()Does nothing.voiddelete()Removes all instances from the set.voiddelete(int index)Removes an instance at the given position from the set.voiddeleteAttributeAt(int position)Deletes an attribute at the given position (0 to numAttributes() - 1).voiddeleteAttributeType(int attType)Deletes all attributes of the given type in the dataset.voiddeleteWithMissing(int attIndex)Removes all instances with missing values for a particular attribute from the dataset.Enumeration<weka.core.Instance>enumerateInstances()Returns an enumeration of all instances in the dataset.weka.core.InstancefirstInstance()Returns the first instance in the set.weka.core.Instanceget(int index)Returns the instance at the given position.voidinsertAttributeAt(weka.core.Attribute att, int position)Inserts an attribute at the given position (0 to numAttributes()) and sets all values to be missing.weka.core.Instanceinstance(int index)Returns the instance at the given position.weka.core.InstancelastInstance()Returns the last instance in the set.intnumClasses()Returns the number of class labels.intnumInstances()Returns the number of instances in the dataset.weka.core.Instanceremove(int index)Removes the instance at the given position.voidrenameAttribute(int att, String name)Renames an attribute.voidrenameAttributeValue(int att, int val, String name)Renames the value of a nominal (or string) attribute value.voidreplaceAttributeAt(weka.core.Attribute att, int position)Replaces the attribute at the given position (0 to numAttributes()) with the given attribute and sets all its values to be missing.weka.core.Instanceset(int index, weka.core.Instance instance)Replaces the instance at the given position.voidsetClassIndex(int classIndex)Sets the class index of the set.intsize()Returns the number of instances in the dataset.voidsort(int attIndex)Sorts the instances based on an attribute.protected voidsortBasedOnNominalAttribute(int attIndex)Sorts a nominal attribute (stable, linear-time sort).voidstableSort(int attIndex)Sorts the instances based on an attribute, using a stable sort.protected voidstratStep(int numFolds)Help function needed for stratification of set.weka.core.InstancesstringFreeStructure()Create a copy of the structure.voidswap(int i, int j)Swaps two instances in the set.-
Methods inherited from class weka.core.Instances
attribute, attribute, attributeToDoubleArray, checkForAttributeType, checkForStringAttributes, checkInstance, classAttribute, classIndex, copyInstances, deleteStringAttributes, deleteWithMissing, deleteWithMissingClass, enumerateAttributes, equalHeaders, equalHeadersMsg, getRandomNumberGenerator, getRevision, initialize, instancesAndWeights, kthSmallestValue, kthSmallestValue, main, meanOrMode, meanOrMode, mergeInstances, numAttributes, numDistinctValues, numDistinctValues, randomize, readInstance, relationName, renameAttribute, renameAttributeValue, resample, resampleWithWeights, resampleWithWeights, resampleWithWeights, resampleWithWeights, resampleWithWeights, resampleWithWeights, resampleWithWeights, setClass, setRelationName, sort, stableSort, stratify, stringWithoutHeader, sumOfWeights, test, testCV, toString, toSummaryString, trainCV, trainCV, variance, variance, variances
-
Methods inherited from class java.util.AbstractList
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
InstancesView
public InstancesView(weka.core.Instances dataset, int[] rows)Initializes the dataset.- Parameters:
dataset- the underlying datasetrows- the rows to use, null for all
-
InstancesView
public InstancesView(weka.core.Instances dataset, int fromRow, int toRow)Initializes the dataset.- Parameters:
dataset- the underlying datasetfromRow- the first rowtoRow- the last row (excluded)
-
-
Method Detail
-
stringFreeStructure
public weka.core.Instances stringFreeStructure()
Create a copy of the structure. If the data has string or relational attributes, theses are replaced by empty copies. Other attributes are left unmodified, but the underlying list structure holding references to the attributes is shallow-copied, so that other Instances objects with a reference to this list are not affected.- Overrides:
stringFreeStructurein classweka.core.Instances- Returns:
- a copy of the instance structure.
-
add
public boolean 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. Note: String or relational values are not transferred.- Specified by:
addin interfaceCollection<weka.core.Instance>- Specified by:
addin interfaceList<weka.core.Instance>- Overrides:
addin classweka.core.Instances- Parameters:
instance- the instance to be added
-
add
public void add(int index, weka.core.Instance instance)Adds one instance at the given position in the list. 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. Note: String or relational values are not transferred.
-
compactify
public void compactify()
Does nothing.- Overrides:
compactifyin classweka.core.Instances
-
delete
public void delete()
Removes all instances from the set.- Overrides:
deletein classweka.core.Instances
-
delete
public void delete(int index)
Removes an instance at the given position from the set.- Overrides:
deletein classweka.core.Instances- Parameters:
index- the instance's position (index starts with 0)
-
deleteAttributeAt
public void deleteAttributeAt(int position)
Deletes an attribute at the given position (0 to numAttributes() - 1). Attribute objects after the deletion point are copied so that their indices can be decremented. Creates a fresh list to hold the old and new attribute objects.- Overrides:
deleteAttributeAtin classweka.core.Instances- Parameters:
position- the attribute's position (position starts with 0)- Throws:
IllegalArgumentException- if the given index is out of range or the class attribute is being deleted
-
deleteAttributeType
public void deleteAttributeType(int attType)
Deletes all attributes of the given type in the dataset. A deep copy of the attribute information is performed before an attribute is deleted.- Overrides:
deleteAttributeTypein classweka.core.Instances- Parameters:
attType- the attribute type to delete- Throws:
IllegalArgumentException- if attribute couldn't be successfully deleted (probably because it is the class attribute).
-
deleteWithMissing
public void deleteWithMissing(int attIndex)
Removes all instances with missing values for a particular attribute from the dataset.- Overrides:
deleteWithMissingin classweka.core.Instances- Parameters:
attIndex- the attribute's index (index starts with 0)
-
enumerateInstances
public Enumeration<weka.core.Instance> enumerateInstances()
Returns an enumeration of all instances in the dataset.- Overrides:
enumerateInstancesin classweka.core.Instances- Returns:
- enumeration of all instances in the dataset
-
firstInstance
public weka.core.Instance firstInstance()
Returns the first instance in the set.- Overrides:
firstInstancein classweka.core.Instances- Returns:
- the first instance in the set
-
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. Existing attribute objects at and after the insertion point are also copied so that their indices can be incremented. Creates a fresh list to hold the old and new attribute objects.- Overrides:
insertAttributeAtin classweka.core.Instances- Parameters:
att- the attribute to be insertedposition- the attribute's position (position starts with 0)- Throws:
IllegalArgumentException- if the given index is out of range
-
instance
public weka.core.Instance instance(int index)
Returns the instance at the given position.- Overrides:
instancein classweka.core.Instances- Parameters:
index- the instance's index (index starts with 0)- Returns:
- the instance at the given position
-
get
public weka.core.Instance get(int index)
Returns the instance at the given position.
-
lastInstance
public weka.core.Instance lastInstance()
Returns the last instance in the set.- Overrides:
lastInstancein classweka.core.Instances- Returns:
- the last instance in the set
-
numClasses
public int numClasses()
Returns the number of class labels.- Overrides:
numClassesin classweka.core.Instances- Returns:
- the number of class labels as an integer if the class attribute is nominal, 1 otherwise.
- Throws:
weka.core.UnassignedClassException- if the class is not set
-
size
public int size()
Returns the number of instances in the dataset.- Specified by:
sizein interfaceCollection<weka.core.Instance>- Specified by:
sizein interfaceList<weka.core.Instance>- Overrides:
sizein classweka.core.Instances- Returns:
- the number of instances in the dataset as an integer
-
numInstances
public int numInstances()
Returns the number of instances in the dataset.- Overrides:
numInstancesin classweka.core.Instances- Returns:
- the number of instances in the dataset as an integer
-
swap
public void swap(int i, int j)Swaps two instances in the set.- Overrides:
swapin classweka.core.Instances- Parameters:
i- the first instance's index (index starts with 0)j- the second instance's index (index starts with 0)
-
replaceAttributeAt
public void replaceAttributeAt(weka.core.Attribute att, int position)Replaces the attribute at the given position (0 to numAttributes()) with the given attribute and sets all its values to be missing. Shallow copies the given attribute before it is inserted. Creates a fresh list to hold the old and new attribute objects.- Overrides:
replaceAttributeAtin classweka.core.Instances- Parameters:
att- the attribute to be insertedposition- the attribute's position (position starts with 0)- Throws:
IllegalArgumentException- if the given index is out of range
-
remove
public weka.core.Instance remove(int index)
Removes the instance at the given position.
-
renameAttribute
public void renameAttribute(int att, String name)Renames an attribute. This change only affects this dataset.- Overrides:
renameAttributein classweka.core.Instances- Parameters:
att- the attribute's index (index starts with 0)name- the new name
-
renameAttributeValue
public void renameAttributeValue(int att, int val, String name)Renames the value of a nominal (or string) attribute value. This change only affects this dataset.- Overrides:
renameAttributeValuein classweka.core.Instances- Parameters:
att- the attribute's index (index starts with 0)val- the value's index (index starts with 0)name- the new name
-
set
public weka.core.Instance set(int index, weka.core.Instance instance)Replaces the instance at the given position. Shallow copies instance before it is added. Does not check if the instance is compatible with the dataset. Note: String or relational values are not transferred.
-
sortBasedOnNominalAttribute
protected void sortBasedOnNominalAttribute(int attIndex)
Sorts a nominal attribute (stable, linear-time sort). Instances are sorted based on the attribute label ordering specified in the header.- Overrides:
sortBasedOnNominalAttributein classweka.core.Instances- Parameters:
attIndex- the attribute's index (index starts with 0)- Throws:
adams.core.exception.NotImplementedException
-
sort
public void sort(int attIndex)
Sorts the instances based on an attribute. For numeric attributes, instances are sorted in ascending order. For nominal attributes, instances are sorted based on the attribute label ordering specified in the header. Instances with missing values for the attribute are placed at the end of the dataset.- Overrides:
sortin classweka.core.Instances- Parameters:
attIndex- the attribute's index (index starts with 0)- Throws:
adams.core.exception.NotImplementedException
-
stableSort
public void stableSort(int attIndex)
Sorts the instances based on an attribute, using a stable sort. For numeric attributes, instances are sorted in ascending order. For nominal attributes, instances are sorted based on the attribute label ordering specified in the header. Instances with missing values for the attribute are placed at the end of the dataset.- Overrides:
stableSortin classweka.core.Instances- Parameters:
attIndex- the attribute's index (index starts with 0)- Throws:
adams.core.exception.NotImplementedException
-
attributeStats
public weka.core.AttributeStats attributeStats(int index)
Calculates summary statistics on the values that appear in this set of instances for a specified attribute.- Overrides:
attributeStatsin classweka.core.Instances- Parameters:
index- the index of the attribute to summarize (index starts with 0)- Returns:
- an AttributeStats object with it's fields calculated.
-
stratStep
protected void stratStep(int numFolds)
Help function needed for stratification of set.- Overrides:
stratStepin classweka.core.Instances- Parameters:
numFolds- the number of folds for the stratification- Throws:
adams.core.exception.NotImplementedException
-
setClassIndex
public void setClassIndex(int classIndex)
Sets the class index of the set. If the class index is negative there is assumed to be no class. (ie. it is undefined)- Overrides:
setClassIndexin classweka.core.Instances- Parameters:
classIndex- the new class index (index starts with 0)- Throws:
IllegalArgumentException- if the class index is too big or < 0
-
-