Last active
February 9, 2018 00:33
-
-
Save flaviovdf/16368fa9d2b896e23465461d6021717e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf8 | |
from hyperopt import fmin | |
from hyperopt import hp | |
from hyperopt import tpe | |
from tick.hawkes import HawkesADM4 | |
from tick.hawkes import HawkesCumulantMatching | |
from tick.hawkes import HawkesSumGaussians | |
import numpy as np | |
def run_cumulants(data): | |
def objective(h): | |
model = HawkesCumulantMatching(h, max_iter=300) | |
model.fit(data) | |
return model.objective(model.adjacency) | |
best = fmin(objective, | |
space=hp.uniform('h', 1, 100), | |
algo=tpe.suggest, | |
max_evals=20) | |
half_width = best['h'] | |
model = HawkesCumulantMatching(half_width, max_iter=300, verbose=True) | |
model.fit(data) | |
return model.adjacency | |
def run_adm4(data): | |
def objective(d): | |
model = HawkesADM4(d, max_iter=300, n_threads=20) | |
model.fit(data) | |
return -model.score() | |
best = fmin(objective, | |
space=hp.uniform('d', 1e-2, 1e2), | |
algo=tpe.suggest, | |
max_evals=20) | |
decay = best['d'] | |
model = HawkesADM4(decay, max_iter=300, n_threads=20, verbose=True) | |
model.fit(data) | |
return model.adjacency | |
def run_sumgauss(data): | |
model = HawkesSumGaussians(10, n_threads=20, max_iter=300, verbose=True) | |
model.fit(data) | |
return model.amplitudes.mean(axis=2) | |
paths = ['ticks_top100.dat', 'ticks_top500.dat'] | |
methods = [run_adm4, run_sumgauss, run_cumulants] | |
for p in paths: | |
realizations = [] | |
with open(p) as in_file: | |
for line in in_file: | |
spl = line.split() | |
realizations.append([np.array([float(x) for x in spl[1:]])]) | |
for m in methods: | |
name = m.__name__ | |
np.savez_compressed(name + '-' + p + '.npz', G=m(realizations)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment