Step#

lamatrix provides a Step model to capture step functions and breaks in data.

[2]:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10, 10, 0.01)


from lamatrix import Step
[3]:
Step().equation
[3]:
\[f(\mathbf{x}) = w_{0} \mathbb{I}_{[{-\infty}, {0}]}(\mathbf{x}) + w_{1} \mathbb{I}_{[{0}, {\infty}]}(\mathbf{x})\]
[4]:
model = Step('x', breakpoints=[0])
w = np.random.normal(size=model.width)
sample = model.design_matrix(x=x).dot(w)
[5]:
fig, ax = plt.subplots()
ax.plot(x, sample, c='k')
ax.set(xlabel='$x$', ylabel='$y$', title='Step model sample');
../_images/model-examples_Step_5_0.png