File size: 4,184 Bytes
0f755ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import time
import sys
import os
import random

# ANSI Colors for "Hacker Mode" Dashboard
class Colors:
    HEADER = '\033[95m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'

def main():
    print(f"{Colors.HEADER}╔══════════════════════════════════════════════════════════════╗{Colors.ENDC}")
    print(f"{Colors.HEADER}β•‘      FUSION REACTOR SAFETY MONITOR - HYBRID AI SYSTEM        β•‘{Colors.ENDC}")
    print(f"{Colors.HEADER}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•{Colors.ENDC}")
    print("Loading Neural Links...")
    time.sleep(1)

    # 1. LOAD THE "TRUTH" DATA
    try:
        q_data = np.load("qsvc_results/qsvc_results.npz")
        q_preds = q_data['preds']
        y_test = q_data['targets']
        
        # Regenerate Classical Predictions
        possible_paths = ['vG.0.1/qgan_data_optimized.npz', 'qgan_data_optimized.npz']
        data_path = next((p for p in possible_paths if os.path.exists(p)), None)
        data = np.load(data_path)
        
        from sklearn.ensemble import RandomForestClassifier
        rf = RandomForestClassifier(n_estimators=100, random_state=42)
        rf.fit(data['X_train'], data['y_train'])
        
        # Predict on same subset
        X_test_sub = data['X_test'][:len(q_preds)]
        c_preds = rf.predict_proba(X_test_sub)[:, 1]

    except Exception as e:
        print(f"{Colors.FAIL}System Error: Could not load model history.{Colors.ENDC}")
        print(e)
        return

    print(f"{Colors.GREEN}βœ” System Online.{Colors.ENDC}\n")
    print(f"{'SHOT ID':<10} | {'CLASSICAL GUARD':<20} | {'QUANTUM GUARD':<20} | {'STATUS'}")
    print("-" * 75)

    events_found = 0
    
    for i in range(len(y_test)):
        c_score = c_preds[i]
        q_score = q_preds[i]
        is_disruption = y_test[i] == 1
        
        # Formatting
        c_status = f"{c_score:.2f} (SAFE)" if c_score < 0.5 else f"{c_score:.2f} {Colors.FAIL}(WARN){Colors.ENDC}"
        q_status = f"{q_score:.2f} (SAFE)" if q_score < 0.5 else f"{q_score:.2f} {Colors.FAIL}(WARN){Colors.ENDC}"
        
        final_msg = ""
        delay = 0.05 # Default delay
        
        # --- LOGIC TREE ---
        
        # A. BORING (Both Safe)
        if (c_score < 0.5 and q_score < 0.5):
            final_msg = f"{Colors.GREEN}STABLE{Colors.ENDC}"
            delay = 0.02 # Fast forward
            
        # B. AGREEMENT (Both Danger)
        elif (c_score > 0.5 and q_score > 0.5):
             final_msg = f"{Colors.WARNING}MITIGATED{Colors.ENDC}"
             delay = 0.1

        # C. THE QUANTUM SAVE (The Money Shot)
        elif (c_score < 0.5 and q_score > 0.5 and is_disruption):
            events_found += 1
            print("-" * 75)
            print(f"{Colors.BOLD}>>> ANOMALY DETECTED IN SHOT {i} <<<{Colors.ENDC}")
            print(f"    Classical AI: {Colors.GREEN}SAFE ({c_score:.2f}){Colors.ENDC} --> ❌ FALSE NEGATIVE")
            print(f"    Quantum AI:   {Colors.FAIL}DANGER ({q_score:.2f}){Colors.ENDC} --> βœ… TRUE POSITIVE")
            print(f"    ACTION:       {Colors.WARNING}[TRIGGERING EMERGENCY SHUTDOWN]{Colors.ENDC}")
            print("-" * 75)
            time.sleep(1.5) 
            continue 

        # D. FALLBACK (Disagreements that aren't saves, or False Alarms)
        else:
             final_msg = f"{Colors.BLUE}ANALYZING{Colors.ENDC}"
             delay = 0.05

        # Print Logic (Skip boring lines to keep screen moving)
        if delay == 0.02 and i % 10 != 0:
            continue
            
        print(f"{i:<10} | {c_status:<29} | {q_status:<29} | {final_msg}")
        time.sleep(delay)

        if events_found >= 5:
            print(f"\n{Colors.BOLD}Simulation Limit Reached. 5 Quantum Saves Demonstrated.{Colors.ENDC}")
            break

if __name__ == "__main__":
    main()