pwlf

fit piecewise linear data for a specified number of line segments

https://github.com/cjekel/piecewise_linear_fit_py

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.6%) to scientific vocabulary

Keywords

numpy piecewise-linear piecewise-regression python scipy segment segmented tensorflow
Last synced: 6 months ago · JSON representation

Repository

fit piecewise linear data for a specified number of line segments

Basic Info
  • Host: GitHub
  • Owner: cjekel
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 15.6 MB
Statistics
  • Stars: 337
  • Watchers: 8
  • Forks: 63
  • Open Issues: 42
  • Releases: 10
Topics
numpy piecewise-linear piecewise-regression python scipy segment segmented tensorflow
Created almost 9 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License

README.md

About

A library for fitting continuous piecewise linear functions to data. Just specify the number of line segments you desire and provide the data.

Downloads a month pwlf ci codecov PyPI version Conda

Check out the documentation!

Read the blog post.

Example of a continuous piecewise linear fit to data.

Example of a continuous piecewise linear fit to a sine wave.

Now you can perform segmented constant fitting and piecewise polynomials! Example of multiple degree fits to a sine wave.

Features

For a specified number of line segments, you can determine (and predict from) the optimal continuous piecewise linear function f(x). See this example.

You can fit and predict a continuous piecewise linear function f(x) if you know the specific x locations where the line segments terminate. See this example.

If you want to pass different keywords for the SciPy differential evolution algorithm see this example.

You can use a different optimization algorithm to find the optimal location for line segments by using the objective function that minimizes the sum of square of residuals. See this example.

Instead of using differential evolution, you can now use a multi-start gradient optimization with fitfast() function. You can specify the number of starting points to use. The default is 2. This means that a latin hyper cube sampling (space filling DOE) of 2 is used to run 2 L-BFGS-B optimizations. See this example which runs fit() function, then runs the fitfast() to compare the runtime differences!

Installation

Python Package Index (PyPI)

You can now install with pip. python -m pip install pwlf

Conda

If you have conda, you can also install from conda-forge. conda install -c conda-forge pwlf

From source

Or clone the repo git clone https://github.com/cjekel/piecewise_linear_fit_py.git

then install with pip python -m pip install ./piecewise_linear_fit_py

How it works

This paper explains how this library works in detail.

This is based on a formulation of a piecewise linear least squares fit, where the user must specify the location of break points. See this post which goes through the derivation of a least squares regression problem if the break point locations are known. Alternatively check out Golovchenko (2004).

Global optimization is used to find the best location for the user defined number of line segments. I specifically use the differential evolution algorithm in SciPy. I default the differential evolution algorithm to be aggressive, and it is probably overkill for your problem. So feel free to pass your own differential evolution keywords to the library. See this example.

Changelog

All changes now stored in CHANGELOG.md

New weights= keyword allows you to perform weighted pwlf fits! Removed TensorFlow code which can now be found here.

Requirements

NumPy >= 1.14.0

SciPy >= 1.8.0

License

MIT License

Citation

bibtex @Manual{pwlf, author = {Jekel, Charles F. and Venter, Gerhard}, title = {{pwlf:} A Python Library for Fitting 1D Continuous Piecewise Linear Functions}, year = {2019}, url = {https://github.com/cjekel/piecewise_linear_fit_py} }

Owner

  • Name: Charles Jekel
  • Login: cjekel
  • Kind: user
  • Location: Livermore, CA
  • Company: Lawrence Livermore National Laboratory, @LLNL

GitHub Events

Total
  • Create event: 9
  • Issues event: 18
  • Release event: 5
  • Watch event: 36
  • Issue comment event: 40
  • Push event: 22
  • Pull request event: 12
  • Fork event: 7
Last Year
  • Create event: 9
  • Issues event: 18
  • Release event: 5
  • Watch event: 36
  • Issue comment event: 40
  • Push event: 22
  • Pull request event: 12
  • Fork event: 7

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 587
  • Total Committers: 10
  • Avg Commits per committer: 58.7
  • Development Distribution Score (DDS): 0.037
Past Year
  • Commits: 43
  • Committers: 5
  • Avg Commits per committer: 8.6
  • Development Distribution Score (DDS): 0.163
Top Committers
Name Email Commits
cjekel c****l@g****m 565
Vladimir Khodygo k****o@g****m 9
Cameron Wonchoba c****a@g****m 4
H. Vetinari h****i@g****m 3
tcanders 4****s 1
bezineb5 b****b@l****t 1
Max x****n 1
Fredrik Hellman f****n@g****m 1
Filippo Bistaffa f****a@g****m 1
Hellman, Fredrik f****n@e****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 84
  • Total pull requests: 39
  • Average time to close issues: 5 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 50
  • Total pull request authors: 12
  • Average comments per issue: 2.96
  • Average comments per pull request: 1.41
  • Merged pull requests: 31
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 11
  • Pull requests: 9
  • Average time to close issues: 14 days
  • Average time to close pull requests: 18 days
  • Issue authors: 6
  • Pull request authors: 5
  • Average comments per issue: 1.82
  • Average comments per pull request: 0.89
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • cjekel (24)
  • doronbehar (4)
  • qingzma (2)
  • SebastianHD (2)
  • dfdd3026 (2)
  • lk1983823 (2)
  • aaronnkang (2)
  • gretzteam (2)
  • riemanncode (2)
  • joaoantoniocardoso (2)
  • QuocTran (1)
  • mschmill (1)
  • binkeleraible (1)
  • SHEN-Cheng (1)
  • markcdaley (1)
Pull Request Authors
  • cjekel (23)
  • wonch002 (4)
  • fredrikhellman (2)
  • h-vetinari (2)
  • vkhodygo (2)
  • matt8s (2)
  • bezineb5 (2)
  • filippobistaffa (2)
  • trueParadise (1)
  • xhain (1)
  • tcanders (1)
  • overlord000 (1)
Top Labels
Issue Labels
bug (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 328,401 last-month
  • Total docker downloads: 122
  • Total dependent packages: 3
    (may contain duplicates)
  • Total dependent repositories: 20
    (may contain duplicates)
  • Total versions: 67
  • Total maintainers: 1
pypi.org: pwlf

fit piecewise linear functions to data

  • Versions: 58
  • Dependent Packages: 2
  • Dependent Repositories: 18
  • Downloads: 328,401 Last month
  • Docker Downloads: 122
Rankings
Downloads: 0.7%
Docker downloads count: 2.4%
Dependent packages count: 3.2%
Average: 3.2%
Dependent repos count: 3.4%
Stargazers count: 3.9%
Forks count: 5.5%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: pwlf

A library for fitting continuous piecewise linear functions to data. Just specify the number of line segments you desire and provide the data.

  • Versions: 9
  • Dependent Packages: 1
  • Dependent Repositories: 2
Rankings
Dependent repos count: 20.3%
Forks count: 23.5%
Average: 24.4%
Stargazers count: 24.8%
Dependent packages count: 29.0%
Last synced: 6 months ago

Dependencies

docs/_sources/requirements.rst.txt pypi
  • Requirements *
setup.py pypi
  • numpy *
  • pyDOE *
  • scipy *
.github/workflows/ci.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v1 composite
.github/workflows/cron.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite