Sinusoid#
lamatrix
provides a Sinusoid model which can be used to capture periodic variability. This model enables you to fit for the amplitude of sinusoids, but is not linear in the period of the sinusoid.
[2]:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10, 10, 0.01)
from lamatrix import Sinusoid
[5]:
Sinusoid(nterms=1).equation
[5]:
\[f(\mathbf{x}) = w_{0} \sin(\mathbf{x}) + w_{1} \cos(\mathbf{x})\]
As shown above, this is only linear in the amplitudes of the sine and cosine terms. There is no way to build a linear model where a multiplicative weight can govern the period of these functions.
lamatrix
also provides a way to increase the number of terms of this model to fit higher order variability
[7]:
Sinusoid(nterms=2).equation
[7]:
\[f(\mathbf{x}) = w_{0} \sin(\mathbf{x}) + w_{1} \cos(\mathbf{x}) + w_{2} \sin(2\mathbf{x}) + w_{3} \cos(2\mathbf{x})\]
[8]:
model = Sinusoid('x', nterms=3)
w = np.random.normal(size=model.width)
sample = model.design_matrix(x=x).dot(w)
[9]:
fig, ax = plt.subplots()
ax.plot(x, sample, c='k')
ax.set(xlabel='$x$', ylabel='$y$', title='Sinusoid model sample');
