We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4ad95e7 commit b866269Copy full SHA for b866269
src/torchjd/aggregation/_utils/dual_cone.py
@@ -60,3 +60,20 @@ def _to_array(tensor: Tensor) -> np.ndarray:
60
"""Transforms a tensor into a numpy array with float64 dtype."""
61
62
return tensor.cpu().detach().numpy().astype(np.float64)
63
+
64
65
+def estimate_dual_cone_spherical_volume(G: Tensor, n_samples=1_000_000) -> Tensor:
66
+ """
67
+ Estimates the spherical volume of the dual cone defined by the Gramian G.
68
69
+ n = G.size(0)
70
+ device = G.device
71
72
+ L = torch.linalg.cholesky(G + torch.eye(n, device=device) * 1e-10)
73
+ ws = torch.randn(n_samples, n, device=device)
74
+ zs = ws @ L.T
75
76
+ is_inside = torch.all(zs >= 0, dim=1)
77
+ proportion = is_inside.float().mean()
78
79
+ return proportion
0 commit comments