-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpredict_comprehensive.py
More file actions
181 lines (145 loc) Β· 7.26 KB
/
predict_comprehensive.py
File metadata and controls
181 lines (145 loc) Β· 7.26 KB
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
#!/usr/bin/env python3
"""
Comprehensive prediction script that uses both approaches to predict
decayRate and surfaceTransferFraction for the observed data.
This script provides predictions from:
1. Flattened Neural Network approach (original method)
2. CNN with sliding windows approach (new 4x56 method)
"""
import numpy as np
import pandas as pd
import subprocess
import sys
def run_flattened_prediction():
"""Run the original flattened neural network prediction."""
print("π¬ Running Flattened Neural Network Prediction...")
print("-" * 50)
try:
result = subprocess.run([sys.executable, 'predict_observed_data.py'],
capture_output=True, text=True, cwd='.')
if result.returncode == 0:
# Extract the final predictions from output
lines = result.stdout.split('\n')
decay_rate = None
surface_transfer = None
for line in lines:
if 'Decay Rate:' in line:
decay_rate = float(line.split(':')[1].strip())
elif 'Surface Transfer Fraction:' in line:
surface_transfer = float(line.split(':')[1].strip())
print(f"β
Flattened NN Results:")
print(f" Decay Rate: {decay_rate:.6f}")
print(f" Surface Transfer Fraction: {surface_transfer:.6f}")
return decay_rate, surface_transfer
else:
print(f"β Error running flattened prediction: {result.stderr}")
return None, None
except Exception as e:
print(f"β Exception in flattened prediction: {e}")
return None, None
def run_cnn_prediction():
"""Run the CNN sliding window prediction."""
print("\nπ§ Running CNN Sliding Window Prediction...")
print("-" * 50)
try:
result = subprocess.run([sys.executable, 'predict_with_cnn.py'],
capture_output=True, text=True, cwd='.')
if result.returncode == 0:
# Extract the final predictions from output
lines = result.stdout.split('\n')
decay_rate = None
surface_transfer = None
for line in lines:
if 'Decay Rate:' in line and 'Final CNN Results:' in result.stdout:
# Get the last occurrence (final results)
decay_rate = float(line.split(':')[1].strip())
elif 'Surface Transfer Fraction:' in line and 'Final CNN Results:' in result.stdout:
surface_transfer = float(line.split(':')[1].strip())
print(f"β
CNN Results:")
print(f" Decay Rate: {decay_rate:.6f}")
print(f" Surface Transfer Fraction: {surface_transfer:.6f}")
return decay_rate, surface_transfer
else:
print(f"β Error running CNN prediction: {result.stderr}")
return None, None
except Exception as e:
print(f"β Exception in CNN prediction: {e}")
return None, None
def summarize_predictions(flattened_results, cnn_results):
"""Provide a comprehensive summary of both predictions."""
print("\n" + "="*80)
print("π― COMPREHENSIVE PREDICTION SUMMARY FOR OBSERVED DATA")
print("="*80)
print(f"\nπ Prediction Results Comparison:")
print("-" * 60)
print(f"{'Method':<25} {'Decay Rate':<15} {'Surface Transfer':<15}")
print("-" * 60)
if flattened_results[0] is not None:
print(f"{'Flattened Neural Net':<25} {flattened_results[0]:<15.6f} {flattened_results[1]:<15.6f}")
else:
print(f"{'Flattened Neural Net':<25} {'Failed':<15} {'Failed':<15}")
if cnn_results[0] is not None:
print(f"{'CNN Sliding Windows':<25} {cnn_results[0]:<15.6f} {cnn_results[1]:<15.6f}")
else:
print(f"{'CNN Sliding Windows':<25} {'Failed':<15} {'Failed':<15}")
print("-" * 60)
# Calculate differences if both methods worked
if (flattened_results[0] is not None and cnn_results[0] is not None):
decay_diff = abs(flattened_results[0] - cnn_results[0])
surface_diff = abs(flattened_results[1] - cnn_results[1])
print(f"\nπ Method Comparison:")
print(f" Decay Rate difference: {decay_diff:.6f}")
print(f" Surface Transfer difference: {surface_diff:.6f}")
# Average predictions
avg_decay = (flattened_results[0] + cnn_results[0]) / 2
avg_surface = (flattened_results[1] + cnn_results[1]) / 2
print(f"\nπ― Ensemble Average Predictions:")
print(f" Average Decay Rate: {avg_decay:.6f}")
print(f" Average Surface Transfer Fraction: {avg_surface:.6f}")
# Provide confidence assessment
if decay_diff < 0.1 and surface_diff < 0.1:
confidence = "π’ High confidence - methods agree closely"
elif decay_diff < 0.2 and surface_diff < 0.2:
confidence = "π‘ Moderate confidence - some disagreement between methods"
else:
confidence = "π΄ Low confidence - significant disagreement between methods"
print(f"\nπ Prediction Confidence: {confidence}")
print(f"\nπ Method Details:")
print(f" β’ Flattened Neural Net: Uses 224 features (4 variables Γ 56 days)")
print(f" β’ CNN Sliding Windows: Uses 4Γ56 arrays with 4,431 training examples")
print(f" β’ Both methods trained on simulation data with sliding windows")
print(f"\nβ
Prediction analysis completed!")
def main():
"""Main function to run both prediction approaches and summarize results."""
print("π PARAMETER ESTIMATION FOR OBSERVED DATA")
print("="*80)
print("Running both prediction approaches for comprehensive analysis...")
# Run both prediction methods
flattened_results = run_flattened_prediction()
cnn_results = run_cnn_prediction()
# Summarize and compare results
summarize_predictions(flattened_results, cnn_results)
# Return the best estimate
if flattened_results[0] is not None and cnn_results[0] is not None:
# Use ensemble average as best estimate
best_decay = (flattened_results[0] + cnn_results[0]) / 2
best_surface = (flattened_results[1] + cnn_results[1]) / 2
print(f"\nπ FINAL RECOMMENDATION:")
print(f" Estimated Decay Rate: {best_decay:.6f}")
print(f" Estimated Surface Transfer Fraction: {best_surface:.6f}")
return best_decay, best_surface
elif flattened_results[0] is not None:
print(f"\nπ FINAL RECOMMENDATION (Flattened NN only):")
print(f" Estimated Decay Rate: {flattened_results[0]:.6f}")
print(f" Estimated Surface Transfer Fraction: {flattened_results[1]:.6f}")
return flattened_results
elif cnn_results[0] is not None:
print(f"\nπ FINAL RECOMMENDATION (CNN only):")
print(f" Estimated Decay Rate: {cnn_results[0]:.6f}")
print(f" Estimated Surface Transfer Fraction: {cnn_results[1]:.6f}")
return cnn_results
else:
print(f"\nβ PREDICTION FAILED - Both methods encountered errors")
return None, None
if __name__ == "__main__":
results = main()