MCPcopy Create free account
hub / github.com/PythonOT/POT / proj_SDP

Function proj_SDP

ot/utils.py:1388–1425  ·  view source on GitHub ↗

Project a symmetric matrix onto the space of symmetric matrices with eigenvalues larger or equal to `vmin`. Parameters ---------- S : array_like (n, d, d) or (d, d) The input symmetric matrix or matrices. nx : module, optional The numerical backend module to

(S, nx=None, vmin=0.0)

Source from the content-addressed store, hash-verified

1386
1387
1388def proj_SDP(S, nx=None, vmin=0.0):
1389 """
1390 Project a symmetric matrix onto the space of symmetric matrices with
1391 eigenvalues larger or equal to `vmin`.
1392
1393 Parameters
1394 ----------
1395 S : array_like (n, d, d) or (d, d)
1396 The input symmetric matrix or matrices.
1397 nx : module, optional
1398 The numerical backend module to use. If not provided, the backend will
1399 be fetched from the input matrix `S`.
1400 vmin : float, optional
1401 The minimum value for the eigenvalues. Eigenvalues below this value will
1402 be clipped to vmin.
1403
1404 .. note:: This function is backend-compatible and will work on arrays
1405 from all compatible backends.
1406
1407 Returns
1408 -------
1409 P : ndarray (n, d, d) or (d, d)
1410 The projected symmetric positive definite matrix.
1411
1412 """
1413 if nx is None:
1414 nx = get_backend(S)
1415
1416 w, P = nx.eigh(S)
1417 w = nx.clip(w, vmin, None)
1418
1419 if len(S.shape) == 2: # input was (d, d)
1420 return P @ nx.diag(w) @ P.T
1421
1422 else: # input was (n, d, d): broadcasting
1423 Q = nx.einsum("ijk,ik->ijk", P, w) # Q[i] = P[i] @ diag(w[i])
1424 # R[i] = Q[i] @ P[i].T
1425 return nx.einsum("ijk,ikl->ijl", Q, nx.transpose(P, (0, 2, 1)))
1426
1427
1428def exp_bures(Sigma, S, nx=None):

Callers 1

plot_GMM_flow.pyFile · 0.90

Calls 6

get_backendFunction · 0.85
eighMethod · 0.45
clipMethod · 0.45
diagMethod · 0.45
einsumMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected