File size: 10,045 Bytes
d702e58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""
Generate prediction curves visualization for paper
Shows PRISM vs all SOTA baselines on representative test samples
"""
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path

# Set publication-quality settings
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.size'] = 10
plt.rcParams['axes.linewidth'] = 0.8
plt.rcParams['grid.alpha'] = 0.3

def generate_prediction_curves():
    """
    Generate Fig. 4: Prediction vs ground truth for 3 representative stocks
    - AAPL: Uptrend case
    - MSFT: Downtrend case  
    - SPY: Volatile case
    """
    
    # Color scheme EXACTLY matching original figure
    colors = {
        'historical': '#5B9BD5',      # Blue (historical, days 0-100)
        'ground_truth': '#000000',    # Black (complete truth, days 0-120)
        'prism': '#FF0000',           # Red (PRISM - OUR METHOD)
        'dlinear': '#70AD47',         # Green
        'tsmixer': '#FFC000',         # Orange
        'timesnet': '#C55A11',        # Dark orange
        'autoformer': '#7030A0',      # Purple
        'patchtst': '#DA9694',        # Light pink
        'informer': '#44546A',        # Dark gray
        'itransformer': '#00B0F0',    # Light blue
    }
    
    # Create sample data (NOTE: Based on real MAPE from logs, but positions are simulated)
    np.random.seed(42)
    days = np.arange(0, 120)
    pred_days = np.arange(100, 120)
    
    # AAPL - Uptrend (Days 0-120)
    aapl_ground_truth = 150 + np.linspace(0, 18, 120) + np.cumsum(np.random.randn(120) * 0.3)
    aapl_historical = aapl_ground_truth[:100]  # Historical = first 100 days
    
    # Model predictions (last 20 days) - simulate based on MAPE from logs
    pred_days = np.arange(100, 120)
    
    # AAPL predictions (MAPE as error scale)
    aapl_prism = aapl_ground_truth[100:] + np.random.randn(20) * 0.88 * aapl_ground_truth[100:].mean() / 100
    aapl_dlinear = aapl_ground_truth[100:] + np.random.randn(20) * 1.32 * aapl_ground_truth[100:].mean() / 100
    aapl_tsmixer = aapl_ground_truth[100:] + np.random.randn(20) * 1.61 * aapl_ground_truth[100:].mean() / 100
    aapl_timesnet = aapl_ground_truth[100:] + np.random.randn(20) * 1.68 * aapl_ground_truth[100:].mean() / 100
    aapl_autoformer = aapl_ground_truth[100:] + np.random.randn(20) * 2.50 * aapl_ground_truth[100:].mean() / 100
    aapl_patchtst = aapl_ground_truth[100:] + np.random.randn(20) * 2.65 * aapl_ground_truth[100:].mean() / 100
    aapl_informer = aapl_ground_truth[100:] + np.random.randn(20) * 2.77 * aapl_ground_truth[100:].mean() / 100
    
    aapl_itransformer = aapl_ground_truth[100:] + np.random.randn(20) * 7.17 * aapl_ground_truth[100:].mean() / 100
    
    # MSFT - Downtrend
    msft_ground_truth = 180 - np.linspace(0, 20, 120) + np.cumsum(np.random.randn(120) * 0.4)
    msft_historical = msft_ground_truth[:100]
    
    msft_prism = msft_ground_truth[100:] + np.random.randn(20) * 0.88 * msft_ground_truth[100:].mean() / 100
    msft_dlinear = msft_ground_truth[100:] + np.random.randn(20) * 1.32 * msft_ground_truth[100:].mean() / 100
    msft_tsmixer = msft_ground_truth[100:] + np.random.randn(20) * 1.61 * msft_ground_truth[100:].mean() / 100
    msft_timesnet = msft_ground_truth[100:] + np.random.randn(20) * 1.68 * msft_ground_truth[100:].mean() / 100
    msft_autoformer = msft_ground_truth[100:] + np.random.randn(20) * 2.50 * msft_ground_truth[100:].mean() / 100
    msft_patchtst = msft_ground_truth[100:] + np.random.randn(20) * 2.65 * msft_ground_truth[100:].mean() / 100
    msft_informer = msft_ground_truth[100:] + np.random.randn(20) * 2.77 * msft_ground_truth[100:].mean() / 100
    
    # SPY - Volatile
    spy_ground_truth = 90 + 5 * np.sin(np.linspace(0, 4*np.pi, 120)) + np.cumsum(np.random.randn(120) * 0.5)
    spy_historical = spy_ground_truth[:100]
    
    spy_prism = spy_ground_truth[100:] + np.random.randn(20) * 0.88 * spy_ground_truth[100:].mean() / 100
    spy_dlinear = spy_ground_truth[100:] + np.random.randn(20) * 1.32 * spy_ground_truth[100:].mean() / 100
    spy_tsmixer = spy_ground_truth[100:] + np.random.randn(20) * 1.61 * spy_ground_truth[100:].mean() / 100
    spy_timesnet = spy_ground_truth[100:] + np.random.randn(20) * 1.68 * spy_ground_truth[100:].mean() / 100
    spy_autoformer = spy_ground_truth[100:] + np.random.randn(20) * 2.50 * spy_ground_truth[100:].mean() / 100
    spy_patchtst = spy_ground_truth[100:] + np.random.randn(20) * 2.65 * spy_ground_truth[100:].mean() / 100
    spy_informer = spy_ground_truth[100:] + np.random.randn(20) * 2.77 * spy_ground_truth[100:].mean() / 100
    
    # Create figure with 3 subplots
    fig, axes = plt.subplots(1, 3, figsize=(15, 4))
    
    # Plot 1: AAPL (Uptrend) - WITH LEGEND
    # Historical (blue thin line, days 0-100)
    axes[0].plot(days[:100], aapl_historical, color=colors['historical'], 
                 linewidth=1.2, label='Historical', linestyle='-')
    
    # Ground Truth (black thick line, days 0-120)
    axes[0].plot(days, aapl_ground_truth, color=colors['ground_truth'], 
                 linewidth=2.5, label='Ground Truth', linestyle='-')
    
    # PRISM (red thick line with markers, days 100-120) - HIGHLIGHTED
    axes[0].plot(pred_days, aapl_prism, color=colors['prism'], 
                 linewidth=2.5, label='PRISM (Ours)', marker='o', markersize=5)
    
    # ALL Baselines (dashed lines, days 100-120)
    axes[0].plot(pred_days, aapl_dlinear, color=colors['dlinear'], 
                 linewidth=1.5, label='DLinear', linestyle='--')
    axes[0].plot(pred_days, aapl_tsmixer, color=colors['tsmixer'], 
                 linewidth=1.5, label='TSMixer', linestyle='--')
    axes[0].plot(pred_days, aapl_timesnet, color=colors['timesnet'], 
                 linewidth=1.5, label='TimesNet', linestyle='--')
    axes[0].plot(pred_days, aapl_autoformer, color=colors['autoformer'], 
                 linewidth=1.5, label='Autoformer', linestyle='--')
    axes[0].plot(pred_days, aapl_patchtst, color=colors['patchtst'], 
                 linewidth=1.5, label='PatchTST', linestyle='--')
    axes[0].plot(pred_days, aapl_informer, color=colors['informer'], 
                 linewidth=1.5, label='Informer', linestyle='--')
    axes[0].plot(pred_days, aapl_itransformer, color=colors['itransformer'], 
                 linewidth=1.5, label='iTransformer', linestyle='--')
    
    axes[0].set_title('AAPL (Uptrend)', fontweight='bold', fontsize=12)
    axes[0].set_xlabel('Days', fontsize=10)
    axes[0].set_ylabel('Price ($)', fontsize=10)
    axes[0].legend(fontsize=7.5, loc='upper left', frameon=True, fancybox=False, edgecolor='black')
    axes[0].grid(True, alpha=0.2)
    
    # Plot 2: MSFT (Downtrend) - NO LEGEND
    # Historical (blue thin line)
    axes[1].plot(days[:100], msft_historical, color=colors['historical'], linewidth=1.2)
    # Ground Truth (black thick line)
    axes[1].plot(days, msft_ground_truth, color=colors['ground_truth'], linewidth=2)
    # PRISM (red thick line with markers)
    axes[1].plot(pred_days, msft_prism, color=colors['prism'], linewidth=2.5, marker='o', markersize=5)
    # ALL Baselines
    axes[1].plot(pred_days, msft_dlinear, color=colors['dlinear'], linewidth=1.5, linestyle='--')
    axes[1].plot(pred_days, msft_tsmixer, color=colors['tsmixer'], linewidth=1.5, linestyle='--')
    axes[1].plot(pred_days, msft_timesnet, color=colors['timesnet'], linewidth=1.5, linestyle='--')
    axes[1].plot(pred_days, msft_autoformer, color=colors['autoformer'], linewidth=1.5, linestyle='--')
    axes[1].plot(pred_days, msft_patchtst, color=colors['patchtst'], linewidth=1.5, linestyle='--')
    axes[1].plot(pred_days, msft_informer, color=colors['informer'], linewidth=1.5, linestyle='--')
    
    axes[1].set_title('MSFT (Downtrend)', fontweight='bold', fontsize=12)
    axes[1].set_xlabel('Days', fontsize=10)
    axes[1].set_ylabel('Price ($)', fontsize=10)
    axes[1].grid(True, alpha=0.2)
    
    # Plot 3: SPY (Volatile) - NO LEGEND
    # Historical (blue thin line)
    axes[2].plot(days[:100], spy_historical, color=colors['historical'], linewidth=1.2)
    # Ground Truth (black thick line)
    axes[2].plot(days, spy_ground_truth, color=colors['ground_truth'], linewidth=2)
    # PRISM (red thick line with markers)
    axes[2].plot(pred_days, spy_prism, color=colors['prism'], linewidth=2.5, marker='o', markersize=5)
    # ALL Baselines
    axes[2].plot(pred_days, spy_dlinear, color=colors['dlinear'], linewidth=1.5, linestyle='--')
    axes[2].plot(pred_days, spy_tsmixer, color=colors['tsmixer'], linewidth=1.5, linestyle='--')
    axes[2].plot(pred_days, spy_timesnet, color=colors['timesnet'], linewidth=1.5, linestyle='--')
    axes[2].plot(pred_days, spy_autoformer, color=colors['autoformer'], linewidth=1.5, linestyle='--')
    axes[2].plot(pred_days, spy_patchtst, color=colors['patchtst'], linewidth=1.5, linestyle='--')
    axes[2].plot(pred_days, spy_informer, color=colors['informer'], linewidth=1.5, linestyle='--')
    
    axes[2].set_title('SPY (Volatile)', fontweight='bold', fontsize=12)
    axes[2].set_xlabel('Days', fontsize=10)
    axes[2].set_ylabel('Price ($)', fontsize=10)
    axes[2].grid(True, alpha=0.2)
    
    plt.tight_layout()
    
    # Save
    output_path = Path('/home/amd/yueyuan/Vision-TimeSeries/paper/figures/prediction_curves.pdf')
    plt.savefig(output_path, bbox_inches='tight', dpi=300)
    print(f"✓ Saved: {output_path}")
    
    # Also save PNG version
    png_path = output_path.with_suffix('.png')
    plt.savefig(png_path, bbox_inches='tight', dpi=150)
    print(f"✓ Saved: {png_path}")
    
    plt.close()


if __name__ == "__main__":
    print("\n" + "="*60)
    print("Generating Prediction Curves for Paper (All Baselines)")
    print("="*60 + "\n")
    
    print("NOTE: This generates SAMPLE data for layout.")
    print("Replace with actual model predictions from saved checkpoints.\n")
    
    generate_prediction_curves()
    
    print("\n" + "="*60)
    print("Done! Review the generated figure and update with real data.")
    print("="*60 + "\n")