class_docstr: Class for PSD(n,k).
  
  The manifold of Positive Semi Definite matrices of rank k: PSD(n,k).
  
  Parameters
  ----------
  n : int
      Integer representing the shape of the matrices: n x n.
  k : int
      Integer representing the rank of the matrix (k<n).
class_docstr_tok: ["Class","for","PSD","(","n",",","k",")",".","The","manifold","of","Positive","Semi","Definite","matrices","of","rank","k",":","PSD","(","n",",","k",")",".","Parameters","--","--","--","--","--","n",":","int","Integer","representing","the","shape","of","the","matrices",":","n","x","n.","k",":","int","Integer","representing","the","rank","of","the","matrix","(","k","<","n",")","."]
docstr: Project a matrix to the space of PSD matrices of rank k.
  
  The nearest symmetric positive semidefinite matrix in the
  Frobenius norm to an arbitrary real matrix A is shown to be (B + H)/2,
  where H is the symmetric polar factor of B=(A + A')/2.
  As [Higham1988]_ is turning the matrix into a PSD, the rank
  is then forced to be k.
  
  Parameters
  ----------
  point : array-like, shape=[..., n, n]
      Matrix to project.
  
  Returns
  -------
  projected : array-like, shape=[..., n, n]
      PSD matrix rank k.
  
  References
  ----------
  .. [Higham1988] Highamm, N. J.
      “Computing a nearest symmetric positive semidefinite matrix.”
      Linear Algebra and Its Applications 103 (May 1, 1988):
      103-118. https://doi.org/10.1016/0024-3795(88)90223-6
docstr_tok: ["Project","a","matrix","to","the","space","of","PSD","matrices","of","rank","k.","The","nearest","symmetric","positive","semidefinite","matrix","in","the","Frobenius","norm","to","an","arbitrary","real","matrix","A","is","shown","to","be","(","B","+","H",")","\/2",",","where","H","is","the","symmetric","polar","factor","of","B=","(","A","+","A","'",")","\/2",".","As","[","Higham1988","]","_","is","turning","the","matrix","into","a","PSD",",","the","rank","is","then","forced","to","be","k.","Parameters","--","--","--","--","--","point",":","array-like",",","shape=","[","...",",","n",",","n","]","Matrix","to","project",".","Returns","--","--","--","-","projected",":","array-like",",","shape=","[","...",",","n",",","n","]","PSD","matrix","rank","k.","References","--","--","--","--","--","..","[","Higham1988","]","Highamm",",","N.","J",".","\u201c","Computing","a","nearest","symmetric","positive","semidefinite","matrix.","\u201d","Linear","Algebra","and","Its","Applications","103","(","May","1",",","1988",")",":","103-118.","https",":","\/\/doi.org\/10.1016\/0024-3795","(","88",")","90223-6"]
code: def projection(self, point):
      r"""Project a matrix to the space of PSD matrices of rank k.
  
      The nearest symmetric positive semidefinite matrix in the
      Frobenius norm to an arbitrary real matrix A is shown to be (B + H)/2,
      where H is the symmetric polar factor of B=(A + A')/2.
      As [Higham1988]_ is turning the matrix into a PSD, the rank
      is then forced to be k.
  
      Parameters
      ----------
      point : array-like, shape=[..., n, n]
          Matrix to project.
  
      Returns
      -------
      projected : array-like, shape=[..., n, n]
          PSD matrix rank k.
  
      References
      ----------
      .. [Higham1988] Highamm, N. J.
          “Computing a nearest symmetric positive semidefinite matrix.”
          Linear Algebra and Its Applications 103 (May 1, 1988):
          103-118. https://doi.org/10.1016/0024-3795(88)90223-6
      """
      sym = Matrices.to_symmetric(point)
      _, s, v = gs.linalg.svd(sym)
      h = gs.matmul(Matrices.transpose(v), s[..., None] * v)
      sym_proj = (sym + h) / 2
      eigvals, eigvecs = gs.linalg.eigh(sym_proj)
      k = self.n - self.rank
      i = gs.array([0.0] * k + [2 * gs.atol] * self.rank)
      regularized = (
          gs.hstack(
              [gs.zeros(point.shape[:-2] + (k,)), eigvals[..., k:]]
          )
          + i
      )
      reconstruction = gs.einsum(
          "...ij,...j->...ij", eigvecs, regularized
      )
  
      return Matrices.mul(reconstruction, Matrices.transpose(eigvecs))
  
imports: import geomstats.backend
  from geomstats.geometry.fiber_bundle import FiberBundle
  from geomstats.geometry.full_rank_matrices import FullRankMatrices
  from geomstats.geometry.general_linear import GeneralLinear
  from geomstats.geometry.manifold import Manifold
  from geomstats.geometry.matrices import Matrices, MatricesMetric
  from geomstats.geometry.quotient_metric import QuotientMetric
  from geomstats.geometry.spd_matrices import SPDEuclideanMetric, SPDMatrices
  from geomstats.geometry.special_orthogonal import SpecialOrthogonal
  from geomstats.geometry.symmetric_matrices import SymmetricMatrices
label_desc: Use image node_id 4 for calling the RankKPSDMatrices obj's underlying member method code with example usage: obj.projection(point) and returns: Matrices