Skip to main content

Cluster-based Superposed Marked Hawkes Process

Project description

CSMHP

This package is an implementation of:
Cluster-based Superposed Marked Hawkes Process (CIBer)

The CSMHP package implements a novel Hawkes process model in PyTorch for modeling event sequence with high dimension of covariates, especially categorical ones. This model is useful in various fields such as finance, healthcare, and cyber-risk analysis, where temporal event sequences need to be modeled and analyzed. The package allows training a Hawkes process with clustering-based probability estimates.

Features

  • Hawkes Process Model: A self-exciting point process that models events whose intensity is influenced by prior events.
  • Clustering Model Integration: Integrates clustering algorithms to infer event type probabilities.
  • Parameter Optimization: Supports optimization of the model parameters (mu, gamma, alpha_kernel, beta_kernel) using gradient-based methods.
  • Event Simulation: Implements the thinning algorithm for simulating future event times based on the trained model.
  • Mini-batch Optimization: Option for mini-batch optimization to handle large datasets efficiently.

Installation

To install the CSMHP package, you can use pip:

pip install CSMHP

```python
import torch
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from CSMHP import CSM_Hawkes

# Initialize parameters
T = 1000  # Length of observation window
num_clusters = 3  # Number of event clusters
params = None  # Optionally provide initial parameters
X_train = np.random.rand(100, 5)  # Example training data with 100 events and 5 features
y_train = np.random.randint(0, num_clusters, size=100)

# Define a clustering model (e.g., KMeans)
cluster_model = RandomForestClassifier(n_estimators=50, max_depth=2)
cluster_model.fit(X_train, y_train)
probability = cluster_model.predict(X_train)

# Initialize CSM_Hawkes model
hawkes_model = CSMHP(T=T, num_clusters=num_clusters, params=params, 
                          model=cluster_model, X_train=X_train, step=0.01, unit='Week')

# Fit the model (train the probability and parameters)
event_times = np.random.rand(100) * T  # Example event times
hawkes_model.fit_param(event_times, probability epoch=20)
hawkes_model.fit_prob(event_times, probability, step=0.5, epoch=5)
hawkes_model.fit_param(event_times, None, epoch=20)
hawkes_model.fit_prob(event_times, None, step=0.5, epoch=5)
hawkes_model.fit_param(event_times, None, epoch=10)

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

csmhp-0.0.7.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

CSMHP-0.0.7-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file csmhp-0.0.7.tar.gz.

File metadata

  • Download URL: csmhp-0.0.7.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for csmhp-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f1077cfdb4c2fa0bfd1dd4714550283c7015215d5bf9ad6ebf3a80203541ae5a
MD5 4b68a317cc2533951571cf7af3b35983
BLAKE2b-256 2a59afcf573f56f89f1c3e5c8e2e4cdbdc2556e7fc6c2f6bf974ed5bd78e30eb

See more details on using hashes here.

File details

Details for the file CSMHP-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: CSMHP-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for CSMHP-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 95669b9e98ae16ffacf20e0a624a51944c3d73850efb25dc727b8ec7f24ec756
MD5 784da872c06f1ff4c4a7d5955299361d
BLAKE2b-256 f5d2279b9830128de5fe2e03725f5a731c71936d5d116e1a497f2fede8bf16dd

See more details on using hashes here.

Supported by

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