-
Notifications
You must be signed in to change notification settings - Fork 0
feat: v0.3.0-alpha feedback #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ElouenGinat
wants to merge
8
commits into
main
Choose a base branch
from
doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d5c651e
fix: remove API comparison card in doc index
ElouenGinat ff62264
doc(readme): more conscise readme
ElouenGinat 179391d
fix: implement alpha test feedback. Make density=True by default for …
ElouenGinat c5cedcc
doc: get api comparison markdown back
ElouenGinat 0bc3748
fix: remove density=True param in readme quickstart because it's the …
ElouenGinat 28a3844
fix: remove left over test file
ElouenGinat 27fd836
fix: new khiops hist doc in the demo. Better function reference in do…
ElouenGinat 593bc39
doc: update demo.ipynb
ElouenGinat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| # API Comparison | ||
|
|
||
| This document compares the current Khisto APIs with NumPy and Matplotlib. | ||
|
|
||
| ## NumPy Comparison | ||
|
|
||
| ### `numpy.histogram` vs `khisto.histogram` | ||
|
|
||
| Khisto's `histogram` function is designed as a drop-in replacement for `numpy.histogram`. | ||
|
|
||
| #### Signature Comparison | ||
|
|
||
| ```python | ||
| # NumPy | ||
| numpy.histogram( | ||
| a, | ||
| bins=10, | ||
| range=None, | ||
| density=None, | ||
| weights=None, | ||
| ) | ||
|
|
||
| # Khisto | ||
| khisto.histogram( | ||
| a, | ||
| range=None, | ||
| max_bins=None, | ||
| density=False, | ||
| ) | ||
| ``` | ||
|
|
||
| #### Key Differences | ||
|
|
||
| | Feature | NumPy | Khisto | | ||
| |---|---|---| | ||
| | **Binning method** | Fixed-width bins | Optimal variable-width bins | | ||
| | **Bins parameter** | `bins` (int or edges) | `max_bins` (optional limit) | | ||
| | **Default bins** | 10 fixed bins | Auto-determined optimal | | ||
| | **Weights support** | Yes | No | | ||
| | **Returns** | `(hist, bin_edges)` | `(hist, bin_edges)` | | ||
|
|
||
| #### Usage Comparison | ||
|
|
||
| ```python | ||
| import numpy as np | ||
| from khisto import histogram | ||
|
|
||
| data = np.random.normal(0, 1, 1000) | ||
|
|
||
| # NumPy - fixed 10 bins | ||
| np_hist, np_edges = np.histogram(data) | ||
|
|
||
| # Khisto - optimal bins (automatic) | ||
| khisto_hist, khisto_edges = histogram(data) | ||
|
|
||
| # NumPy - specified bin count | ||
| np_hist, np_edges = np.histogram(data, bins=20) | ||
|
|
||
| # Khisto - maximum bin count | ||
| khisto_hist, khisto_edges = histogram(data, max_bins=20) | ||
|
|
||
| # Both support density normalization | ||
| np_density, _ = np.histogram(data, density=True) | ||
| khisto_density, _ = histogram(data, density=True) | ||
|
|
||
| # Both support range specification | ||
| np_hist, _ = np.histogram(data, range=(-2, 2)) | ||
| khisto_hist, _ = histogram(data, range=(-2, 2)) | ||
| ``` | ||
|
|
||
| #### When to Use Each | ||
|
|
||
| | Use NumPy | Use Khisto | | ||
| |---|---| | ||
| | Need fixed-width bins | Want optimal data representation | | ||
| | Need weighted histograms | Want automatic bin selection | | ||
| | Need specific bin edges | Want adaptive bin widths | | ||
| | Performance-critical loops | Data visualization | | ||
|
|
||
| --- | ||
|
|
||
| ## Matplotlib Comparison | ||
|
|
||
| ### `matplotlib.pyplot.hist` vs `khisto.matplotlib.hist` | ||
|
|
||
| Khisto's `hist` function works similarly to matplotlib's `hist`, but with optimal binning. | ||
|
|
||
| #### Signature Comparison | ||
|
|
||
| ```python | ||
| # Matplotlib | ||
| matplotlib.pyplot.hist( | ||
| x, | ||
| bins=10, | ||
| range=None, | ||
| density=False, | ||
| weights=None, | ||
| cumulative=False, | ||
| bottom=None, | ||
| histtype='bar', | ||
| align='mid', | ||
| orientation='vertical', | ||
| rwidth=None, | ||
| log=False, | ||
| color=None, | ||
| label=None, | ||
| stacked=False, | ||
| **kwargs, | ||
| ) | ||
|
|
||
| # Khisto | ||
| khisto.matplotlib.hist( | ||
| x, | ||
| range=None, | ||
| max_bins=None, | ||
| density=False, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| cumulative=False, | ||
| histtype='bar', | ||
| orientation='vertical', | ||
| log=False, | ||
| color=None, | ||
| label=None, | ||
| ax=None, | ||
| edgecolor=None, | ||
| linewidth=None, | ||
| alpha=None, | ||
| **kwargs, | ||
| ) | ||
| ``` | ||
|
|
||
| #### Key Differences | ||
|
|
||
| | Feature | Matplotlib | Khisto | | ||
| |---|---|---| | ||
| | **Binning** | Fixed-width | Optimal variable-width | | ||
| | **Bins param** | `bins` | `max_bins` | | ||
| | **Axes param** | Implicit (current) | Optional `ax` parameter | | ||
| | **Cumulative** | Supported | Supported | | ||
| | **Reverse cumulative** | Supported with negative `cumulative` | Supported with negative `cumulative` | | ||
| | **Stacked** | Supported | Not supported | | ||
| | **Weights** | Supported | Not supported | | ||
| | **Unsupported histogram args** | None | `bins`, `stacked`, and `weights` raise a `TypeError` | | ||
| | **Multiple datasets** | Supported | Not supported; only 1-D arrays are accepted | | ||
|
|
||
| #### Usage Comparison | ||
|
|
||
| ```python | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| from khisto.matplotlib import hist | ||
|
|
||
| data = np.random.normal(0, 1, 1000) | ||
|
|
||
| # Matplotlib - fixed bins | ||
| fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) | ||
|
|
||
| ax1.hist(data, bins=30) | ||
| ax1.set_title("Matplotlib (30 bins)") | ||
|
|
||
| hist(data, ax=ax2) | ||
| ax2.set_title("Khisto (optimal bins)") | ||
|
|
||
| plt.tight_layout() | ||
| plt.show() | ||
| ``` | ||
|
|
||
| #### Common Parameters (Same Behavior) | ||
|
|
||
| ```python | ||
| # Both support these parameters identically: | ||
|
|
||
| # density normalization | ||
| plt.hist(data, density=True) | ||
| hist(data, density=True) | ||
|
|
||
| # cumulative view | ||
| plt.hist(data, density=True, cumulative=True) | ||
| hist(data, density=True, cumulative=True) | ||
|
|
||
| # reverse cumulative view | ||
| plt.hist(data, cumulative=-1) | ||
| hist(data, cumulative=-1) | ||
|
|
||
| # histogram type | ||
| plt.hist(data, histtype='step') | ||
| hist(data, histtype='step') | ||
|
|
||
| # orientation | ||
| plt.hist(data, orientation='horizontal') | ||
| hist(data, orientation='horizontal') | ||
|
|
||
| # log scale | ||
| plt.hist(data, log=True) | ||
| hist(data, log=True) | ||
|
|
||
| # color and label | ||
| plt.hist(data, color='blue', label='Data') | ||
| hist(data, color='blue', label='Data') | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Migration Guide | ||
|
|
||
| ### From NumPy | ||
|
|
||
| ```python | ||
| # Before (NumPy) | ||
| import numpy as np | ||
| hist, edges = np.histogram(data, bins=30) | ||
|
|
||
| # After (Khisto) | ||
| from khisto import histogram | ||
| hist, edges = histogram(data, max_bins=30) # max_bins is optional | ||
| ``` | ||
|
|
||
| ### From Matplotlib | ||
|
|
||
| ```python | ||
| # Before (Matplotlib) | ||
| import matplotlib.pyplot as plt | ||
| n, bins, patches = plt.hist(data, bins=30) | ||
|
|
||
| # After (Khisto) | ||
| from khisto.matplotlib import hist | ||
| n, bins, patches = hist(data, max_bins=30) # max_bins is optional | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Feature Matrix | ||
|
|
||
| | Feature | NumPy | Matplotlib | Khisto | | ||
| |---|---|---|---| | ||
| | Fixed-width bins | Yes | Yes | No | | ||
| | Optimal bins | No | No | Yes | | ||
| | Variable-width bins | Manual | Manual | Auto | | ||
| | Density | Yes | Yes | Yes | | ||
| | Range | Yes | Yes | Yes | | ||
| | Weights | Yes | Yes | No | | ||
| | Cumulative | No | Yes | Yes | | ||
| | Reverse cumulative | No | Yes | Yes | | ||
| | Plotting | No | Yes | Yes | | ||
| | Step histogram | No | Yes | Yes | | ||
| | Horizontal | No | Yes | Yes | | ||
| | Log scale | No | Yes | Yes | | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
density=True, as this is the default value now.