Modelling of quantitative state changes as step functions
Project description
The leading use-case for the staircase package is for the creation and analysis of step functions.
Pretty exciting huh.
But don't hit the close button on the browser just yet. Let us convince you that much of the world around you can be modelled as step functions.
For example, the number of users viewing this page over time can be modelled as a step function. The value of the function increases by 1 every time a user arrives at the page, and decreases by 1 every time a user leaves the page. Let's say we have this data in vector format (i.e. tuple, list, numpy array, pandas series). Specifically, assume arrive and leave are vectors of times, expressed as minutes past midnight, for all page views occuring yesterday. Creating the corresponding step function is simple. To achieve it we use the Stairs class:
>>> import staircase as sc
>>> views = sc.Stairs()
>>> views.layer(arrive,leave)
We can visualise the function with the plot function:
>>> views.plot()
We can find the total time in minutes the page was viewed:
>>> views.integrate(0,1440)
9297.94622521079
We can find the average number of viewers:
>>> views.mean(0,1440)
6.4569071008408265
We can find the average number of viewers, per hour of the day, and plot:
>>> pd.Series([views.mean(60*i, 60*(i+1)) for i in range(24)]).plot()
We can find the maximum concurrent views:
>>> views.max(0,1440)
16
We can create histogram data showing relative frequency of concurrent viewers (and plot it):
>>> views.hist(0,1440).plot.bar()
Plotting is based on matplotlib and it requires relatively little effort to take the previous chart and improve the aesthetics:
There is plenty more analysis that could be done. The staircase package provides a rich variety of arithmetic operations, relational operations, logical operations, statistical operations, for use with Stairs, in addition to functions for univariate analysis, aggregations and compatibility with pandas.Timestamp.
Installation
Staircase can be installed from PyPI:
python -m pip install staircase
or also with conda:
conda install -c venaturum staircase
Documentation
The complete guide to using staircase can be found at Read the Docs
Contributing
Please stay tuned for how you can contribute...
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MIT License - see the LICENSE file for details
Acknowledgments
- This project is heavily reliant on sorted containers. Grant Jenks has done a great job bringing this functionality to Python at lightning fast speeds.
- staircase began development from within the Hunter Valley Coal Chain Coordinator. Thanks for the support!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for staircase-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9676cdd2700afb2948b8d3b9aeef5fb8bc8334051caa1af9b6185560b2da1f9 |
|
MD5 | d1a39367bf9bdfb3750dfa9d64fab0a5 |
|
BLAKE2b-256 | 93b677f7ab3f7eed5fd0280c13d0e1f007f939fd45bf26e0f6a80caae916fb8a |