Spaces:
Running

PhysInOne-Leaderboard / src /display /future_prediction.py
HAHAHA97's picture
change bar range
bd5c1e5
Raw History Blame Contribute Delete
4.12 kB
"""Independent display projections of existing, stored future-prediction metrics."""
import math
import pandas as pd
from src.tasks.future_prediction import TASK
from src.tasks.physiq_display import FUTURE_PHYSIQ_LABELS, metric_bar_modes_for_task, metric_bar_profiles_for_task, metric_ranges_for_task
VIEW_TITLES = {"train": "Training View Prediction", "novel": "Novel View Prediction"}
VIEW_METRICS = {"pmf": "PMF", "psnr": "PSNR", "ssim": "SSIM", "lpips": "LPIPS", **FUTURE_PHYSIQ_LABELS}
def view_frame(frame: pd.DataFrame, split: str) -> pd.DataFrame:
if split not in VIEW_TITLES:
raise ValueError("Unknown future-prediction view")
mapping = {TASK.column_display_names.get(f"{key}_{split}", f"{key}_{split}"): label
for key, label in VIEW_METRICS.items()}
columns = ["#", "Team", "Method", *mapping, "Scenes", "Updated At", "Submission"]
result = frame.reindex(columns=columns).rename(columns=mapping).copy()
result.attrs = dict(frame.attrs)
result.attrs["metric_directions"] = {label: label != "LPIPS" for label in VIEW_METRICS.values()}
ranges = {**metric_ranges_for_task(TASK), **frame.attrs.get("metric_ranges", {})}
result.attrs["metric_ranges"] = {label: ranges[source] for source, label in mapping.items() if source in ranges}
modes = {**metric_bar_modes_for_task(TASK), **frame.attrs.get("metric_bar_modes", {})}
result.attrs["metric_bar_modes"] = {label: modes[source] for source, label in mapping.items() if source in modes}
profiles = {**metric_bar_profiles_for_task(TASK), **frame.attrs.get("metric_bar_profiles", {})}
result.attrs["metric_bar_profiles"] = {label: profiles[source] for source, label in mapping.items() if source in profiles}
# Missing FP metrics use the same '-' placeholder, including PhysicsIQ.
# Keep the underlying null values and sorting metadata unchanged.
result.attrs["optional_metric_columns"] = []
result.attrs["split_view"] = split
result.attrs["metric_sort_values"] = {
identity: {label: values[source] for source, label in mapping.items() if source in values}
for identity, values in frame.attrs.get("metric_sort_values", {}).items()
}
if result.empty:
return result
def numeric(value):
if isinstance(value, bool):
return float("nan")
try:
number = float(value)
return number if math.isfinite(number) else float("nan")
except (ValueError, TypeError):
return float("nan")
def sort_key(row):
identity = row["Submission"]
return identity if pd.notna(identity) and identity else ("legacy", row["Team"], row["Method"])
if split == "novel":
optional = frame.attrs.get("optional_novel_submissions", set())
def valid_metric(row, label):
value = numeric(row[label])
bounds = result.attrs["metric_ranges"].get(label)
return math.isfinite(value) and (bounds is None or bounds[0] <= value <= bounds[1])
present = result.apply(lambda row: any(valid_metric(row, label) for label in VIEW_METRICS.values()), axis=1)
omitted = result.apply(lambda row: sort_key(row) in optional, axis=1)
result.attrs["unverified_missing_view_count"] = int((~present & ~omitted).sum())
result = result.loc[present & ~omitted].copy()
if result.empty:
return result
result["_pmf"] = result.apply(
lambda row: numeric(frame.attrs.get("metric_sort_values", {}).get(sort_key(row), {}).get(
next(iter(mapping)), row["PMF"])), axis=1)
result["_submitted"] = result.apply(
lambda row: frame.attrs.get("submission_times", {}).get(sort_key(row), float("inf")), axis=1)
result = result.sort_values(["_pmf", "_submitted", "Submission"], ascending=[False, True, True],
na_position="last", kind="stable").reset_index(drop=True)
result["#"] = pd.Series([index + 1 if pd.notna(value) else None for index, value in enumerate(result["_pmf"])], dtype=object)
return result.drop(columns=["_pmf", "_submitted"])