Exemplo n.º 1
0
def stand(x, m, s):
    '''Standardize timeseries x by mean m and std deviation s

    Args: 
    x: Timeseries that is beign standardized
    m: Mean of the timeseries after standardization
    s: Standard deviation of the timeseries after standardization

    Output:
    A timeseries with mean 0 and standard deviation 1
    '''
    vals = np.array(list(iter(x)))
    vals = (vals - m) / s
    return ts.TimeSeries(vals, list(x.itertimes()))
Exemplo n.º 2
0
Returns (Prints):
#### Nearest Timeseries ####
tsdata/ts398.dat


Requires folder:
tsdb

'''

if __name__ == "__main__":
    # Load in the TS to Evaluate
    filename = sys.argv[1]
    x = np.loadtxt(filename, delimiter=' ')
    origTs = ts.TimeSeries(x[:,1],x[:,0])
    time = np.arange(0.0, 1.0, 0.01)
    testTs = origTs.interpolate(time)

    # Find the Nearest vantagePt
    minDist = float('inf')
    for j in range(20):
        dbName = "tsdb/db"+str(j)+".dbdb"
        db = lab10.connect(dbName)
        vantagePtFile = db.get(0)
        x = np.loadtxt(vantagePtFile, delimiter=' ')
        comparePt = ts.TimeSeries(x[:,1],x[:,0])
        dist = 2*(1-ss.kernel_corr(comparePt,testTs))
        if dist < minDist:
            minDist = dist
            minDbName = dbName
Exemplo n.º 3
0
'''

if __name__ == "__main__":

    indexes = np.random.choice(1000, 20, replace=False)
    vantagePtList = []
    dbList = []

    #Create TS Referencing
    #The 20 randomally selected vantagePtFiles
    for j in range(20):
        fileName = 'tsdata/ts' + str(indexes[j]) + '.dat'
        dbName = "tsdb/db" + str(j) + ".dbdb"
        x = np.loadtxt(fileName, delimiter=' ')
        vantagePt = ts.TimeSeries(x[:, 1], x[:, 0])
        vantagePtList.append(vantagePt)
        ##Remove DB if it has previously been created
        if os.path.exists(dbName):
            os.remove(dbName)

        # Connect to Databses
        db = lab10.connect(dbName)
        dbList.append(db)

    #For all 20 Databases
    #Loop through 1000 TimeSeries
    #Add Key = Distance(vantagePt, comparePt)
    #Value = comparePT's fileName
    for i in range(1000):
        fileName = 'tsdata/ts' + str(i) + '.dat'
Exemplo n.º 4
0
def test_kernel_corr():
    ts1 = ts.TimeSeries([0, 1, 2, 3, 4, 3, 2, 1, 0],
                        [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ts2 = ts.TimeSeries([1, 2, 3, 4, 3, 2, 1, 0, 0],
                        [1, 2, 3, 4, 5, 6, 7, 8, 9])
    assert abs(kernel_corr(ts1, ts2, 10) - 1) < 1e-3
Exemplo n.º 5
0
def test_maxccor():
    ts1 = ts.TimeSeries([0, 1, 2, 3, 4, 3, 2, 1, 0],
                        [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ts2 = ts.TimeSeries([1, 2, 3, 4, 3, 2, 1, 0, 0],
                        [1, 2, 3, 4, 5, 6, 7, 8, 9])
    assert abs(max_corr_at_phase(ts1, ts2)[1] - 1.0) < 1e-5
Exemplo n.º 6
0
def test_self_maxccor():
    ts1 = ts.TimeSeries([100, 101, 102, 103], [1, 2, 3, 4])
    assert max_corr_at_phase(ts1, ts1)[1] == 1.0
Exemplo n.º 7
0
def test_stand():
    ts1 = ts.TimeSeries([100, 101, 102, 103], [1, 2, 3, 4])
    ts1_stand = stand(ts1, np.mean([100, 101, 102, 103]),
                      np.std([100, 101, 102, 103]))
    assert np.std(list(iter(ts1_stand))) == 1.0
Exemplo n.º 8
0
def random_ts(a):
    t = np.arange(0.0, 1.0, 0.01)
    v = a * np.random.random(100)
    return ts.TimeSeries(v, t)
Exemplo n.º 9
0
def tsmaker(m, s, j):
    t = np.arange(0.0, 1.0, 0.01)
    v = norm.pdf(t, m, s) + j * np.random.randn(100)
    return ts.TimeSeries(v, t)