<jupyter_start><jupyter_text>Testing Fourier formulation for seasonality<jupyter_code>np.random.seed(6)
def fourier_series(t, p=365.25, n=10):
    # 2 pi n / p
    x = 2 * np.pi * np.arange(1, n + 1) / p
    # 2 pi n / p * t
    x = x * t[:, None]
    x = np.concatenate((np.cos(x), np.sin(x)), axis=1)
    return x

def fourier_series2(t, p=365.25, n=10):
    x = 2* np.pi * np.arange(1, n+1) / p
    x = x*t[:, None]
    x = np.cos(x - phi_n)
    return x

phi_n = np.arctan2(beta[1::2], beta[::2])
An = np.sqrt(beta[1::2]**2+ beta[::2]**2)
n = 4
t = np.arange(1000)
beta = np.random.normal(size=2 * n)
pl.figure(figsize=(16, 6))
pl.plot(fourier_series(t, 365.25, n) @ beta)
pl.plot(fourier_series2(t, n=n) @An, color='r')
An.shape
phi = np.arctan2(beta[1::2], beta[::2])
An = np.sqrt(beta[1::2]**2+ beta[::2]**2)
An<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22169811320754718, 'fraction_numerical': 0.06839622641509434, 'mean_word_length': 3.639344262295082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '508765', 'license': 'CC0-1.0', 'n_tokens_mistral': 435, 'n_tokens_neox': 409, 'n_words': 84, 'path': 'Part-2-PyMC3-modeling/ipynb/GAM/Tests.ipynb', 'repo_name': 'madHatter106/SouthernOcean', 'size': '848'}