Coder Social home page Coder Social logo

antixk / sgmrfmix Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 12.1 MB

A Python library for sGMRFmix model for anomaly detection in time series

License: MIT License

CMake 0.77% C++ 25.72% Python 5.04% Makefile 0.27% Shell 1.17% Jupyter Notebook 67.04%
anomaly-detection time-series machine-learning sparse-representations sparse-modeling graphical-lasso variational-bayes python3 cpp sgmrfmix

sgmrfmix's Introduction

sGMRFmix

Build Status

Python library for sGMRFmix model for anomaly detection in time-series data. sGMRFmix is short for sparse mixture of Gaussian Markov Random Fields. This is essentially a C++ (and python) port of the R package sGMRFmix to make it run faster for larger datasets.

Model Overview

sGMRFmix is a mixture of GMRFs that predict the likelihood of a random variable using the variables in its markov blanket. Lower the log likelihood, higher the anomaly score. The markov blanket is estimated using a Gaussian graphical model with constraint that enforces sparsity in the inverse covariance matrices of the mixture of GMRF model. This can be done in a stright-forward manner using Graphical LASSO model. You can check out the paper for further details and the math.

sGMRFmix Model

Performance Comparison

The follwing plot shows the performance comparison with the only sGMRFmix library available publicaly in R language.

sGMRFmix Model

Installation

Requirements

  • Python >= 3.6 (For Python Thread-Specific-Storage (TSS) API used by pybind11)
  • Numpy >= 1.16.5

Binaries

Check out the releases of this repo for wheels for various platforms. Install the wheel using pip inside your python environment.

pip install sgmrfmix-<platform/other tags>.whl

Build from source

For Linux

sudo apt-get update
sudo apt-get install libopenblas-dev liblapack-dev libarpack2-dev libsuperlu-dev
sudo apt install libarmadillo-dev libboost-all-dev build-essential

For Mac

brew install cmake pkg-config boost openblas 
brew install armadillo 

Clone the repository (including the pybind11 submodule) into a suitable directory

git clone --recursive [email protected]:AntixK/sGMRFmix.git
cd sGMRFmix

Build the C++ files

cd build
cmake ..
make

Install requirements and build the library. Optionally create a python virtual environment to install the library.

cd ..
pip install -r requirements.txt
python setup.py install

pip install auditwheel
auditwheel show dist/sgmrfmix-0.1-cp37-cp37m-linux_x86_64.whl
auditwheel repair --plat linux_x86_64  dist/sgmrfmix-0.1-cp37-cp37m-linux_x86_64.whl

## Usage
```python
import numpy as np
from sgmrfmix import sGMRFmix

m = sGMRFmix(K = 5, rho=0.8)
train = np.genfromtxt('train.csv', delimiter=',', skip_header=True)[:, 1:]
test = np.genfromtxt('test.csv', delimiter=',', skip_header=True)[:, 1:]

m.fit(train)
m.show_model_params()
results = m.compute_anomaly(test)

Check out further examples in the Examples/ folder.

Acknowledgements

sgmrfmix's People

Contributors

antixk avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.