Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Python package for fast and flexible univariate trend filtering

License

Notifications You must be signed in to change notification settings

jiapivialiu/trendfilter-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trendfilter

License: MIT Python 3.8+

Python package for fast and flexible univariate trend filtering with C++ backend for high performance.

Overview

Trend filtering is a method for nonparametric regression that fits a piecewise polynomial function to data. This package provides efficient implementations of trend filtering algorithms with the following features:

  • Fast C++ backend: High-performance implementations using modern C++
  • Python interface: Easy-to-use Python API built with pybind11
  • Flexible algorithms: Support for different orders of trend filtering
  • Cross-validation: Built-in cross-validation for parameter selection
  • Efficient solvers: Optimized linear system solvers for large datasets

Installation

From GitHub

pip install git+https://github.com/jiapivialiu/trendfilter-py.git

From source

git clone https://github.com/jiapivialiu/trendfilter-py.git
cd trendfilter-py
pip install .

Quick Start

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from trendfilter import TrendFilter, CVTrendFilter

# Generate sample data
n = 100
x = np.linspace(0, 1, n)
true_signal = np.sin(2 * np.pi * x) + 0.5 * np.cos(4 * np.pi * x)
y = true_signal + 0.2 * np.random.randn(n)

# Fit trend filter
tf = TrendFilter(order=2, lambda_reg=0.1)
tf.fit(y)
y_fit = tf.predict()

# Cross-validation for parameter selection
cv_tf = CVTrendFilter(order=2)
cv_tf.fit(y)
y_fit_cv = cv_tf.predict()

Check out the README_plot script or the basic_usage for visualizing the output. Preview of the output as below:

Quick Start figure

Features

Core Algorithms

  • Trend Filtering: Fast implementation of univariate trend filtering
  • Cross-Validation: Automated parameter selection via cross-validation
  • Multiple Orders: Support for different polynomial orders (0, 1, 2, ...)

Performance

  • C++ Backend: High-performance C++ implementations
  • Efficient Solvers: Specialized linear system solvers
  • Memory Optimized: Efficient memory usage for large datasets

Requirements

  • Python >= 3.7
  • NumPy >= 1.18.0
  • SciPy >= 1.5.0

About

Python package for fast and flexible univariate trend filtering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published