1 import numpy as np, matplotlib.pyplot as plt 2 from _utils.plot_utils import setup_style, save_fig, PALETTE, COLORS, _lighten 3 setup_style() 4 5 np.random.seed(42) 6 steps = np.arange(1, 13) 7 models_data = {'Ours': 0.95*np.exp(-0.03*steps)+np.random.randn(12)*0.005, 8 'LSTM': 0.92*np.exp(-0.05*steps)+np.random.randn(12)*0.008, 9 'GRU': 0.91*np.exp(-0.045*steps)+np.random.randn(12)*0.007, 10 'ARIMA': 0.88*np.exp(-0.08*steps)+np.random.randn(12)*0.01} 11 12 fig, ax = plt.subplots(figsize=(9, 5)) 13 all_vals = np.array(list(models_data.values())) 14 best_line, worst_line = all_vals.max(axis=0), all_vals.min(axis=0) 15 16 n_layers = 15 17 for k in range(n_layers, 0, -1): 18 frac = k / n_layers 19 ax.fill_between(steps, worst_line, worst_line+frac*(best_line-worst_line), 20 alpha=0.02, color=PALETTE[0], linewidth=0) 21 ax.fill_between(steps, worst_line, best_line, alpha=0.06, color=PALETTE[0], linewidth=0, label='Model Spread') 22 23 threshold = 0.80 24 ax.axhline(y=threshold, color=COLORS['up'], linestyle='--', linewidth=1.2, alpha=0.7) 25 ax.axhspan(0, threshold, color=COLORS['bg_box'], alpha=0.15, zorder=0) 26 ax.axhspan(threshold, 1.0, color=_lighten(COLORS['up'], 0.8), alpha=0.1, zorder=0) 27 ax.text(12.3, threshold, 'Acceptable\nThreshold', ha='left', va='center', fontsize=8, color=COLORS['up'], 28 bbox=dict(boxstyle='round,pad=0.2', facecolor='white', edgecolor=COLORS['up'], alpha=0.9)) 29 30 markers = ['o','s','D','^'] 31 for i, (name, acc) in enumerate(models_data.items()): 32 lw = 2.5 if name == 'Ours' else 1.5; ms = 7 if name == 'Ours' else 5 33 ax.plot(steps, acc, f'{markers[i]}-', color=PALETTE[i], linewidth=lw, markersize=ms, 34 label=name, markeredgecolor='white', markeredgewidth=0.8, zorder=5) 35 if name in ['Ours', 'ARIMA']: 36 decay_rate = (acc[0]-acc[-1])/acc[0]*100 37 ax.annotate(f'Decay: {decay_rate:.1f}%', xy=(steps[-1], acc[-1]), 38 xytext=(steps[-1]-2.5, acc[-1]-0.04), fontsize=8, color=PALETTE[i], 39 arrowprops=dict(arrowstyle='->', color=PALETTE[i], lw=1.0, connectionstyle='arc3,rad=0.2'), 40 bbox=dict(boxstyle='round,pad=0.25', facecolor='white', edgecolor=PALETTE[i], alpha=0.9)) 41 42 ax.set_xlabel('Prediction Horizon (steps ahead)', fontsize=11); ax.set_ylabel('R² Score', fontsize=11) 43 ax.set_xticks(steps); ax.legend(frameon=False, labelspacing=0.35, handlelength=1.6, fontsize=9, loc='lower left', ncol=2) 44 ax.spines['top'].set_visible(False) 45 ax.spines['right'].set_visible(False) 46 ax.grid(alpha=0.15, linestyle='--'); ax.set_ylim(0.55, 1.0) 47 fig.tight_layout() 48 save_fig(fig, 'figures/fig_multistep_decay.pdf')