Esempio n. 1
0
def test_to_empty():
    '''Valid empty creation test'''

    idx1 = np.array([], dtype='d')
    data1 = np.array([], dtype='d')
    
    ts1 = TimeSeries(idx1, data1)
    ts2 = TimeSeries(idx1.copy(), data1.copy())

    dataset = TimeSeriesDataset(np.asarray([ts1, ts2]))

    X = dataset.np_like_firstn()
    assert_array_equal(X, [[], []])
    
    X = dataset.np_like_lastn()
    assert_array_equal(X, [[], []])
Esempio n. 2
0
def test_to_empty():
    '''Valid empty creation test'''

    idx1 = np.array([], dtype='d')
    data1 = np.array([], dtype='d')

    ts1 = TimeSeries(idx1, data1)
    ts2 = TimeSeries(idx1.copy(), data1.copy())

    dataset = TimeSeriesDataset(np.asarray([ts1, ts2]))

    X = dataset.np_like_firstn()
    assert_array_equal(X, [[], []])

    X = dataset.np_like_lastn()
    assert_array_equal(X, [[], []])
Esempio n. 3
0
def test_to_numpy():
    '''Valid creation test'''

    idx1 = np.array([0, 1, 2, 3, 4], dtype='d')
    data1 = np.array([1.0, 2, 3, 4, 5], dtype='d')
    
    ts1 = TimeSeries(idx1, data1)

    idx2 = np.array([0, 1, 2, 3, 4, 5], dtype='d')
    data2 = np.array([1.0, 2, 3, 4, 8, 6], dtype='d')

    ts2 = TimeSeries(idx2, data2)

    dataset = TimeSeriesDataset(np.asarray([ts1, ts2]))

    X = dataset.np_like_firstn()
    assert_array_equal(X, [[1.0, 2, 3, 4, 5], [1.0, 2, 3, 4, 8]])
    
    X = dataset.np_like_lastn()
    assert_array_equal(X, [[1.0, 2, 3, 4, 5], [2, 3, 4, 8, 6]])
Esempio n. 4
0
def test_to_numpy():
    '''Valid creation test'''

    idx1 = np.array([0, 1, 2, 3, 4], dtype='d')
    data1 = np.array([1.0, 2, 3, 4, 5], dtype='d')

    ts1 = TimeSeries(idx1, data1)

    idx2 = np.array([0, 1, 2, 3, 4, 5], dtype='d')
    data2 = np.array([1.0, 2, 3, 4, 8, 6], dtype='d')

    ts2 = TimeSeries(idx2, data2)

    dataset = TimeSeriesDataset(np.asarray([ts1, ts2]))

    X = dataset.np_like_firstn()
    assert_array_equal(X, [[1.0, 2, 3, 4, 5], [1.0, 2, 3, 4, 8]])

    X = dataset.np_like_lastn()
    assert_array_equal(X, [[1.0, 2, 3, 4, 5], [2, 3, 4, 8, 6]])
Esempio n. 5
0
def test_iter():
    '''Iterates over the time series'''

    idx1 = np.array([0, 1, 2, 3, 4], dtype='d')
    data1 = np.array([1.0, 2, 3, 4, 5], dtype='d')

    ts1 = TimeSeries(idx1, data1)

    idx2 = np.array([0, 1, 2, 3, 4, 5], dtype='d')
    data2 = np.array([1.0, 2, 3, 4, 8, 6], dtype='d')

    ts2 = TimeSeries(idx2, data2)

    dataset = TimeSeriesDataset(np.asarray([ts1, ts2]))
    for i, timeseries in enumerate(dataset):
        if i == 0:
            assert_equal(5, len(timeseries))
        if i == 1:
            assert_equal(6, len(timeseries))

        if i > 1:
            raise Exception()
Esempio n. 6
0
def from_id_row_mat(matrix_fpath, skip_first_col=True, add_eps=0):
    '''
    Converts a file where each row composes of equally spaced time series
    observations. Moreover, all series have the same number of observations.
    The first row in the id of the time series, which will be ignored.
    
    Parameters
    ----------
    matrix_fpath : str 
        path to the matrix file
    skip_first_col : bool
        indicates that first column is an id which can be ignored
    add_eps : int (default=0)
        eps to add to each observatio
    
    Returns
    -------
    a time series dataset object
    '''
    X = np.genfromtxt(matrix_fpath, dtype='d')
    if X.ndim == 1:
        X = X[None]

    from_ = int(skip_first_col)
    X = X[:, from_:]
    X += add_eps

    n, f = X.shape
    tseries = []
    for i in xrange(n):
        idx = np.arange(f, dtype='d')
        data = X[i]

        ts = TimeSeries(idx, data)
        tseries.append(ts)

    return TimeSeriesDataset(np.asarray(tseries))