Git Product home page Git Product logo

pyhawkes's Introduction

PyHawkes implements a variety of Bayesian inference algorithms for discovering latent network structure given point process observations. Suppose you observe timestamps of Twitter messages, but you don't get to see how those users are connected to one another. You might infer that there is an unobserved connection from one user to another if the first user's activity tends to precede the second user's. This intuition is formalized by combining excitatory point processes (aka Hawkes processes) with random network models and performing Bayesian inference to discover the latent network.

Examples

We provide a number of classes for building and fitting such models. Let's walk through a simple example where we construct a discrete time model with three nodes, as in examples/discrete_demo. The nodes are connected via an excitatory network such that each event increases the likelihood of subsequent events on downstream nodes.

# Create a simple random network with K nodes a sparsity level of p
# Each event induces impulse responses of length dt_max on connected nodes
K = 3
p = 0.25
dt_max = 20
network_hypers = {"p": p, "allow_self_connections": False}
true_model = DiscreteTimeNetworkHawkesModelSpikeAndSlab(
    K=K, dt_max=dt_max, network_hypers=network_hypers)

# Generate T time bins of events from the the model
# S is the TxK event count matrix, R is the TxK rate matrix
S,R = true_model.generate(T=100)
true_model.plot()

You should see something like this. Here, each event on node one adds an impulse response on the rate of nodes two and three. True Model

Now create a test model and try to infer the network given only the event counts.

# Create the test model, add the event count data, and plot
test_model = DiscreteTimeNetworkHawkesModelSpikeAndSlab(
    K=K, dt_max=dt_max, network_hypers=network_hypers)
test_model.add_data(S)
fig, handles = test_model.plot(color="#e41a1c")

# Run a Gibbs sampler
N_samples = 100
lps = []
for itr in range(N_samples):
    test_model.resample_model()
    lps.append(test_model.log_probability())

    # Update plots
    test_model.plot(handles=test_handles)

If you enable interactive plotting, you should see something like this. Inferred Model

In addition to Gibbs sampling, we have implemented maximum a posteriori (MAP) estimation, mean field variational Bayesian inference, and stochastic variational inference. To see how those methods can be used, look in examples/inference.

Installation

For a basic (but lower performance) installation run

pip install pyhawkes

To install from source run

git clone [email protected]:slinderman/pyhawkes.git
cd pyhawkes
pip install -e .

This will be rather slow, however, since the default version does not do any multi-threading. For advanced installation instructions to support multithreading, see MULTITHREADING.md.

This codebase is considerably cleaner than the old CUDA version, and is still quite fast with the Cython+OMP extensions and joblib for parallel sampling of the adjacency matrix.

More Information

Complete details of this work can be found in:

Linderman, Scott W. and Adams, Ryan P. Discovering Latent Network Structure in Point Process Data. International Conference on Machine Learning (ICML), 2014.

and

Linderman, Scott W., and Adams, Ryan P. Scalable Bayesian Inference for Excitatory Point Process Networks. arXiv preprint arXiv:1507.03228, 2015.

pyhawkes's People

Contributors

dawsonv avatar jaworra avatar jayeshchoudhari avatar mpacer avatar slinderman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhawkes's Issues

clang-omp no longer supported

Not an expert on the matter, all I can say is that clang no longer supports openmp, so the MAC OSX instructions are no longer valid. Can't do 'brew install clang-omp' either.

Make GSL and OpenMP optional

A lot of people are having trouble installing due to the dependencies on GSL (via gslrandom package) and OpenMP. I think we can make both of these optional, but the user will suffer a serious performance hit.

Installation issues on MAC OS X Yosemite

I've tried to install your library on MAC OS X with Python 2.7.10 (Anaconda 2.1.0 (x86_64)) following your instruction but it appears that I've several issues trying various examples. One of which is about the method plotting.plotting which does not work.

$ python test_sbm_gibbs.py
Traceback (most recent call last):
File "test_sbm_gibbs.py", line 9, in
from pyhawkes.plotting.plotting import plot_network
ImportError: No module named plotting.plotting

Could you please tell me how to fix that ?

Thanks,
Guillaume.

AssertionError from gslrandom

Hello
I just installed pyhawkes.
When trying to run the discrete_model demo I run into the following error.
Any idea what is going wrong/ how to fix this?

for itr in xrange(N_samples):
... test_model.resample_model()
... lps.append(test_model.log_probability())
...
Traceback (most recent call last):
File "", line 2, in
File "/home/mihirkale.s/lib/python/pyhawkes/pyhawkes/models.py", line 1207, in resample_model
p.resample()
File "/home/mihirkale.s/lib/python/pyhawkes/pyhawkes/internals/parents.py", line 262, in resample
self._resample_Z_gsl()
File "/home/mihirkale.s/lib/python/pyhawkes/pyhawkes/internals/parents.py", line 255, in _resample_Z_gsl
multinomial(self.pyrngs, Sk, P, out=Zk)
File "gslrandom/gslrandom.pyx", line 114, in gslrandom.gslrandom.multinomial (gslrandom/gslrandom.cpp:3699)
assert isinstance(rng, PyRNG)
AssertionError

About problem"ImportError: cant import name 'logsumexp' from 'scipy.misc'"

Hi,I successfully install the pyhawkes from pip install, but when I start to import pyhawkes from the python, I got the error importerror: cant import name 'logsumexp' from 'scipy.misc'. And after I have already upgraded my scipy, it still appears,
And could you plz tell me that the code is python2 or python3?
My current env is python3

Code for Stock Market Data

Hi!
Thanks for your great Codes!
I was wondering where is the code for estimation of Net Hawkes with Gaussian Cox baseline? (The one which has been used for estimation of S&P data)

Clarification on a comment

Hi, first of all thank you for the great work. I was looking into your code and I need a clarification on a comment made at line 1425 in pyhawkes/models.py. Isn't that part referring to the initialisation of a Continuous Time Network Hawkes Model, instead of Discrete. Am I wrong?
Thank you for the clarification

code

Make PyHawkes installable on Windows

when i use

python setup.py build_ext --inplace

to install this package , error happens and the main part is :

writing build\temp.win-amd64-2.7\Release\pyhawkes\internals\continuous_time_helpers.def
c:\Rtools\mingw_32\bin\gcc.exe -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\pyhawkes\internals\continuous_time_helpers.o build\temp.win-amd64-2.7\Release\pyhawkes\internals\continuous_time_helpers.def -LC:\Users\hp\Anaconda2\libs -LC:\Users\hp\Anaconda2\PCbuild\amd64 -LC:\Users\hp\Anaconda2\PC\VS9.0\amd64 -lpython27 -lmsvcr90 -o C:\Users\hp\Desktop\pyhawkes-master\pyhawkes-master\pyhawkes\internals\continuous_time_helpers.pyd -fopenmp
C:\Users\hp\Anaconda2\libs/libpython27.dll.a: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
error: command 'c:\Rtools\mingw_32\bin\gcc.exe' failed with exit status 1

how can i solve this problem?

Multi-Threading resample seems not working for continuous process.

I have installed both gslrandom and enabled OpenPM support on my ubuntu 18.04 machine . But when I run resample using these code:

    def genHawkesModel(dates,ids):
        K = len(np.unique(ids))
        network_hypers = {"p":0.25,"allow_self_connections":False}
        model = ContinuousTimeNetworkHawkesModel(
                    K,
                    dt_max = 1,
                    network_hypers=network_hypers,
                )
        model.add_data(dates,ids,T=dates.max() + 1)
        return model

    hawkes_model = genHawkesModel(dates,ids)
    N_samples = len(np.unique(ids))
    hawkes_lls = [hawkes_model.log_likelihood()]
    logging.info("Start iterating")
    for itr in progprint_xrange(N_samples, perline=25):
        hawkes_model.resample_model()
        hawkes_lls.append(hawkes_model.log_likelihood())

I found this code is running too slow :

3c86d9744c4f3aa8b3ab644174878f2

I check the cpu usage using top command, finding that the program only using one cpu when resampling:

d3daecdcb35b85749675e88abf698a5

I'm sure I have install gslrandom on my machine (both pip and apt):
68e47ba8cc80348754d963f05d7079f

b77fdd67163229d441a1ba070a0d96c

I want to know how to make sure the resample process is running in the multi-threading mode so that I can do the resample as fast as possible.
Thank you and looking forward for your reply.

Updating examples

Hi, I just wanted to ask which parts of the examples "need to be updated":

def demo(seed=None):
    """
    Create a discrete time Hawkes model and generate from it.
    :return:
    """
raise NotImplementedError("This example needs to be updated.")

from

/examples/inference/standard_bfgs_demo.py

and other files.

Thanks in advance.

Python 3 support?

It looks like its just python2 compatible, if you're interested in making this python3 compatible (and it turns out to be as straightforward as it looks at first glance with only needing to tweak print statements), I'm happy to submit a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.