コード例 #1
0
# Load test data
data = datasets.loadDatasets(dataset, 'interval')

# Try different thresholds for interval proposing
results = OrderedDict()
for propmeth in PROPMETHODS:
    results[propmeth] = OrderedDict()
    for sd_th in THS:
        ygts = []
        regions = []
        
        for ftype in data:
            for func in data[ftype]:
                ygts.append(func['gt'])
                ts = preproc.normalize_time_series(func['ts'])
                if td_dim > 1:
                    ts = preproc.td(ts, td_dim, td_lag)
                regions.append(list(pointwiseRegionProposals(ts, method = propmeth, sd_th = sd_th,
                                                             extint_min_len = 10, extint_max_len = extint_max_len)))
            
        results[propmeth][sd_th] = eval.recall_precision(ygts, regions, multiAsFP = False)


# Print results as table
labels = ('Recall', 'Precision', 'F1-Score')
hdiv_len = 5 + sum(len(lbl) + 3 for lbl in labels) # length of horizontal divider

for propmeth, res in results.items():
    print('\n-- {} --\n'.format(propmeth))
コード例 #2
0
    print('Period of {}. right singular vector: {} -> {}'.format(i+1, period, float(minSVDLen) / period))
plt.show()
# Remove some leading singular values
try:
    rsRem = raw_input('Enter number of right-singular vectors to remove: ')
except:
    rsRem = input('Enter number of right-singular vectors to remove: ')
rsRem = int(rsRem)
mm_s[:rsRem] = 0.0
mm_norm = mm_u.dot(np.diag(mm_s).dot(mm_vt))
"""

# Individual De-seasonalization by DFT, Hourly Z Score and OLS
print('-- DFT, Hourly Z Score, OLS --')
for id in ids:
    func = preproc.normalize_time_series(data[id]['ts']).ravel()

    # Search non-trivial peak in power-spectrum
    freq = np.fft.fft(func)
    ps = (freq * freq.conj()).real
    ps[0] = 0
    th = np.mean(ps) + 3 * np.std(ps)
    period = (ps > th)
    period[0:7] = False
    period[-6:] = False
    period_ind = np.where(period)[0]
    print('{}: period = {} -> {}'.format(
        id, period_ind[:len(period_ind) // 2],
        periods2time(period_ind[:len(period_ind) // 2], len(func))))

    # Remove seasonal frequency and reconstruct deseasonalized time series
コード例 #3
0
        a = datetime.datetime.combine(a, datetime.datetime.min.time())
    if isinstance(b, datetime.date):
        b = datetime.datetime.combine(b, datetime.datetime.min.time())

    return int((a - b).total_seconds()) / 3600


if __name__ == '__main__':

    import sys
    method = sys.argv[1] if len(sys.argv) > 1 else 'gaussian_cov_ts'
    propmeth = sys.argv[2] if len(sys.argv) > 2 else 'dense'

    # Load data
    data, dates = read_hpw_csv('HPW_2012_41046.csv')
    data = preproc.normalize_time_series(data)

    # Detect
    if method in ['hotellings_t', 'kde']:
        if method == 'kde':
            scores = baselines_noninterval.pointwiseKDE(preproc.td(data))
        else:
            scores = baselines_noninterval.hotellings_t(preproc.td(data))
        regions = baselines_noninterval.pointwiseScoresToIntervals(scores, 24)
    elif method == 'gaussian_cov_ts':
        regions = maxdiv.maxdiv(data,
                                'gaussian_cov',
                                mode='TS',
                                td_dim=3,
                                td_lag=1,
                                proposals=propmeth,