Class DataSet
- java.lang.Object
-
- java.util.AbstractCollection<DataPoint>
-
- net.sourceforge.openforecast.DataSet
-
public class DataSet extends java.util.AbstractCollection<DataPoint>
Represents a collection of data points. Data points are either observations of past data (including both the values of the independent variables and the observed value of the dependent variable), or forecasts or estimates of the dependent variable (for a given set of independent variable values).Generally when trying to forecast future values you'll use two data sets. The first data set contains all of the observations, or historical data. This data set is used to help initialize the selected forecasting model, the details of which depend on the specific forecasting model. A second data set is then created and initialized with data points describing the values of the independent variables that are to be used to predict or forecast values of the dependent variable.
When defining any data set it is important to provide as much information as possible about the data. While on the surface it may seem trivial, the more information you can provide about a data set (such as whether it is a time-based series, the name of the independent variable representing time, the number of data points/periods in a year), the better the forecasting model will be able to model the data. This is because some models need this type of data to even be applicable.
-
-
Constructor Summary
Constructors Constructor and Description DataSet()Constructs a new empty data set.DataSet(DataSet dataSet)Copy constructor: constructs a new data set object by copying the given data set.DataSet(java.lang.String timeVariable, int periodsPerYear, java.util.Collection<DataPoint> c)Constructs a new time-based data set with the named time variable, the given number of data points in a year, and the given Collection of data points.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(DataPoint obj)Adds the given data point object to this data set.booleanaddAll(java.util.Collection<? extends DataPoint> c)Adds a collection of data points to this data set.voidclear()Removes all of the data points from this data set.booleancontains(java.lang.Object obj)Returns true if this data set contains the given data point object; or false otherwise.booleancontainsAll(java.util.Collection<?> c)Returns true if this DataSet contains all of the DataPoints in the specified collection.booleanequals(DataSet dataSet)Indicates whether some other DataSet is "equal to" this one.booleanequals(java.lang.Object obj)Indicates whether some other object, obj, is "equal to" this one.java.lang.String[]getIndependentVariables()Returns an ordered array of all independent variable names used in this data set.intgetPeriodsPerYear()Returns the number of periods - or data points - in a years worth of data for time-series data.java.lang.StringgetTimeVariable()Returns the time variable associated with this data set, ornullif no time variable has been defined.inthashCode()Returns the hash code value for this collection, based on the underlying Collection of DataPoints.booleanisEmpty()Returns true if this data set contains no data points.java.util.Iterator<DataPoint>iterator()Returns an iterator over the data points in this data set.booleanremove(java.lang.Object obj)Removes a single instance of the specified data point object from this data set, if it is present.booleanremoveAll(java.util.Collection<?> c)Not currently implemented - always throws UnsupportedOperationException.booleanretainAll(java.util.Collection<?> c)Not currently implemented - always throws UnsupportedOperationException.voidsetPeriodsPerYear(int periodsPerYear)Sets the number of periods - or data points - in a years worth of data for time-series data.voidsetTimeVariable(java.lang.String timeVariable)Sets the name of the time variable for this data set.intsize()Returns the number of data points in this data set.voidsort(java.lang.String independentVariable)Sorts the given data set according to increasing value of the named independent variable.java.lang.StringtoString()Overrides the default toString method.
-
-
-
Constructor Detail
-
DataSet
public DataSet()
Constructs a new empty data set.
-
DataSet
public DataSet(DataSet dataSet)
Copy constructor: constructs a new data set object by copying the given data set.- Parameters:
dataSet- the data set to copy from to initialize the new data set.
-
DataSet
public DataSet(java.lang.String timeVariable, int periodsPerYear, java.util.Collection<DataPoint> c)Constructs a new time-based data set with the named time variable, the given number of data points in a year, and the given Collection of data points. This is equivalent to using the default constructor, then calling setTimeVariable, setPeriodsPerYear and addAll to initialize it.- Parameters:
timeVariable- the name of the independent variable representing time.periodsPerYear- the number of periods - data points - in one years worth of data.c- a Collection of data points to initialize this data set with.- See Also:
setTimeVariable(java.lang.String),setPeriodsPerYear(int),addAll(java.util.Collection<? extends net.sourceforge.openforecast.DataPoint>)
-
-
Method Detail
-
add
public boolean add(DataPoint obj)
Adds the given data point object to this data set.- Specified by:
addin interfacejava.util.Collection<DataPoint>- Overrides:
addin classjava.util.AbstractCollection<DataPoint>- Parameters:
obj- the data point object to add to this set.- Returns:
- true if this collection changed as a result of the call. This is consistent with the add method in the java.util.Collection class.
- Throws:
java.lang.ClassCastException- if the specified object does not implement the DataPoint interface.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
addAll
public boolean addAll(java.util.Collection<? extends DataPoint> c)
Adds a collection of data points to this data set. All elements of the collection must be DataPoints.- Specified by:
addAllin interfacejava.util.Collection<DataPoint>- Overrides:
addAllin classjava.util.AbstractCollection<DataPoint>- Parameters:
c- a collection of data points to add to this data set.- Returns:
- true if this collection changed as a result of the call. This is consistent with the add method in the java.util.Collection class.
-
clear
public void clear()
Removes all of the data points from this data set. This data set will be empty after this method returns unless it throws an exception.
-
isEmpty
public boolean isEmpty()
Returns true if this data set contains no data points. Otherwise returns false.
-
contains
public boolean contains(java.lang.Object obj)
Returns true if this data set contains the given data point object; or false otherwise. This data set is said to contain the given data point iffdataPoint.equals(dp)returns true for some DataPoint object,dp, within the set of data points.- Specified by:
containsin interfacejava.util.Collection<DataPoint>- Overrides:
containsin classjava.util.AbstractCollection<DataPoint>- Parameters:
obj- the data point object to search for in this data set.- Returns:
- true if this data set contains dataPoint.
- Throws:
java.lang.ClassCastException- if the specified object does not implement the DataPoint interface.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
containsAll
public boolean containsAll(java.util.Collection<?> c) throws java.lang.ClassCastException, java.lang.NullPointerExceptionReturns true if this DataSet contains all of the DataPoints in the specified collection.- Specified by:
containsAllin interfacejava.util.Collection<DataPoint>- Overrides:
containsAllin classjava.util.AbstractCollection<DataPoint>- Parameters:
c- collection to be checked for containment in this collection.- Returns:
- true if this DataSet contains all of the DataPoints in the specified collection.
- Throws:
java.lang.ClassCastException- if the types of one or more elements in the specified collection do not implement the DataPoint interface.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
remove
public boolean remove(java.lang.Object obj)
Removes a single instance of the specified data point object from this data set, if it is present. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).- Specified by:
removein interfacejava.util.Collection<DataPoint>- Overrides:
removein classjava.util.AbstractCollection<DataPoint>- Parameters:
obj- the data point object to remove from this data set.- Returns:
- true if this collection changed as a result of the call. This is consistent with the add method in the java.util.Collection class.
- Throws:
java.lang.ClassCastException- if the specified object does not implement the DataPoint interface.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
size
public int size()
Returns the number of data points in this data set. If this data contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
-
iterator
public java.util.Iterator<DataPoint> iterator()
Returns an iterator over the data points in this data set. There are no guarantees concerning the order in which the elements are returned.
-
sort
public void sort(java.lang.String independentVariable)
Sorts the given data set according to increasing value of the named independent variable. The initial implementation of this sort method appears a little cumbersome - it may be more efficient later to implement a small quicksort routine here instead.- Parameters:
independentVariable- the name of the independent variable to set by. The resulting data set will be sorted in increasing value of this variable.
-
getIndependentVariables
public java.lang.String[] getIndependentVariables()
Returns an ordered array of all independent variable names used in this data set. The array is guaranteed not to contain duplicate names.- Returns:
- a sorted array of unique independent variable names for this data set.
-
setTimeVariable
public void setTimeVariable(java.lang.String timeVariable)
Sets the name of the time variable for this data set. If this is not set, then the data set will be treated as being non time-based. In addition to setting the time variable for time series data, it is strongly recommended that you also initialize the number of periods per year with a call to setPeriodsPerYear.- Parameters:
timeVariable- the name of the independent variable that represents the time data component. For example, this may be something like "t", "month", "period", "year", and so on.- See Also:
setPeriodsPerYear(int)
-
getTimeVariable
public java.lang.String getTimeVariable()
Returns the time variable associated with this data set, ornullif no time variable has been defined.- Returns:
- the time variable associated with this data set.
-
setPeriodsPerYear
public void setPeriodsPerYear(int periodsPerYear)
Sets the number of periods - or data points - in a years worth of data for time-series data. If this is not set, then no seasonality effects will be considered when forecasting using this data set.In addition to setting the number of periods per year, you must also set the time variable otherwise any forecasting model will not be able to consider the potential effects of seasonality.
- Parameters:
periodsPerYear- the number of periods in a years worth of data.- See Also:
setTimeVariable(java.lang.String)
-
getPeriodsPerYear
public int getPeriodsPerYear()
Returns the number of periods - or data points - in a years worth of data for time-series data. If this has not been set, then a value of 0 will be returned.- Returns:
- the number of periods in a years worth of data.
-
removeAll
public boolean removeAll(java.util.Collection<?> c) throws java.lang.UnsupportedOperationExceptionNot currently implemented - always throws UnsupportedOperationException. Removes all this DataSet's elements that are also contained in the specified collection of DataPoint objects. After this call returns, this DataSet will contain no elements in common with the specified collection.- Specified by:
removeAllin interfacejava.util.Collection<DataPoint>- Overrides:
removeAllin classjava.util.AbstractCollection<DataPoint>- Parameters:
c- DataPoint objects to be removed from this collection.- Returns:
- true if this DataSet changed as a result of the call.
- Throws:
java.lang.UnsupportedOperationException- if the removeAll method is not supported by this collection.java.lang.ClassCastException- if the types of one or more elements in the specified DataSet are not DataPoint objects.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
retainAll
public boolean retainAll(java.util.Collection<?> c) throws java.lang.UnsupportedOperationExceptionNot currently implemented - always throws UnsupportedOperationException. Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.- Specified by:
retainAllin interfacejava.util.Collection<DataPoint>- Overrides:
retainAllin classjava.util.AbstractCollection<DataPoint>- Parameters:
c- elements to be retained in this collection.- Returns:
- true if this collection changed as a result of the call.
- Throws:
java.lang.UnsupportedOperationException- if the retainAll method is not supported by this collection.java.lang.ClassCastException- if the types of one or more elements in the specified DataSet are not DataPoint objects.java.lang.NullPointerException- if the specified collection contains one or more null elements.
-
hashCode
public int hashCode()
Returns the hash code value for this collection, based on the underlying Collection of DataPoints.- Specified by:
hashCodein interfacejava.util.Collection<DataPoint>- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this collection.
-
equals
public boolean equals(java.lang.Object obj)
Indicates whether some other object, obj, is "equal to" this one. Returns true if the Object, obj, represents another DataSet for whichequals(DataSet)returns true; otherwise false.- Specified by:
equalsin interfacejava.util.Collection<DataPoint>- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the reference object with which to compare.- Returns:
- true if this object is the same as the obj argument; false otherwise.
- See Also:
equals(DataSet)
-
equals
public boolean equals(DataSet dataSet)
Indicates whether some other DataSet is "equal to" this one. Returns true if the DataSet, dataSet, represents another DataSet containing exactly the same data points as this DataSet. Note that neither the DataPoint objects, or the DataSet objects have to refer to the same instance. They just must refer to a collection of DataPoints with the same values for the independent and dependent variables.- Parameters:
dataSet- the reference object with which to compare.- Returns:
- true if this object is the same as the dataSet argument; false otherwise.
-
toString
public java.lang.String toString()
Overrides the default toString method. Lists all data points in this data set. Note that if there are a large number of data points in this data set, then the String returned could be very long.- Overrides:
toStringin classjava.util.AbstractCollection<DataPoint>- Returns:
- a string representation of this data set.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG