All Projects → NetManAIOps → Donut

NetManAIOps / Donut

WWW 2018: Unsupervised Anomaly Detection via Variational Auto-Encoder for Seasonal KPIs in Web Applications

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Donut

algoexpert-data-structures-algorithms
A collection of solutions for all problem statements on the AlgoExpert Coding Interview platform.
Stars: ✭ 134 (-57.19%)
Mutual labels:  code
Hacktoberfest-2021
This repository aims to help code beginners with their first successful pull request and open source contribution. 🥳🎯🚀
Stars: ✭ 24 (-92.33%)
Mutual labels:  code
Awesome Woocommerce
Plugins and code snippets to improve your WooCommerce store.
Stars: ✭ 279 (-10.86%)
Mutual labels:  code
riblet-sample
A sample to represent Uber Riblets design pattern using Swift.
Stars: ✭ 42 (-86.58%)
Mutual labels:  code
SharpLoader
🔮 [C#] Source code randomizer and compiler
Stars: ✭ 36 (-88.5%)
Mutual labels:  code
snakefmt
The uncompromising Snakemake code formatter
Stars: ✭ 78 (-75.08%)
Mutual labels:  code
fake-news-detection
This repo is a collection of AWESOME things about fake news detection, including papers, code, etc.
Stars: ✭ 34 (-89.14%)
Mutual labels:  code
Javacodeaudit
Getting started with java code auditing 代码审计入门的小项目
Stars: ✭ 289 (-7.67%)
Mutual labels:  code
BlazorMonaco
Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
Stars: ✭ 151 (-51.76%)
Mutual labels:  code
Code To Image
Convert blocks of code to a highlighted jpeg base64 image.
Stars: ✭ 271 (-13.42%)
Mutual labels:  code
Awesome-Deepfakes-Detection
A list of tools, papers and code related to Deepfake Detection.
Stars: ✭ 30 (-90.42%)
Mutual labels:  code
gfm-code-blocks
Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string.
Stars: ✭ 20 (-93.61%)
Mutual labels:  code
laravel-markdown
A highly configurable markdown renderer and Blade component for Laravel
Stars: ✭ 159 (-49.2%)
Mutual labels:  code
CodeAndQuestsEveryDay
Regular research on the Quest for developers.
Stars: ✭ 27 (-91.37%)
Mutual labels:  code
Cheatsheetseries
The OWASP Cheat Sheet Series was created to provide a concise collection of high value information on specific application security topics.
Stars: ✭ 19,302 (+6066.77%)
Mutual labels:  code
larapos
Laravel Point of sale with invoice full source code free download pos apps.
Stars: ✭ 38 (-87.86%)
Mutual labels:  code
lowcode
React Lowcode - prototype, develop and maintain internal apps easier
Stars: ✭ 32 (-89.78%)
Mutual labels:  code
Updated Carbanak Source With Plugins
https://twitter.com/itsreallynick/status/1120410950430089224
Stars: ✭ 303 (-3.19%)
Mutual labels:  code
Nodebook
📖 Livre publié aux Éditions Eyrolles • Première édition : Node.js v10 et npm v6.
Stars: ✭ 286 (-8.63%)
Mutual labels:  code
Vue Code Diff
vue文件差异对比
Stars: ✭ 271 (-13.42%)
Mutual labels:  code

DONUT

.. image:: https://travis-ci.org/haowen-xu/donut.svg?branch=master :target: https://travis-ci.org/haowen-xu/donut .. image:: https://coveralls.io/repos/github/haowen-xu/donut/badge.svg?branch=master :target: https://coveralls.io/github/haowen-xu/donut?branch=master

Donut is an anomaly detection algorithm for seasonal KPIs.

Citation

.. code-block:: bibtex

@inproceedings{donut,
  title={Unsupervised Anomaly Detection via Variational Auto-Encoder for Seasonal KPIs in Web Applications},
  author={Xu, Haowen and Chen, Wenxiao and Zhao, Nengwen and Li, Zeyan and Bu, Jiahao and Li, Zhihan and Liu, Ying and Zhao, Youjian and Pei, Dan and Feng, Yang and others},
  booktitle={Proceedings of the 2018 World Wide Web Conference on World Wide Web},
  pages={187--196},
  year={2018},
  organization={International World Wide Web Conferences Steering Committee}
}

Dependencies

TensorFlow >= 1.5

Installation

Checkout this repository and execute:

.. code-block:: bash

pip install git+https://github.com/thu-ml/zhusuan.git
pip install git+https://github.com/haowen-xu/[email protected]
pip install .

This will first install ZhuSuan <https://github.com/thu-ml/zhusuan>_ and TFSnippet <https://github.com/haowen-xu/tfsnippet>_, the two major dependencies of Donut, then install the Donut package itself.

API Usage

To prepare the data:

.. code-block:: python

import numpy as np
from donut import complete_timestamp, standardize_kpi

# Read the raw data.
timestamp, values, labels = ...
# If there is no label, simply use all zeros.
labels = np.zeros_like(values, dtype=np.int32)

# Complete the timestamp, and obtain the missing point indicators.
timestamp, missing, (values, labels) = \
    complete_timestamp(timestamp, (values, labels))

# Split the training and testing data.
test_portion = 0.3
test_n = int(len(values) * test_portion)
train_values, test_values = values[:-test_n], values[-test_n:]
train_labels, test_labels = labels[:-test_n], labels[-test_n:]
train_missing, test_missing = missing[:-test_n], missing[-test_n:]

# Standardize the training and testing data.
train_values, mean, std = standardize_kpi(
    train_values, excludes=np.logical_or(train_labels, train_missing))
test_values, _, _ = standardize_kpi(test_values, mean=mean, std=std)

To construct a Donut model:

.. code-block:: python

import tensorflow as tf
from donut import Donut
from tensorflow import keras as K
from tfsnippet.modules import Sequential

# We build the entire model within the scope of `model_vs`,
# it should hold exactly all the variables of `model`, including
# the variables created by Keras layers.
with tf.variable_scope('model') as model_vs:
    model = Donut(
        h_for_p_x=Sequential([
            K.layers.Dense(100, kernel_regularizer=K.regularizers.l2(0.001),
                           activation=tf.nn.relu),
            K.layers.Dense(100, kernel_regularizer=K.regularizers.l2(0.001),
                           activation=tf.nn.relu),
        ]),
        h_for_q_z=Sequential([
            K.layers.Dense(100, kernel_regularizer=K.regularizers.l2(0.001),
                           activation=tf.nn.relu),
            K.layers.Dense(100, kernel_regularizer=K.regularizers.l2(0.001),
                           activation=tf.nn.relu),
        ]),
        x_dims=120,
        z_dims=5,
    )

To train the Donut model, and use a trained model for prediction:

.. code-block:: python

from donut import DonutTrainer, DonutPredictor

trainer = DonutTrainer(model=model, model_vs=model_vs)
predictor = DonutPredictor(model)

with tf.Session().as_default():
    trainer.fit(train_values, train_labels, train_missing, mean, std)
    test_score = predictor.get_score(test_values, test_missing)

To save and restore a trained model:

.. code-block:: python

from tfsnippet.utils import get_variables_as_dict, VariableSaver

with tf.Session().as_default():
    # Train the model.
    ...

    # Remember to get the model variables after the birth of a
    # `predictor` or a `trainer`.  The :class:`Donut` instances
    # does not build the graph until :meth:`Donut.get_score` or
    # :meth:`Donut.get_training_loss` is called, which is
    # done in the `predictor` or the `trainer`.
    var_dict = get_variables_as_dict(model_vs)

    # save variables to `save_dir`
    saver = VariableSaver(var_dict, save_dir)
    saver.save()

with tf.Session().as_default():
    # Restore variables from `save_dir`.
    saver = VariableSaver(get_variables_as_dict(model_vs), save_dir)
    saver.restore()

If you need more advanced outputs from the model, you may derive the outputs by using model.vae directly, for example:

.. code-block:: python

from donut import iterative_masked_reconstruct

# Obtain the reconstructed `x`, with MCMC missing data imputation.
# See also:
#   :meth:`donut.Donut.get_score`
#   :func:`donut.iterative_masked_reconstruct`
#   :meth:`tfsnippet.modules.VAE.reconstruct`
input_x = ...  # 2-D `float32` :class:`tf.Tensor`, input `x` windows
input_y = ...  # 2-D `int32` :class:`tf.Tensor`, missing point indicators
               # for the `x` windows
x = model.vae.reconstruct(
    iterative_masked_reconstruct(
        reconstruct=model.vae.reconstruct,
        x=input_x,
        mask=input_y,
        iter_count=mcmc_iteration,
        back_prop=False
    )
)
# `x` is a :class:`tfsnippet.stochastic.StochasticTensor`, from which
# you may derive many useful outputs, for example:
x.tensor  # the `x` samples
x.log_prob(group_ndims=0)  # element-wise log p(x|z) of sampled x
x.distribution.log_prob(input_x)  # the reconstruction probability
x.distribution.mean, x.distribution.std  # mean and std of p(x|z)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].