Gaussian Data

Contents

Gaussian Data#

In this notebook, we want to demonstrate how to use Entropy (H) and Mutual Information (MI), and showcase the different approaches on gaussian random data.

import infomeasure as im
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(29615)
2025-04-17 07:25:58,307 |  WARNING | font_manager.py:1095 | Matplotlib is building the font cache; this may take a moment.
2025-04-17 07:26:03,522 |     INFO | font_manager.py:1107 | Failed to extract font properties from /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf: Can not load face (unknown file format; error code 0x2)
2025-04-17 07:26:32,076 |     INFO | font_manager.py:1639 | generated new fontManager

Entropy#

Generate normal distributed random variables with varying standard deviation \(\sigma\).

n = 2000
stds = np.linspace(0.1, 10, 20)  # standard deviations to test
# data is an array of shape (len(stds), n)
data_h = rng.normal(0, stds[:, None], (len(stds), n))

Let’s look at the first time series and plot the first 200 samples. Also, compare the histograms of the time series for different \(\sigma\) values.

Hide code cell source
fig, axes = plt.subplots(1, 2, figsize=(12, 6))

m = 200
axes[0].plot(data_h[0])
axes[0].grid()
axes[0].set_xlabel('Number of samples')
axes[0].set_xlim(-10, m)
axes[0].set_ylabel('Value')
axes[0].set_title(
    fr'Normal distributed time series ($\sigma={stds[0]:.2f}$, first {m} samples)')

cmap = plt.get_cmap('viridis')
for i in range(len(stds)):
    hist, bins = np.histogram(data_h[i], bins=20, density=True)
    axes[1].plot(hist, bins[:-1], color=cmap(i / len(stds)), label=(f'std={stds[i]:.2f}' if i in [0, len(stds)//2, len(stds)-1] else None))
axes[1].set_ylim(-20, 20)
axes[1].set_xlim(0, 0.25)
axes[1].set_xlabel('Value')
axes[1].set_ylabel('Density')
axes[1].set_title(
    fr'Histogram for the normal distributed time series')
axes[1].legend()
axes[1].grid()

plt.show()
../../_images/afeba1bb7172625d8f79c91c105c63cadb81764114f9c15debdb338945a086b8.png

Warning

This section is under construction. Please check back in a few days for updates.