u_projection#

u_projection(a)[source]#

Return the orthogonal projection function over \(a\).

The function returned computes the orthogonal projection over \(a\) in the Hilbert space of \(U\)-centered distance matrices.

The projection of a matrix \(B\) over a matrix \(A\) is defined as

\[\begin{split}\text{proj}_A(B) = \begin{cases} \frac{\langle A, B \rangle}{\langle A, A \rangle} A, & \text{if} \langle A, A \rangle \neq 0, \\ 0, & \text{if} \langle A, A \rangle = 0. \end{cases}\end{split}\]

where \(\langle {}\cdot{}, {}\cdot{} \rangle\) is the scalar product in the Hilbert space of \(U\)-centered distance matrices, given by the function u_product().

Parameters

a (Array) – \(U\)-centered distance matrix.

Returns

Function that receives a \(U\)-centered distance matrix and computes its orthogonal projection over \(a\).

Return type

Callable[[Array], Array]

See also

u_complementary_projection u_centered

Examples

>>> import numpy as np
>>> import dcor
>>> a = np.array([[  0.,   3.,  11.,   6.],
...               [  3.,   0.,   8.,   3.],
...               [ 11.,   8.,   0.,   5.],
...               [  6.,   3.,   5.,   0.]])
>>> b = np.array([[  0.,  13.,  11.,   3.],
...               [ 13.,   0.,   2.,  10.],
...               [ 11.,   2.,   0.,   8.],
...               [  3.,  10.,   8.,   0.]])
>>> u_a = dcor.u_centered(a)
>>> u_a
array([[ 0., -2.,  1.,  1.],
       [-2.,  0.,  1.,  1.],
       [ 1.,  1.,  0., -2.],
       [ 1.,  1., -2.,  0.]])
>>> u_b = dcor.u_centered(b)
>>> u_b
array([[ 0.        ,  2.66666667,  2.66666667, -5.33333333],
       [ 2.66666667,  0.        , -5.33333333,  2.66666667],
       [ 2.66666667, -5.33333333,  0.        ,  2.66666667],
       [-5.33333333,  2.66666667,  2.66666667,  0.        ]])
>>> proj_a = dcor.u_projection(u_a)
>>> proj_a(u_a)
array([[ 0., -2.,  1.,  1.],
       [-2.,  0.,  1.,  1.],
       [ 1.,  1.,  0., -2.],
       [ 1.,  1., -2.,  0.]])
>>> proj_a(u_b)
array([[-0.        ,  2.66666667, -1.33333333, -1.33333333],
       [ 2.66666667, -0.        , -1.33333333, -1.33333333],
       [-1.33333333, -1.33333333, -0.        ,  2.66666667],
       [-1.33333333, -1.33333333,  2.66666667, -0.        ]])

The function gives the correct result if \(\\langle A, A \\rangle = 0\).

>>> proj_null = dcor.u_projection(np.zeros((4, 4)))
>>> proj_null(u_a)
array([[0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.]])