Download bbflow_base/tests/test_pca_projection_ceiling.py from hanghang214/data_transfer: direct link, hf CLI and curl.
- Browser
- Download file 907 Bytes
-
https://huggingface.co/datasets/hanghang214/data_transfer/resolve/main/bbflow_base/tests/test_pca_projection_ceiling.py
- Command line
-
hf download hf://datasets/hanghang214/data_transfer/bbflow_base/tests/test_pca_projection_ceiling.py
-
curl -L -o test_pca_projection_ceiling.py https://huggingface.co/datasets/hanghang214/data_transfer/resolve/main/bbflow_base/tests/test_pca_projection_ceiling.py
907 Bytes
| import math | |
| import torch | |
| from scripts.diagnose_pca_projection_ceiling import target_pca_metrics | |
| def test_target_pca_metrics_uses_covariance_trace_and_mean_offset(): | |
| local_cov = torch.zeros(2, 3, 3) | |
| local_cov[0, 0, 0] = 4.0 | |
| local_cov[0, 1, 1] = 3.0 | |
| local_cov[1, 2, 2] = 3.0 | |
| target = { | |
| "local_cov": local_cov, | |
| "oracle_energy": torch.tensor([4.0, 3.0, 2.0]), | |
| "oracle_mean_disp": torch.tensor([[3.0, 0.0, 0.0], [1.0, 0.0, 0.0]]), | |
| "res_mask": torch.ones(2), | |
| } | |
| metrics = target_pca_metrics(target, num_modes=2) | |
| assert metrics["num_res"] == 2 | |
| assert metrics["pca_explained_fraction"] == 0.7 | |
| assert math.isclose(metrics["pca_optimal_relative_rmse"], math.sqrt(0.3), rel_tol=1e-6) | |
| assert metrics["mean_offset_energy"] == 10.0 | |
| assert metrics["fluctuation_energy"] == 10.0 | |
| assert metrics["mean_fraction_of_total_energy"] == 0.5 | |