Skip to content

Commit

Permalink
allow basis parameter override in smooth plot
Browse files Browse the repository at this point in the history
fixed bug that would exclude step key = 0
-
  • Loading branch information
probability committed Mar 21, 2021
1 parent 0b3d2f8 commit 5fb8a4a
Show file tree
Hide file tree
Showing 20 changed files with 941 additions and 347 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ It's all about tools that just work and no need for extensive knowledge of Panda
</p>

## Installation

HotStepper can be installed from PyPI:

```bash
Expand All @@ -32,7 +31,6 @@ Conda install coming soon!


## Quick Test Drive

<p align="center">
<a href="https://mybinder.org/v2/gh/TangleSpace/hotstepper/master?filepath=docs%2Fexamples" alt="Binder">
<img src="https://mybinder.org/badge_logo.svg" /></a>
Expand All @@ -52,6 +50,7 @@ I'd like to thank the Staircase package owner for currating some of these datase

## Step Functions
Behold! the power of the [Heaviside step function](https://en.wikipedia.org/wiki/Heaviside_step_function)
Checkout a detailed, somewhat, probably <a href="https://hotstepper.readthedocs.io/notebooks/step_functions.html">very exciting, non-stop adventure ride</a> of through some of the, umm, math.....behind HotStepper and step functions. With any luck, someone will have a deadline tomorrow and HotStepper and step functions will save the day! Or atleast, I like to keep thinking that.

### Ok, don't packup just yet.
<p align="center"><img src="https://raw.githubusercontent.com/tanglespace/hotstepper/master/docs/images/temperature.gif" title="Daily Temperature" alt="Daily Temperature", width="50%" height="50%"><img src="https://raw.githubusercontent.com/tanglespace/hotstepper/master/docs/images/store.gif" title="Store" alt="Store", width="50%" height="50%"></p>
Expand Down
14 changes: 12 additions & 2 deletions docs/basis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,24 @@ Bases
:nowrap:
\begin{equation*}
\gamma(t,\alpha) =1-exp\left(-\frac{t}{\alpha} \right)
\gamma(t,\alpha) =exp\left(-exp\left(-\frac{t}{\alpha} \right)\right)
\;\;\;\;\; where \;t,\; \alpha \in \mathbb{R}
\end{equation*}
- Normal
.. math::
:nowrap:
\begin{equation*}
\gamma(t,\alpha) =exp\left(-\frac{t^2}{\alpha} \right)
\;\;\;\;\; where \;t,\; \alpha \in \mathbb{R}
\end{equation*}
- Sinc
.. math::
:nowrap:
\begin{equation*}
\gamma(t,\alpha) =\frac{sin\left(\frac{t}{\alpha} \right)}{\left(\frac{t}{\alpha} \right)}
\gamma(t,\alpha) =\frac{sin\left(\frac{t}{\alpha} \right)}{\left(t \right)}
\;\;\;\;\; where \;t,\; \alpha \in \mathbb{R}
\end{equation*}
3 changes: 1 addition & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ Case Studies
examples/more currency
examples/uber trips
examples/daily temperatures
examples/store_orders
examples/sequency_quickstart
examples/store_orders
12 changes: 6 additions & 6 deletions docs/examples/more currency.ipynb

Large diffs are not rendered by default.

Binary file added docs/images/sad.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ Behold! the power of the `Heaviside step function <https://en.wikipedia.org/wiki
.. rst-class:: center

HotStepper is a Numpy based step function analysis and exploration library that trys (not always) to follow general patterns established by Numpy in order to implement step and smoothing functions by way of a linear algebra approach.

Some use cases for the HotStepper package are the analysis of count and discontinuous data (queues, forex, trips etc.). It's all about tools that just work and no need for extensive knowledge of Pandas or Numpy or whatever, just HotStepper. Analysis and exploration should take less code!

Sequency Analysis
**Step Functions**
======================================
.. toctree::
:maxdepth: 1

step_functions.rst

**Sequency Analysis**
======================================
.. toctree::
:maxdepth: 1

sequency_methods.rst
sequency.rst

What do you want to know?
**What do you want to know?**
======================================

.. toctree::
:maxdepth: 1

Expand Down
53 changes: 37 additions & 16 deletions docs/notebooks/Even more How To's.ipynb

Large diffs are not rendered by default.

305 changes: 150 additions & 155 deletions docs/notebooks/How To's.ipynb

Large diffs are not rendered by default.

192 changes: 85 additions & 107 deletions docs/notebooks/More How To's.ipynb

Large diffs are not rendered by default.

179 changes: 169 additions & 10 deletions docs/notebooks/prettyplot.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/notebooks/sequency_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@
"source": [
"Wait, I thought we were talking about Sequency Analysis, what is the Walsh transform? In the realm of Sequency Analysis, the Walsh transform plays the role of the Fourier transform, with a few differences. It is those delicious differences that make this investigation worth the effort, as the Fourier transform is awesome, no doubt, but it does have some hang ups if we give it data that doesn't play nicely in terms of smoothness and jumpiness? is that a word, it is now. We will have a look at the younger but less well known brother of the Fourier transform, the Welsh transform and will show how whilst Fourier is all that and a bag of potato chips, there are some cases (actually quite a few) where we should use a different method and will be rewarded with more insight and a clearer picture of the nature of the data. Anyways, enough woffling.\n",
"\n",
"The Walsh transform is defined as the sequency ordered Hadamand transform, which is nothing more than a matrix full of -1 and 1's arranged in order of increasing sequency number. Ok ok, sequency number, wtf is that? If we start with the definition of [frequency](https://en.wikipedia.org/wiki/Frequency#:~:text=Frequency%20is%20the%20number%20of,a%20repeating%20event%20per%20second.), in simple terms, the number of times a pattern repeats within an interval, usually a unit interval of time, such as a second and is defined as;\n",
"The Walsh transform is defined as the sequency ordered Hadamand transform, which is nothing more than a matrix full of -1 and 1's arranged in order of increasing sequency number. Ok ok, sequency number, wtf is that? If we start with the definition of [frequency](https://en.wikipedia.org/wiki/Frequency#:~:text=Frequency%20is%20the%20number%20of,a%20repeating%20event%20per%20second.), in simple terms, the number of times a pattern repeats within an interval T, usually a unit interval of time, such as a second and is defined as;\n",
"\n",
"$f = \\frac{1}{T} \\;\\; T = 1 \\;time \\;unit \\;(usually \\;seconds)$\n",
"$f = \\frac{1}{T}$\n",
"\n",
"Fair enough, so the definition of [sequency](https://mathworld.wolfram.com/Sequency.html) is similar, except we just use the idea of crossing **through** zero, the number of zero crossings within a given interval.\n",
"\n",
Expand Down
390 changes: 390 additions & 0 deletions docs/notebooks/step_functions.ipynb

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions docs/step_functions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Step Functions
======================================

.. warning::

The content ahead may cause extreme drowsiness or deplete the will to go on.

.. image:: images/sad.jpg
:width: 50%
:alt: sad warning
:align: left

.. toctree::
:maxdepth: 2

notebooks/step_functions.ipynb
10 changes: 5 additions & 5 deletions docs/steps_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Basic methods

.. _api.plot_functions:

Plotting functions
Plotting methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autosummary::
:toctree: api/
Expand All @@ -42,7 +42,7 @@ Plotting functions

.. _api.class_loader_functions:

Class Loader functions
Class Loader methods
~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
Expand All @@ -54,7 +54,7 @@ Class Loader functions

.. _api.instant_loader_functions:

Instance Loader functions
Instance Loader methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
Expand All @@ -66,7 +66,7 @@ Instance Loader functions

.. _api.step_functions:

Step Functions
Step methods
~~~~~~~~~~~~~~~~~~~~

.. autosummary::
Expand Down Expand Up @@ -145,7 +145,7 @@ Summary statistics
Steps.histogram


Miscellaneous functions
Miscellaneous methods
~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
Expand Down
2 changes: 1 addition & 1 deletion hotstepper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.0.9'
__version__ = '1.0.10'
__packagename__ = 'HotStepper'
__author__ = 'Jackson Storm'

Expand Down
19 changes: 15 additions & 4 deletions hotstepper/basis/Bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class Bases(ABC):
The mathematical bases defined within this class are;
Heaviside
Logit
Logistic
Sigmoid
Arctan
Exponential
Normal
Sinc
"""
Expand Down Expand Up @@ -70,11 +71,21 @@ def sigmoid(x,steps,param):

@staticmethod
@njit(parallel=True,nogil=True)
def expon(x,steps,param):
def exponential(x,steps,param):
result = np.zeros(len(x))

for i in nb.prange(steps.shape[0]):
result += steps[i,2]*(1.0 - np.exp(-1*steps[i,1]*(x-steps[i,0])/param))
result += steps[i,2]*(np.exp(-1*np.exp(-1*steps[i,1]*(x-steps[i,0])/param)))

return result

@staticmethod
@njit(parallel=True,nogil=True)
def normal(x,steps,param):
result = np.zeros(len(x))

for i in nb.prange(steps.shape[0]):
result += steps[i,2]*(np.exp((-1/param)*(steps[i,1]*(x-steps[i,0]))**2))

return result

Expand All @@ -85,7 +96,7 @@ def sinc(x,steps,param):
result = np.zeros(len(x))

for i in nb.prange(steps.shape[0]):
result += steps[i,2]*np.sinc(steps[i,1]*(x-steps[i,0])/param)
result += steps[i,2]*(np.sinc(steps[i,1]*(x-steps[i,0])/param))/param

return result

Expand Down
21 changes: 16 additions & 5 deletions hotstepper/core/AbstractSteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,18 @@ def smooth_step(self,xdata,smooth_factor = None,smooth_basis = None, process_inp
using_default = self._basis.name == 'Heaviside'
#check we don't already have a new basis assigned
if using_default:
if smooth_factor is None:
smooth_factor = self._get_auto_smooth_factor()


if smooth_basis is None:
if smooth_factor is None:
smooth_factor = self._get_auto_smooth_factor()
self.rebase(new_basis=Basis(Bases.logistic,param=smooth_factor))
else:
# Override basis param is we got smooth_factor
if smooth_factor is not None:
smooth_basis.param = smooth_factor
#smooth_factor = self._get_auto_smooth_factor()

self.rebase(new_basis=smooth_basis)

if self._step_data.shape[0] > 0:
Expand Down Expand Up @@ -408,14 +414,19 @@ def reflect(self,reflect_point = 0):


def __iter__(self):
self._index = 0
return iter([type(self)(self._using_dt).add_steps([s]) for s in self._step_data])

if self._step_data[0,DataModel.START.value] == get_epoch_start(False):
self._index = 1
return iter([type(self)(self._using_dt).add_steps([s]) for s in self._step_data[1:]])
else:
self._index = 0
return iter([type(self)(self._using_dt).add_steps([s]) for s in self._step_data])


def __next__(self):
if self._index < self._step_data.shape[0]:
self._index += 1
return type(self)(self._using_dt).add_steps(self._step_data[self._index-1])
return type(self)(self._using_dt).add_steps([self._step_data[self._index-1]])
else:
self._index = 0
raise StopIteration
Expand Down
2 changes: 1 addition & 1 deletion hotstepper/core/Steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def add(self,steps):
def _recalculate(self):
try:
self._step_data = self._step_data[~np.isnan(self._step_data[:,DataModel.START.value])]
self._step_data = self._step_data[self._step_data[:,DataModel.START.value]!=0]
#self._step_data = self._step_data[self._step_data[:,DataModel.START.value]!=0]
self._step_data = self._step_data[self._step_data[:,DataModel.START.value]!=np.NINF]
self._step_data = self._step_data[self._step_data[:,DataModel.START.value]!=np.PINF]
self._step_data = self._step_data[np.argsort(self._step_data[:,DataModel.START.value])]
Expand Down
47 changes: 25 additions & 22 deletions hotstepper/mixins/StepsPlottingMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ def smooth_plot(self,smooth_factor = None,smooth_basis=None, interval = 0.01,ax=
Matplotlib.Axes
A reference to the plot axes object to allow further plotting on the same axes.
"""
# Examples
# ==========
Examples
==========
# .. plot::
# :context: close-figs
.. plot::
:context: close-figs
# st = Step(5,10,3) + Step(6,weight=2)
# ax = st.smooth_plot(smooth_factor=2,offset=0.01)
# st.plot(ax=ax,color='g')
# ax.set_title('Smooth Steps Plot')
st = Step(5,10,3) + Step(6,weight=2)
ax = st.smooth_plot(smooth_factor=2)
st.plot(ax=ax,color='g')
ax.set_title('Smooth Steps Plot')
"""

return self.plot(method='smooth',smooth_factor = smooth_factor,smooth_basis=smooth_basis,interval = interval,ax=ax,where=where,**kargs)

Expand Down Expand Up @@ -111,22 +112,24 @@ def plot(self,method=None,smooth_factor=None,smooth_basis=None,interval = 0.01,a
Matplotlib.Axes
A reference to the plot axes object to allow further plotting on the same axes.
"""

# Examples
# ==========
Examples
==========
# .. plot::
# :context: close-figs
.. plot::
:context: close-figs
# s1 = Step(5,10,3)
# s2 = Step(6,weight=2)
# st = s1 + s2
# ax = s1.plot(color='r')
# s2.plot(ax=ax,color='g',method='function')
# st.plot(ax=ax)
s1 = Step(5,10,3)
s2 = Step(6,weight=2)
st = s1 + s2
ax = s1.plot(color='r',figsize=(8,4))
s2.plot(ax=ax,method='function')
s2.plot(ax=ax,method='smooth')
st.plot(ax=ax)
st.smooth_plot(ax=ax)
# ax.set_title('Steps Plot')
ax.set_title('Steps Plot')
"""

if ax is None:
plot_size = kargs.pop('figsize',None)
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='hotstepper',
version='1.0.9',
version='1.0.10',
description='Numpy based step function library.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand All @@ -24,12 +24,10 @@
packages=setuptools.find_packages(),
classifiers=[
'Operating System :: OS Independent',
'Intended Audience :: Science/Research/Analysis',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering/Analysis',
],
install_requires=[
'numpy',
Expand Down

0 comments on commit 5fb8a4a

Please sign in to comment.