Skip to content

Commit d4e5157

Browse files
authored
Merge pull request #167 from arvkevi/chore/update_docs
Update docs
2 parents c815d15 + acc417d commit d4e5157

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1446
-641
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,19 @@ permissions:
88
pull-requests: write
99

1010
jobs:
11-
build:
11+
build:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
python-version: ["3.8", "3.9", "3.10", "3.11"]
15+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1616
os: [ubuntu-latest, macos-latest, windows-latest]
17-
exclude: # Python < v3.8 does not support Apple Silicon ARM64.
18-
- python-version: "3.7"
19-
os: macos-latest
20-
- python-version: "3.7"
21-
os: ubuntu-latest
22-
include: # So run those legacy versions on Intel CPUs.
23-
- python-version: "3.7"
24-
os: macos-13
25-
- python-version: "3.7"
26-
os: windows-latest
2717
env:
2818
OS: ${{ matrix.os }}
2919
PYTHON: ${{ matrix.python-version }}
3020
steps:
31-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
3222
- name: Set up Python ${{ matrix.python-version }}
33-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
3424
with:
3525
python-version: ${{ matrix.python-version }}
3626
- name: Install dependencies

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ nosetests.xml
3939
output/*.html
4040
output/*/index.html
4141

42-
# Sphinx
43-
docs/_build
42+
# MkDocs
43+
site/
4444

4545
# Cookiecutter
4646
output/

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors:
55
given-names: "Kevin"
66
orcid: "https://orcid.org/0000-0001-8751-8918"
77
title: "kneed"
8-
version: 0.7.0
8+
version: 0.8.5
99
doi: 10.5281/zenodo.6496267
10-
date-released: 2020-08-12
10+
date-released: 2023-07-08
1111
url: "https://github.com/arvkevi/kneed"

README.md

Lines changed: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,85 @@
11
# kneed
2-
Knee-point detection in Python
32

4-
[![Downloads](https://pepy.tech/badge/kneed)](https://pepy.tech/project/kneed) [![Downloads](https://pepy.tech/badge/kneed/week)](https://pepy.tech/project/kneed) ![Dependents](https://badgen.net/github/dependents-repo/arvkevi/kneed/?icon=github) [![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://share.streamlit.io/arvkevi/ikneed/main/ikneed.py) [![codecov](https://codecov.io/gh/arvkevi/kneed/branch/main/graph/badge.svg)](https://codecov.io/gh/arvkevi/kneed)[![DOI](https://zenodo.org/badge/113799037.svg)](https://zenodo.org/badge/latestdoi/113799037)
3+
Knee-point detection in Python
54

5+
[![PyPI version](https://img.shields.io/pypi/v/kneed.svg)](https://pypi.org/project/kneed/)
6+
[![Downloads](https://pepy.tech/badge/kneed)](https://pepy.tech/project/kneed)
7+
[![Downloads](https://pepy.tech/badge/kneed/week)](https://pepy.tech/project/kneed)
8+
![Dependents](https://badgen.net/github/dependents-repo/arvkevi/kneed/?icon=github)
9+
[![codecov](https://codecov.io/gh/arvkevi/kneed/branch/main/graph/badge.svg)](https://codecov.io/gh/arvkevi/kneed)
10+
[![DOI](https://zenodo.org/badge/113799037.svg)](https://zenodo.org/badge/latestdoi/113799037)
611

7-
This repository is an attempt to implement the kneedle algorithm, published [here](https://www1.icsi.berkeley.edu/~barath/papers/kneedle-simplex11.pdf). Given a set of `x` and `y` values, `kneed` will return the knee point of the function. The knee point is the point of maximum curvature.
12+
A Python library for detecting knee (elbow) points in curves using the [Kneedle algorithm](https://www1.icsi.berkeley.edu/~barath/papers/kneedle-simplex11.pdf). Given a set of `x` and `y` values, `kneed` returns the point of maximum curvature.
813

9-
![](https://raw.githubusercontent.com/arvkevi/kneed/main/images/functions_args_summary.png)
14+
![Summary of curve and direction arguments](https://raw.githubusercontent.com/arvkevi/kneed/main/images/functions_args_summary.png)
1015

11-
## Table of contents
12-
- [Installation](#installation)
13-
- [Usage](#usage)
14-
- [Input Data](#input-data)
15-
- [Find Knee](#find-knee)
16-
- [Visualize](#visualize)
17-
- [Documentation](#documentation)
18-
- [Interactive](#interactive)
19-
- [Contributing](#contributing)
20-
- [Citation](#citation)
16+
## Features
2117

22-
## Installation
23-
`kneed` has been tested with Python 3.7, 3.8, 3.9, and 3.10.
18+
- Detect knee/elbow points in concave or convex curves
19+
- Support for increasing and decreasing functions
20+
- Automatic curve shape detection with `find_shape()`
21+
- Multiple knee detection via online mode (`all_knees` / `all_elbows`)
22+
- Tunable sensitivity parameter (`S`)
23+
- Multiple interpolation methods (`interp1d`, `polynomial`)
24+
- Built-in plotting for quick visualizations
25+
26+
## Installation
27+
28+
`kneed` has been tested with Python 3.8, 3.9, 3.10, 3.11, and 3.12.
29+
30+
### anaconda
2431

25-
**anaconda**
2632
```bash
27-
$ conda install -c conda-forge kneed
33+
conda install -c conda-forge kneed
2834
```
2935

30-
**pip**
36+
### pip
37+
3138
```bash
32-
$ pip install kneed # To install only knee-detection algorithm
33-
$ pip install kneed[plot] # To also install plotting functions for quick visualizations
39+
pip install kneed # knee-detection only
40+
pip install kneed[plot] # also install matplotlib for visualizations
3441
```
3542

36-
**Clone from GitHub**
43+
### Clone from GitHub
44+
3745
```bash
38-
$ git clone https://github.com/arvkevi/kneed.git && cd kneed
39-
$ pip install -e .
46+
git clone https://github.com/arvkevi/kneed.git && cd kneed
47+
pip install -e .
48+
```
49+
50+
## Quick Start
51+
52+
```python
53+
from kneed import KneeLocator, DataGenerator
54+
55+
# Generate sample data
56+
x, y = DataGenerator.figure2()
57+
58+
# Find the knee point
59+
kl = KneeLocator(x, y, curve="concave", direction="increasing")
60+
print(kl.knee) # 0.222
61+
print(kl.knee_y) # 1.897
62+
```
63+
64+
If you're unsure about the curve type and direction, use `find_shape()` to auto-detect:
65+
66+
```python
67+
from kneed import find_shape
68+
69+
direction, curve = find_shape(x, y)
70+
kl = KneeLocator(x, y, curve=curve, direction=direction)
4071
```
4172

4273
## Usage
43-
These steps introduce how to use `kneed` by reproducing Figure 2 from the manuscript.
74+
75+
These steps reproduce Figure 2 from the original Kneedle manuscript.
4476

4577
### Input Data
46-
The `DataGenerator` class is only included as a utility to generate sample datasets.
47-
> Note: `x` and `y` must be equal length arrays.
78+
79+
The `DataGenerator` class is a utility to generate sample datasets.
80+
81+
> Note: `x` and `y` must be equal length arrays.
82+
4883
```python
4984
from kneed import DataGenerator, KneeLocator
5085

@@ -57,9 +92,10 @@ print([round(i, 3) for i in y])
5792
[-5.0, 0.263, 1.897, 2.692, 3.163, 3.475, 3.696, 3.861, 3.989, 4.091]
5893
```
5994

60-
### Find Knee
61-
The knee (or elbow) point is calculated simply by instantiating the `KneeLocator` class with `x`, `y` and the appropriate `curve` and `direction`.
62-
Here, `kneedle.knee` and/or `kneedle.elbow` store the point of maximum curvature.
95+
### Find Knee
96+
97+
The knee (or elbow) point is calculated by instantiating the `KneeLocator` class with `x`, `y` and the appropriate `curve` and `direction`.
98+
Here, `kneedle.knee` and `kneedle.elbow` store the point of maximum curvature.
6399

64100
```python
65101
kneedle = KneeLocator(x, y, S=1.0, curve="concave", direction="increasing")
@@ -79,50 +115,54 @@ print(round(kneedle.knee_y, 3))
79115
```
80116

81117
### Visualize
82-
The `KneeLocator` class also has two plotting functions for quick visualizations.
118+
119+
The `KneeLocator` class has two plotting functions for quick visualizations.
83120
**Note that all (x, y) are transformed for the normalized plots**
84121
```python
85122
# Normalized data, normalized knee, and normalized distance curve.
86123
kneedle.plot_knee_normalized()
87124
```
88125

89-
![](https://raw.githubusercontent.com/arvkevi/kneed/main/images/figure2.knee.png)
126+
![Normalized knee point](https://raw.githubusercontent.com/arvkevi/kneed/main/images/figure2.knee.png)
90127

91128
```python
92129
# Raw data and knee.
93130
kneedle.plot_knee()
94131
```
95132

96-
![](https://raw.githubusercontent.com/arvkevi/kneed/main/images/figure2.knee.raw.png)
133+
![Raw knee point](https://raw.githubusercontent.com/arvkevi/kneed/main/images/figure2.knee.raw.png)
97134

98135
## Documentation
99-
Documentation of the parameters and a full API reference can be found [here](https://kneed.readthedocs.io/).
136+
137+
Full documentation including parameter tuning guides, real-world examples, and API reference is available at [kneed.readthedocs.io](https://kneed.readthedocs.io/).
100138

101139
## Interactive
102-
An interactive streamlit app was developed to help users explore the effect of tuning the parameters.
103-
There are two sites where you can test out kneed by copy-pasting your own data:
104-
1. https://share.streamlit.io/arvkevi/ikneed/main/ikneed.py
105-
2. https://ikneed.herokuapp.com/
106140

107-
You can also run your own version -- head over to the [source code for ikneed](https://github.com/arvkevi/ikneed).
141+
An interactive Streamlit app is available to explore the effect of tuning parameters:
142+
143+
[share.streamlit.io/arvkevi/ikneed](https://share.streamlit.io/arvkevi/ikneed/main/ikneed.py)
144+
145+
You can also run your own version — head over to the [source code for ikneed](https://github.com/arvkevi/ikneed).
108146

109-
![ikneed](images/ikneed.gif)
147+
![ikneed](https://raw.githubusercontent.com/arvkevi/kneed/main/images/ikneed.gif)
110148

111149
## Contributing
112150

113-
Contributions are welcome, please refer to [CONTRIBUTING](https://github.com/arvkevi/kneed/blob/main/CONTRIBUTING.md)
114-
to learn more about how to contribute.
151+
Contributions are welcome, please refer to [CONTRIBUTING](https://github.com/arvkevi/kneed/blob/main/CONTRIBUTING.md)
152+
to learn more about how to contribute.
115153

116154
## Citation
117155

118-
Finding a “Kneedle” in a Haystack:
119-
Detecting Knee Points in System Behavior
120-
Ville Satopa
121-
122-
, Jeannie Albrecht†
123-
, David Irwin‡
124-
, and Barath Raghavan§
125-
†Williams College, Williamstown, MA
126-
‡University of Massachusetts Amherst, Amherst, MA
127-
§
128-
International Computer Science Institute, Berkeley, CA
156+
If you use `kneed` in your research, please cite:
157+
158+
> Satopa, V., Albrecht, J., Irwin, D., and Raghavan, B. (2011). "Finding a 'Kneedle' in a Haystack: Detecting Knee Points in System Behavior." *31st International Conference on Distributed Computing Systems Workshops*, pp. 166-171.
159+
160+
```bibtex
161+
@inproceedings{satopa2011kneedle,
162+
title={Finding a "Kneedle" in a Haystack: Detecting Knee Points in System Behavior},
163+
author={Satopa, Ville and Albrecht, Jeannie and Irwin, David and Raghavan, Barath},
164+
booktitle={31st International Conference on Distributed Computing Systems Workshops},
165+
pages={166--171},
166+
year={2011},
167+
}
168+
```

docs/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/api.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# API Reference
2+
3+
## KneeLocator
4+
5+
The primary class for knee/elbow point detection.
6+
7+
::: kneed.knee_locator.KneeLocator
8+
options:
9+
show_source: true
10+
members_order: source
11+
12+
## DataGenerator
13+
14+
Utility class for generating synthetic test data.
15+
16+
::: kneed.data_generator.DataGenerator
17+
options:
18+
show_source: true
19+
members_order: source
20+
21+
## find_shape
22+
23+
Utility function to auto-detect the curve direction and type.
24+
25+
::: kneed.shape_detector.find_shape
26+
options:
27+
show_source: true

docs/api.rst

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)