r""" Generates n_projections samples from the uniform distribution on the Stiefel manifold of dimension :math:`d\times 2`: :math:`\mathbb{V}_{d,2}=\{X \in \mathbb{R}^{d\times 2}, X^TX=I_2\}` Parameters ---------- d : int dimension of the space n_projections : int
(d, n_projections, seed=None, backend=None, type_as=None)
| 289 | |
| 290 | |
| 291 | def get_projections_sphere(d, n_projections, seed=None, backend=None, type_as=None): |
| 292 | r""" |
| 293 | Generates n_projections samples from the uniform distribution on the Stiefel manifold of dimension :math:`d\times 2`: :math:`\mathbb{V}_{d,2}=\{X \in \mathbb{R}^{d\times 2}, X^TX=I_2\}` |
| 294 | |
| 295 | Parameters |
| 296 | ---------- |
| 297 | d : int |
| 298 | dimension of the space |
| 299 | n_projections : int |
| 300 | number of samples requested |
| 301 | seed: int or RandomState, optional |
| 302 | Seed used for numpy random number generator |
| 303 | backend: |
| 304 | Backend to use for random generation |
| 305 | type_as: optional |
| 306 | Type to use for random generation |
| 307 | |
| 308 | Returns |
| 309 | ------- |
| 310 | out: ndarray, shape (n_projections, d, 2) |
| 311 | |
| 312 | Examples |
| 313 | -------- |
| 314 | >>> n_projections = 100 |
| 315 | >>> d = 5 |
| 316 | >>> projs = get_projections_sphere(d, n_projections) |
| 317 | >>> np.allclose(np.einsum("nij, nik -> njk", projs, projs), np.eye(2)) # doctest: +NORMALIZE_WHITESPACE |
| 318 | True |
| 319 | """ |
| 320 | if backend is None: |
| 321 | nx = NumpyBackend() |
| 322 | else: |
| 323 | nx = backend |
| 324 | |
| 325 | if isinstance(seed, np.random.RandomState) and str(nx) == "numpy": |
| 326 | Z = seed.randn(n_projections, d, 2) |
| 327 | else: |
| 328 | if seed is not None: |
| 329 | nx.seed(seed) |
| 330 | Z = nx.randn(n_projections, d, 2, type_as=type_as) |
| 331 | |
| 332 | projections, _ = nx.qr(Z) |
| 333 | return projections |
| 334 | |
| 335 | |
| 336 | def projection_sphere_to_circle( |
no test coverage detected