Skip to main content

Fast intensity inference

Project description

fast-intensity

authors: Thomas A. Lasko, Jacek Bajor

Overview

Fast density inference. Generates intensity curves from given events.

Installation

If you prefer to install a precompiled binary, we provide wheels for OS X and Linux (via the manylinux project). The basic pip install command line

$ pip install fast-intensity

should prefer one of our prebuilt binaries. Installation from source requires an environment with Cython and numpy preinstalled.

$ pip install cython numpy

Then you may install a release from source by specifying not to use a binary:

$ pip install fast-intensity --no-binary fast-intensity

(Yes, it is necessary to specify fast-intensity twice.) Alternately, to install the bleeding edge version:

$ git clone https://github.com/ComputationalMedicineLab/fast-intensity.git
$ cd fast-intensity
$ pip install -e .

Usage

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
from fast_intensity import FastIntensity

np.random.seed(42)

# Specify a series of 100 events spread over a year
days = np.arange(0, 365)
np.random.shuffle(days)
events = sorted(days[:100])

# Specify times (as reals) where we want to calculate the intensity of event occurrence
grid = np.linspace(1, 365, num=12)

# Configure a FastIntensity instance with the events and the grid
curve_builder = FastIntensity(events, grid)

# Generate the intensity curve - the unit is events per time unit
intensity = curve_builder.run_inference()
print(intensity)
#     array([0.38953   , 0.27764734, 0.33549508, 0.27285165, 0.22284481,
#            0.16997545, 0.26651725, 0.23580527, 0.23351076, 0.25272662,
#            0.33146159, 0.28486727])

plt.style.use('ggplot')
fig, ax = plt.subplots(figsize=(9,9))
ax.scatter(events, np.zeros(len(events)), alpha='0.4', label='Events')
ax.scatter(grid, np.zeros(len(grid)) + 0.025, label='Grid')
ax.plot(grid, intensity, label='Intensity')
plt.legend()
plt.show()

You can see how the intensity graph dips in the middle, where events are more thinly spaced, and rises near the beginning (where we have a high density of events).

figure

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast-intensity-0.2.tar.gz (34.2 kB view hashes)

Uploaded Source

Built Distributions

fast_intensity-0.2-cp37-cp37m-manylinux1_x86_64.whl (118.6 kB view hashes)

Uploaded CPython 3.7m

fast_intensity-0.2-cp37-cp37m-macosx_10_9_x86_64.whl (40.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

fast_intensity-0.2-cp36-cp36m-manylinux1_x86_64.whl (116.7 kB view hashes)

Uploaded CPython 3.6m

fast_intensity-0.2-cp35-cp35m-manylinux1_x86_64.whl (116.3 kB view hashes)

Uploaded CPython 3.5m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page