pwlf
fit piecewise linear data for a specified number of line segments
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
Repository
fit piecewise linear data for a specified number of line segments
Basic Info
Statistics
- Stars: 337
- Watchers: 8
- Forks: 63
- Open Issues: 42
- Releases: 10
Topics
Metadata Files
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.
Check out the documentation!
Read the blog post.


Now you can perform segmented constant fitting and piecewise polynomials!

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
- Website: https://jekel.me
- Repositories: 62
- Profile: https://github.com/cjekel
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
Top Committers
| Name | 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
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
- Homepage: https://github.com/cjekel/piecewise_linear_fit_py
- Documentation: https://pwlf.readthedocs.io/
- License: MIT License
-
Latest release: 2.5.2
published 7 months ago
Rankings
Maintainers (1)
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.
- Homepage: https://github.com/cjekel/piecewise_linear_fit_py
- License: MIT
-
Latest release: 2.2.1
published over 3 years ago
Rankings
Dependencies
- Requirements *
- numpy *
- pyDOE *
- scipy *
- actions/checkout v2 composite
- actions/setup-python v2 composite
- codecov/codecov-action v1 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite