Class DataSet
- java.lang.Object
-
- moa.clusterers.outliers.AnyOut.util.DataSet
-
- All Implemented Interfaces:
Iterable<DataObject>
public class DataSet extends Object implements Iterable<DataObject>
A set ofDataObject
s. Internally it uses anArrayList<DataObject>
so it is recommended to use with care. For speedy operations after the data is collected usegetFeaturesAsArray()
. When access speed is not a factor the iterator can be used to go through the data with aforeach
loop.- Author:
- Fernando Sanchez Villaamil
- See Also:
getFeaturesAsArray()
-
-
Constructor Summary
Constructors Constructor Description DataSet(int nrOfDimensions)
Creates an empty set.DataSet(DataObject newData)
Creates a Set with only the given object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObject(DataObject newData)
Adds aDataObject
to the set.void
addObject(DataSet dataSet)
Adds all objects in the given data setvoid
clear()
DataObject[]
getDataObjectArray()
Returns an array of all theDataObject
s in the set.DataSet[]
getDataSetsPerClass()
Separates the objects in this data set according to their class labeldouble[][]
getFeaturesAsArray()
Returns an array with all the features of all the objects in the set.int
getNrOfClasses()
Counts the number of classes that are present in the data set.int
getNrOfDimensions()
Return the dimension of the objects in theDataSet
.DataObject
getObject(int index)
Returns theDataObject
at the given position.double[]
getVariances()
Calculates the variance of this data set for each dimensionIterator<DataObject>
iterator()
An iterator for the set.void
manipulateIds()
resets the ids, so that the set contains ids from 0 to noOfObjects-1int
size()
Returns the size of the set.String
toString()
Returns aString
representation of all theDataObject
s in the code as a list of the representation implemented for these.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
DataSet
public DataSet(int nrOfDimensions)
Creates an empty set.- Parameters:
nrOfDimensions
- The dimension theDataObject
s should have.- Throws:
praktikum.framework.data.InconsistentDimensionException
- See Also:
DataObject
-
DataSet
public DataSet(DataObject newData)
Creates a Set with only the given object. The dimension for theDataSet
is given by the givenDataObject
.- Parameters:
newData
- The firstDataObject
added to the set.- Throws:
praktikum.framework.data.InconsistentDimensionException
- See Also:
DataObject
-
-
Method Detail
-
addObject
public void addObject(DataObject newData)
Adds aDataObject
to the set.- Parameters:
newData
- TheDataObject
to be added.- Throws:
praktikum.framework.data.InconsistentDimensionException
- ThisException
is thrown when the dimension of the object to be added does not fit the rest.praktikum.framework.data.InconsistentDimensionException
- See Also:
DataObject
-
addObject
public void addObject(DataSet dataSet) throws Exception
Adds all objects in the given data set- Parameters:
dataSet
-- Throws:
InconsistentDimensionException
Exception
- See Also:
addObject(moa.clusterers.outliers.AnyOut.util.DataObject)
-
getObject
public DataObject getObject(int index)
Returns theDataObject
at the given position. Use with care. For speedy operations after the data is collected usegetFeaturesAsArray()
.- Parameters:
index
- The index position that is to be returned.- Returns:
- The
DataObeject
at the given position. - See Also:
DataObject
-
size
public int size()
Returns the size of the set.- Returns:
- The size of the set.
-
getNrOfDimensions
public int getNrOfDimensions()
Return the dimension of the objects in theDataSet
. TheDataSet
makes sure all objects have the same dimension.- Returns:
- The dimension of the
DataObjects
in theDataSet
. - See Also:
DataObject
-
getNrOfClasses
public int getNrOfClasses()
Counts the number of classes that are present in the data set. !!! It does not check whether all classes are contained !!!- Returns:
- the number of distinct class labels
-
getFeaturesAsArray
public double[][] getFeaturesAsArray()
Returns an array with all the features of all the objects in the set. Be aware that it does not copy the features so that any changes to the values of the features in this array will result in changes in the initialDataObject
s.- Returns:
- A
double[][]
with the features. The first dimension is the feature number, the second the values in the feature. - See Also:
DataObject
-
getDataObjectArray
public DataObject[] getDataObjectArray()
Returns an array of all theDataObject
s in the set. Use for speedy access when the labels and/or the ids are also needed.- Returns:
- An array with all the
DataObject
s in the set. - See Also:
DataObject
-
getDataSetsPerClass
public DataSet[] getDataSetsPerClass() throws Exception
Separates the objects in this data set according to their class label- Returns:
- an array of DataSets, one for each class
- Throws:
Exception
-
getVariances
public double[] getVariances()
Calculates the variance of this data set for each dimension- Returns:
- double array containing the variance per dimension
-
iterator
public Iterator<DataObject> iterator()
An iterator for the set. This allows to use aforeach
loop over theDataObject
s. This is a nice way of going through the data, but when the access speed is relevant its use is not recommended.- Specified by:
iterator
in interfaceIterable<DataObject>
- Returns:
- An iterator for the set.
- See Also:
DataObject
-
toString
public String toString()
Returns aString
representation of all theDataObject
s in the code as a list of the representation implemented for these.- Overrides:
toString
in classObject
- Returns:
- A
String
representation of all the elements in the set. - See Also:
DataObject
-
manipulateIds
public void manipulateIds()
resets the ids, so that the set contains ids from 0 to noOfObjects-1
-
clear
public void clear()
-
-