1. מפעל רעש (Noise Factory)
15 נק'מה עושים?
צרו שתי סדרות IID באורך 500:
א. התפלגות אחידה: Uniform(-0.5, 0.5)
ב. התפלגות נורמלית (גאוסית): N(0, 1).
ציירו את הסדרה העתית עבור כל אחת מהן. לאחר מכן, ציירו תרשים פיזור (Lag plot) עבור Lag=1 ועבור Lag=5 לכל סדרה.
על מה לענות?
מה אתם מצפים לראות ב-Lag plot של סדרת IID, והאם התוצאות תואמות לציפייה?
רמז:
השתמשו ב-np.random.uniform וב-np.random.normal. כדי לצייר Lag plot של lag=1, ציירו את x[:-1] מול x[1:]. עבור lag=5, ציירו x[:-5] מול x[5:].
פתרון:
בסדרת IID, אין תלות בין תצפית לתצפית אחרת, לכן ה-Lag plot ייראה כמו "ענן" אקראי של נקודות ללא כיוון או צורה מובהקת (אין קורלציה).
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0) # For reproducibility
N = 500
u_noise = np.random.uniform(-0.5, 0.5, N)
g_noise = np.random.normal(0, 1, N)
def plot_lags(series, title):
fig, axes = plt.subplots(1, 3, figsize=(15, 4))
# Time series plot
axes[0].plot(series)
axes[0].set_title(f"{title} - Time Series")
axes[0].set_xlabel("Time (t)")
axes[0].set_ylabel("Value")
# Lag 1 plot
axes[1].scatter(series[:-1], series[1:], alpha=0.5)
axes[1].set_title("Lag 1 Plot")
axes[1].set_xlabel("x[t]")
axes[1].set_ylabel("x[t+1]")
# Lag 5 plot
axes[2].scatter(series[:-5], series[5:], alpha=0.5)
axes[2].set_title("Lag 5 Plot")
axes[2].set_xlabel("x[t]")
axes[2].set_ylabel("x[t+5]")
plt.tight_layout()
plt.show()
plot_lags(u_noise, "Uniform IID")
plot_lags(g_noise, "Gaussian IID")
Take-Home Message:
בסדרות IID (ובפרט רעש לבן), העבר לא מלמד כלום על העתיד. ויזואלית, תרשימי Lag יציגו פיזור אקראי לחלוטין (ענן כדורי/ריבועי) לכל פיגור (Lag) שנבחר.