Git Product home page Git Product logo

bayesiantimeseries's Introduction

Bayesian Time Series Models

Slowly building out methods for doing hierarchical Bayesian inference and prediction for time series data. As it stands, this project is mostly borrowing from TimeSeers in Python and Facebook's prophet.

Features

Define a time series model as a sum or product of individual components. For example, we may wish to decompose a time series as a piecewise linear trend plus seasonality (in terms of a Fourier series). For a given number of change-points and Fourier modes, we can define for our model as

model = LinearTrend(n_change_points) + FourierSeasonality(n_F_nodes)

For trend models with change points, we can additionally specific where these change points are located. When passed with parameters, these models are able to evaluated directly over a time horizon

X = model(theta, times)

Given time series values data and time values time, we can then sample from the posterior distribution of the above model given our data as follows using Stan.

samples, cnames = sample_stan(model, times, data;  num_samples)

TODO: Instructions for sampling from the chain and doing posterior predictive analysis. Then add forecasting. TODO: The current methods for this are get_beta()

Time Series Nodes

This package is built on the idea of decomposing time series in terms of time series nodes. We define several types of time series nodes. By combining individual time series nodes using addition, one can model a time series as a combination of various components defined as trends, seasonality, or other.

Current Components

Currently, we have implemented several components:

A piecewise linear trend model parameterized by the number of change points. This model takes in slopes for each of the n_change_points change points which will evenly space the change points between 0 and max_T.

LinearTrend(n_change_points, max_T)

Alternatively, we can directly pass the change points to the model component as a vector s

LinearTrend(s)

Similarly, we include components for piecewise constant trends ConstantTrend and a FlatTrend. Note that the Linear and Constant trends start at 0, so in order to have a non-zero starting position you must use both FlatTrend and ConstantTrend.

A seasonality component built from Fourier series which is parameterized by the number of Fourier nodes and the seasonality's period

FourierSeasonality(n_F_nodes, period)

You can also specify additional regressors in the form of

AdditionalRegressor(regressors) 

where regressors is a 2-D array with each column being a separate component.

Least Squares

If you're not feeling particularly Bayesian, this package also has support for simple least squares solutions which can be found by doing the following

X = get_design(model, time)
beta  = X \ data
Y_hat = X * beta

Planned Components

  • RadialBasisSeasonality(n_nodes, period)
  • HolidayEffect(days_of_year)

To do

  • Implement pooling and partial pooling for joint inference of time series
  • Implement RadialBasisSeasonality -[x] Work on a method for inference using Stan and CmdStan.jl
  • Work on a method for inference using AdvancedHMC.jl
  • Add explicit support for lack of times and Vector(Date). -[x] Add support for least squares fit using \.

bayesiantimeseries's People

Contributors

marlinfiggins avatar

Stargazers

Owain  gaunders avatar Sam Abbott avatar

Watchers

 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.