SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.timeseries.univariate
Class GenericTimeTimeSeries<T extends java.lang.Comparable<T>>

java.lang.Object
  extended by com.numericalmethod.suanshu.stats.timeseries.univariate.GenericTimeTimeSeries<T>
Type Parameters:
T - the Comparable type
All Implemented Interfaces:
TimeSeries<T,java.lang.Double>

public class GenericTimeTimeSeries<T extends java.lang.Comparable<T>>
extends java.lang.Object
implements TimeSeries<T>

This is an implementation of a univariate time series indexed by some notion of time.

This implementation explicitly remembers all data in memory. It is appropriate for short time series.

GenericTimeTimeSeries is immutable.

See Also:
Wikipedia: Time series

Nested Class Summary
 class GenericTimeTimeSeries.Iterator
          the Iterator used to read a GenericTimeTimeSeries
 
Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.stats.timeseries.univariate.TimeSeries
TimeSeries.Entry<T>
 
Constructor Summary
GenericTimeTimeSeries(T[] timestamps, double[] values)
          Construct a GenericTimeTimeSeries from an array of timestamps and an array of values.
 
Method Summary
 GenericTimeTimeSeries<T> diff(int d)
          Create a new and independent GenericTimeTimeSeries by taking the first difference.
 GenericTimeTimeSeries<T> drop(int nItems)
          Create a new and independent GenericTimeTimeSeries by dropping the leading nItems entries, the most backward in time entries.
 boolean equals(java.lang.Object obj)
           
 double get(int index)
          Get the value at position index.
 int hashCode()
           
 GenericTimeTimeSeries.Iterator iterator()
          Get an Iterator to read this univariate time series.
 int size()
          the length of the time series
 T time(int index)
          Get the time at position index.
 T[] timestamps()
          Get all the timestamps.
 double[] toArray()
          Convert this time series into an array.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericTimeTimeSeries

public GenericTimeTimeSeries(T[] timestamps,
                             double[] values)
Construct a GenericTimeTimeSeries from an array of timestamps and an array of values.

The two arrays must be of the same length.

Parameters:
timestamps - an array of timestamps
values - an array of values
Method Detail

size

public int size()
Description copied from interface: TimeSeries
the length of the time series

Specified by:
size in interface TimeSeries<T extends java.lang.Comparable<T>,java.lang.Double>
Returns:
the size

iterator

public GenericTimeTimeSeries.Iterator iterator()
Description copied from interface: TimeSeries
Get an Iterator to read this univariate time series.

Specified by:
iterator in interface TimeSeries<T extends java.lang.Comparable<T>,java.lang.Double>
Returns:
an iterator

toArray

public double[] toArray()
Description copied from interface: TimeSeries
Convert this time series into an array.

Returns:
the array representation of the time series

get

public double get(int index)
Get the value at position index.

Parameters:
index - the position index
Returns:
the index-th value

time

public T time(int index)
Get the time at position index.

Parameters:
index - the position index
Returns:
the index-th timestamp

timestamps

public T[] timestamps()
Get all the timestamps.

Returns:
the timestamps

drop

public GenericTimeTimeSeries<T> drop(int nItems)
Create a new and independent GenericTimeTimeSeries by dropping the leading nItems entries, the most backward in time entries.

Parameters:
nItems - the number of leading entries to be dropped
Returns:
a new and independent time series

diff

public GenericTimeTimeSeries<T> diff(int d)
Create a new and independent GenericTimeTimeSeries by taking the first difference.

Parameters:
d - the number of differences
Returns:
diff(x, lag = 1, differences = d) as in R

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.