Skip to content

Instantly share code, notes, and snippets.

@flaviovdf
Last active February 9, 2018 00:32
Show Gist options
  • Save flaviovdf/258a23741d53d02282c81f096edce747 to your computer and use it in GitHub Desktop.
Save flaviovdf/258a23741d53d02282c81f096edce747 to your computer and use it in GitHub Desktop.
#-*- 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
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']
print(decay)
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.baselines.mean(axis=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment