modified: __pycache__/evaluation_studio.cpython-314.pyc
modified: evaluation_studio.py modified: scripts/dataset.py new file: scripts/inference_utils.py modified: scripts/predict_single.py modified: scripts_2/__pycache__/task3_identify.cpython-314.pyc modified: scripts_2/task3_identify.py
This commit is contained in:
@@ -97,7 +97,6 @@ def build_prediction_input(csv_path: Path, for_tmd: bool) -> dict:
|
||||
calculate_rms,
|
||||
estimate_sampling_rate,
|
||||
extract_core_features,
|
||||
extract_frequency_hz,
|
||||
get_dominant_frequency,
|
||||
get_middle_segment,
|
||||
)
|
||||
@@ -143,9 +142,7 @@ def build_prediction_input(csv_path: Path, for_tmd: bool) -> dict:
|
||||
has_truth = True
|
||||
|
||||
sampling_rate = estimate_sampling_rate(np.asarray(time_middle, dtype=np.float64))
|
||||
frequency_hz = extract_frequency_hz(csv_path.name)
|
||||
if frequency_hz is None:
|
||||
frequency_hz = get_dominant_frequency(np.asarray(x_middle, dtype=np.float32), sampling_rate)
|
||||
frequency_hz = get_dominant_frequency(np.asarray(x_middle, dtype=np.float32), sampling_rate)
|
||||
features = extract_core_features(np.asarray(x_middle, dtype=np.float32), sampling_rate, config, known_frequency_hz=frequency_hz)
|
||||
x_rms = float(calculate_rms(np.asarray(x_middle, dtype=np.float32)))
|
||||
|
||||
@@ -221,12 +218,20 @@ def save_prediction_overview_figure(
|
||||
|
||||
def run_task1(csv_path: Path) -> tuple[dict, Path]:
|
||||
from scripts.config import CORE_FEATURE_NAMES
|
||||
from scripts.inference_utils import predict_task1_tr
|
||||
|
||||
with CHECKPOINT_DEFAULT.open("rb") as handle:
|
||||
payload = pickle.load(handle)
|
||||
model = payload["model"]
|
||||
pred_input = build_prediction_input(csv_path=csv_path, for_tmd=False)
|
||||
pred_tr = max(float(model.predict([pred_input["features"].tolist()])[0]), pred_input["config"].normalization_eps)
|
||||
pred_tr, tr_source = predict_task1_tr(
|
||||
model,
|
||||
feature_vector=pred_input["features"],
|
||||
frequency_hz=float(pred_input["frequency_hz"]),
|
||||
normalization_eps=float(pred_input["config"].normalization_eps),
|
||||
project_root=PROJECT_ROOT,
|
||||
prefer_curve=True,
|
||||
)
|
||||
pred_rms = pred_tr * float(pred_input["x_rms"])
|
||||
true_rms = pred_input["true_y_rms"]
|
||||
rel_err_pct = None if true_rms is None else abs(pred_rms - true_rms) / max(abs(true_rms), 1e-12) * 100.0
|
||||
@@ -250,6 +255,7 @@ def run_task1(csv_path: Path) -> tuple[dict, Path]:
|
||||
"x_rms": float(pred_input["x_rms"]),
|
||||
"true_y_rms": None if true_rms is None else float(true_rms),
|
||||
"pred_tr": float(pred_tr),
|
||||
"pred_tr_source": str(tr_source),
|
||||
"pred_y_rms": float(pred_rms),
|
||||
"relative_error_percent": None if rel_err_pct is None else float(rel_err_pct),
|
||||
"truth_available": bool(pred_input["has_truth"]),
|
||||
@@ -378,13 +384,21 @@ def run_task3(csv_path: Path) -> tuple[dict, Path]:
|
||||
|
||||
def run_task4_tmd(csv_path: Path) -> tuple[dict, Path]:
|
||||
from scripts_4.adapter import load_adapter
|
||||
from scripts.inference_utils import predict_task1_tr
|
||||
|
||||
with CHECKPOINT_DEFAULT.open("rb") as handle:
|
||||
payload = pickle.load(handle)
|
||||
model = payload["model"]
|
||||
adapter, adapter_extra = load_adapter(ADAPTER_DEFAULT)
|
||||
pred_input = build_prediction_input(csv_path=csv_path, for_tmd=True)
|
||||
pred_tr = max(float(model.predict([pred_input["features"].tolist()])[0]), pred_input["config"].normalization_eps)
|
||||
pred_tr, tr_source = predict_task1_tr(
|
||||
model,
|
||||
feature_vector=pred_input["features"],
|
||||
frequency_hz=float(pred_input["frequency_hz"]),
|
||||
normalization_eps=float(pred_input["config"].normalization_eps),
|
||||
project_root=PROJECT_ROOT,
|
||||
prefer_curve=True,
|
||||
)
|
||||
pred_base = pred_tr * float(pred_input["x_rms"])
|
||||
pred_tmd = adapter.predict(pred_base, float(pred_input["frequency_hz"]))
|
||||
true_rms = pred_input["true_y_rms"]
|
||||
@@ -409,6 +423,7 @@ def run_task4_tmd(csv_path: Path) -> tuple[dict, Path]:
|
||||
"x_rms": float(pred_input["x_rms"]),
|
||||
"true_y_rms": None if true_rms is None else float(true_rms),
|
||||
"pred_base_y_rms": float(pred_base),
|
||||
"pred_tr_source": str(tr_source),
|
||||
"pred_tmd_y_rms": float(pred_tmd),
|
||||
"adapter_scale_k": float(adapter.scale_at(float(pred_input["frequency_hz"]))),
|
||||
"relative_error_percent": None if rel_err_pct is None else float(rel_err_pct),
|
||||
@@ -424,6 +439,7 @@ def build_key_metrics(task_label: str, result: dict) -> str:
|
||||
lines = [
|
||||
f"预测RMS: {result.get('pred_y_rms')}",
|
||||
f"预测TR: {result.get('pred_tr')}",
|
||||
f"TR来源: {result.get('pred_tr_source')}",
|
||||
f"激振频率(Hz): {result.get('frequency_hz')}",
|
||||
f"输入RMS(x): {result.get('x_rms')}",
|
||||
f"是否有真值: {'是' if result.get('truth_available') else '否'}",
|
||||
@@ -435,9 +451,15 @@ def build_key_metrics(task_label: str, result: dict) -> str:
|
||||
if task_label == TASK2_LABEL:
|
||||
lines = [
|
||||
f"自振频率f_n(Hz): {result.get('natural_frequency_hz')}",
|
||||
f"阻尼比zeta: {result.get('damping_ratio')}",
|
||||
f"精确阻尼比: {result.get('damping_ratio_exact')}",
|
||||
f"包络R²: {result.get('envelope_r2')}",
|
||||
f"局部阻尼比zeta: {result.get('damping_ratio')}",
|
||||
f"全局阻尼比zeta: {result.get('global_damping_ratio')}",
|
||||
f"最高峰后衰减阻尼比zeta: {result.get('max_tail_damping_ratio')}",
|
||||
f"局部精确阻尼比: {result.get('damping_ratio_exact')}",
|
||||
f"全局精确阻尼比: {result.get('global_damping_ratio_exact')}",
|
||||
f"最高峰后衰减精确阻尼比: {result.get('max_tail_damping_ratio_exact')}",
|
||||
f"局部包络R²: {result.get('envelope_r2')}",
|
||||
f"全局包络R²: {result.get('global_envelope_r2')}",
|
||||
f"最高峰后衰减包络R²: {result.get('max_tail_envelope_r2')}",
|
||||
f"采样率(Hz): {result.get('sampling_rate_hz')}",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
@@ -462,6 +484,7 @@ def build_key_metrics(task_label: str, result: dict) -> str:
|
||||
lines = [
|
||||
f"挑战任务预测RMS: {result.get('pred_tmd_y_rms')}",
|
||||
f"基础模型RMS: {result.get('pred_base_y_rms')}",
|
||||
f"TR来源: {result.get('pred_tr_source')}",
|
||||
f"适配系数k(f): {result.get('adapter_scale_k')}",
|
||||
f"激振频率(Hz): {result.get('frequency_hz')}",
|
||||
f"是否有真值: {'是' if result.get('truth_available') else '否'}",
|
||||
|
||||
Reference in New Issue
Block a user