295057e80b
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
118 lines
3.7 KiB
Python
118 lines
3.7 KiB
Python
import sys
|
||
import os
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
|
||
def print_header():
|
||
print("=" * 42)
|
||
print(" Inverse Heat PINN")
|
||
print(" Identifica: α, k, h_conv da misure")
|
||
print("=" * 42)
|
||
|
||
|
||
_ALL_PARAMS = ('alpha', 'k', 'h_conv')
|
||
|
||
|
||
def _ask_identify():
|
||
print(f"\nParametri disponibili: {', '.join(_ALL_PARAMS)}")
|
||
raw = input("Quali identificare? (invio = tutti, oppure es: alpha k): ").strip()
|
||
chosen = [p for p in (raw.split() if raw else _ALL_PARAMS) if p in _ALL_PARAMS]
|
||
invalid = [p for p in raw.split() if p not in _ALL_PARAMS] if raw else []
|
||
if invalid:
|
||
print(f" Ignorati (non validi): {invalid}")
|
||
if not chosen:
|
||
print(" Nessun parametro valido — uso tutti.")
|
||
chosen = list(_ALL_PARAMS)
|
||
print(f" Identifico: {chosen}")
|
||
|
||
import config as _cfg
|
||
_true = {'alpha': _cfg.ALPHA, 'k': _cfg.K, 'h_conv': _cfg.H_CONV}
|
||
|
||
init_vals = {}
|
||
for p in chosen:
|
||
true_val = _true[p]
|
||
raw_v = input(f" Valore iniziale per {p} (vero: {true_val}): ").strip()
|
||
try:
|
||
init_vals[p] = float(raw_v) if raw_v else true_val
|
||
except ValueError:
|
||
init_vals[p] = true_val
|
||
print(f" → {p} inizia da {init_vals[p]}")
|
||
|
||
from inverse.config_inverse import W_PDE, W_IC, W_BC, W_DATA
|
||
print(f"\nPesi loss (default — PDE:{W_PDE} IC:{W_IC} BC:{W_BC} Data:{W_DATA})")
|
||
weights = {}
|
||
for wname, wdefault in [('w_pde', W_PDE), ('w_ic', W_IC), ('w_bc', W_BC), ('w_data', W_DATA)]:
|
||
raw_w = input(f" {wname} (default {wdefault}): ").strip()
|
||
try:
|
||
weights[wname] = float(raw_w) if raw_w else wdefault
|
||
except ValueError:
|
||
weights[wname] = wdefault
|
||
|
||
raw_ep = input("\nNumero di epoch (default 10000): ").strip()
|
||
try:
|
||
epochs = int(raw_ep) if raw_ep else 10000
|
||
except ValueError:
|
||
epochs = 10000
|
||
|
||
return chosen, init_vals, weights, epochs
|
||
|
||
|
||
def main():
|
||
print_header()
|
||
|
||
from inverse.engine import prepare_data_inverse, _get_device
|
||
print("\nGenerazione punti di collocazione...")
|
||
data = prepare_data_inverse()
|
||
print(f"Pronti — device: {data['device']}\n")
|
||
|
||
x_s = None
|
||
t_s = None
|
||
T_meas = None
|
||
|
||
while True:
|
||
print("\n" + "-" * 34)
|
||
print(" MAIN MENU")
|
||
print("-" * 34)
|
||
print("1. Carica misure")
|
||
print("2. Addestra (identifica α, k, h)")
|
||
print("3. Valuta risultati")
|
||
print("4. Visualizza")
|
||
print("0. Esci")
|
||
print("-" * 34)
|
||
|
||
choice = input("Scelta (0-4): ").strip()
|
||
|
||
if choice == "1":
|
||
from inverse.data import load_measurements
|
||
x_s, t_s, T_meas = load_measurements(data['device'])
|
||
|
||
elif choice == "2":
|
||
if x_s is None:
|
||
print("Caricare prima le misure (opzione 1).")
|
||
continue
|
||
identify, init_vals, weights, epochs = _ask_identify()
|
||
from inverse.engine import train_inverse
|
||
try:
|
||
train_inverse(data, x_s, t_s, T_meas, identify=identify, init_vals=init_vals, epochs=epochs, **weights)
|
||
except KeyboardInterrupt:
|
||
print("\nTraining interrotto. Il miglior modello trovato è stato salvato.")
|
||
|
||
elif choice == "3":
|
||
from inverse.engine import evaluate_inverse
|
||
evaluate_inverse()
|
||
|
||
elif choice == "4":
|
||
from inverse.engine import generate_visualization_inverse
|
||
generate_visualization_inverse()
|
||
|
||
elif choice == "0":
|
||
print("Uscita.")
|
||
sys.exit(0)
|
||
|
||
else:
|
||
print("Scelta non valida.")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|