Orthogonal projections


 MATLAB function underlying set   input  assumptions
proj_Euclidean_ball[*]  Euclidean ball 

- point  to be projected (vector/matrix)
- center of the ball (vector/matrix)
 - positive radius (positive scalar)
l2 or Frobenius norm   
 proj_box[*]  box

 
- point to be projected (vector/matrix)
 - lower bounds (vector/matrix/scalar)
- upper bounds (vector/matrix/scalar)
 proj_affine_set affine set

 
 - column vector to be projected
- mxn matrix
- m-length column vector
 with full row rank 
 proj_halfspace[*]  half-space

 
 - point to be projected (vector/matrix)
- vector/matrix
 - scalar 
 
 proj_two_halfspaces[*]  intersection of two half-spaces


 
 - point to be projected (vector/matrix)
-vector/matrix

- scalar
 - vector/matrix
 - scalar
 
 linearly independent 
 proj_Lorentz Lorentz cone

 
 - (n+1)-length column vector to be projected   
 proj_hyperplane_box[*]  intersection of a hyperplane and a box

 
 - point to be projected (vector/matrix)
 -vector/matrix
 - scalar
 - lower bounds (vector/matrix/scalar)
 - upper bounds (vector/matrix/scalar)
 proj_halfspace_box[*]  intersection of a halfspace and a box

 
 - point to be projected (vector/matrix)
 -vector/matrix
 - scalar
 - lower bounds (vector/matrix/scalar)
 - upper bounds (vector/matrix/scalar) 
 
proj_simplex[*]   r-simplex  



r-full simplex



 - point to be projected (vector/matrix)
- radius (scalar)
eq_flag - a flag that determines whether the
              projection is onto the r-simplex ('eq') or
              the r-full simplex ('ineq')

 proj_product[*]  product superlevel set 


 - point to be projected (vector/matrix)
 - scalar
 
 proj_l1_ball[*]  l1 ball

 - point to be projected (vector/matrix) 
 - radius 
 
 proj_l1ball_box[*]  intersection of weighted l1 ball
and a box 


 - point to be projected (vector/matrix)
-weights (vector/matrix)
 - radius (scalar)
 - bounds (vector/matrix/scalar)  
 
proj_psd  cone of positive semidefinite matrics
(psd cone)

 
- matrix to be projected    symmetric 
 proj_spectral_box_sym spectral box
(in the set of nxn symmetric matrices)


 - matrix to be projected   
 - lower bound (scalar)
 - upper bound (scalar) 
 symmetric  
proj_spectral_ball  spectral-norm ball

 - matrix to be projected 
 - radius (scalar)
 
  proj_nuclear_ball  nuclear-norm ball

 
 - matrix to be projected 
 - radius (scalar)
  
 proj_spectahedron r-spectahedron



r-full spectahedron


- symmetric matrix to be projected
 - radius (scalar)
eq_flag - a flag that determines whether the 
            projection is onto the r-spectahedron ('eq') or 
            the r-full spectahedron ('ineq')
 
 symmetric  

[*] functions marked by [*] operate on mxn matrices in the same way they operate on the corresponding m*n-length column vector.

Remarks:
  • "vectors" are always column vectors. 
  • The projection is done w.r.t. either the l2-norm or the Frobenuis norm. 
  • The underlying inner product is the dot product. 
  • The output is always the projection vector/matrix

Functions in alphabetical order




proj_Euclidean_ball

Usage: proj_Euclidean_ball(x,[c],[r])

Input: 
x - point  to be projected (vector/matrix)
c - center of the ball (vector/matrix) [default c=0]
r - positive radius (positive scalar) [default r=1]

Method: employs the formula 



Example: project the vector [1;2;3] onto the ball with center [0;0;0] and radius 2
>> proj_Euclidean_ball([1;2;3],zeros(3,1),2)

ans =

    0.5345
    1.0690
    1.6036

If the input is a matrix, then the corresponding norm is the Frobenius norm

>> proj_Euclidean_ball([1,2,3;4,5,6],ones(2,3),1)

ans =

    1.0000    1.1348    1.2697
    1.4045    1.5394    1.6742

The default value of the radius is 1, so there is no need to put it as an input

>> proj_Euclidean_ball([1,2,3;4,5,6],ones(2,3))

ans =

    1.0000    1.1348    1.2697
    1.4045    1.5394    1.6742
top of page


proj_box

Usage: proj_box(x,l,u)

Input: 

x -  point to  be projected (vector/matrix)
- lower bounds (vector/matrix/scalar)
u- upper bounds (vector/matrix/scalar)

Method: employs the formula 

Example: project the vector [1;-1;2] onto the box with lower bounds [0;0;3] and upper bounds [2;3;5]

>> proj_box([1;-1;2], [0;0;3], [2;3;5])

ans =

     1
     0
     3

upper and/or lower bounds may be infinite. The nonnegative orthant of dimension 3, for example, is described by a lower bounds vector  [0;0;0] and upper bounds vector of all-infinities.
Thus, to project the vector [-2;2;3] onto the nonnegative orthant, the following should be executed.

>> proj_box([-2;2;3],zeros(3,1),Inf*ones(3,1))

ans =

     0
     2
     3


proj_affine_set

Usage: proj_affine_set(x,A,b)

Input:

x - column vector to be projected
A - mxn matrix
b - m-length column vector

Method: employs the formula 

Example: project the vector [1;0;1] on the affine set 

>> A=[1,1,1;1,-1,0];
>> b=[1;0];
>> proj_affine_set([1;0;1],A,b)

ans =

    0.1667
    0.1667
    0.6667


proj_halfspace

Usage: proj_halfspace(x,a,b)

Input: 

x - point to be projected (vector/matrix)
a - vector/matrix
b - scalar

Method: employs the formula 

Example: project the matrix [1,0,5;-4,1,-1] onto the half-space 

>> X=[1,0,5;-4,1,-1];
>> proj_halfspace(X,[1,1,1;1,1,1],1)

ans =

    0.8333   -0.1667    4.8333
   -4.1667    0.8333   -1.1667

As a sanity check, we can compute the sum of all components in the obtained matrix

>> sum(sum(ans))

ans =

    1.0000


proj_two_halfspaces

Usage: proj_two_halfspaces(x,a1,b1,a2,b2)

Input:

x - point to be projected (vector/matrix)
a1 -vector/matrix
b1 - scalar
a2 - vector/matrix
b2- scalar

Method: Employs the formula 

where 
 
Example: project the vector [1;-1;2] onto the following intersection of two half-spaces:


>> proj_two_halfspaces([1;-1;2],[1;1;1],1,[0;-1;0],0)

ans =

     0
     0
     1


proj_Lorentz

Usage: proj_Lorentz(x)

Input:

x - (n+1)-length column vector to be projected

Method: Employs the formula 
Example: project the vector [2;3;1] onto L2

>> proj_Lorentz([2;3;1])

ans =

    1.2774
    1.9160
    2.3028
top of page


proj_hyperplane_box    

Usage: 

proj_hyperplane_box(x,a,b,[l],[u])

Input:
x - point to be projected (vector/matrix)
a - vector/matrix
b - scalar
- lower bounds (vector/matrix/scalar) [default=-Inf]
u - upper bounds (vector/matrix/scalar) [default=Inf]

Method: the projection onto 
is computed by the formula 
where is a solution of the equation 
The root is found by bisection.

Example: To project the matrix [1,-2;3,1] on the set of all 2x2 matrices with equal sums of rows:

execut
>> proj_hyperplane_box([-1,2;3,1],[1,1;-1,-1],0,-Inf,Inf)

ans =

   -0.2500    2.7500
    2.2500    0.2500

The same can be accomplished without specifying the lower and upper bounds since these are the default values.
>> proj_hyperplane_box([-1,2;3,1],[1,1;-1,-1],0)

ans =

   -0.2500    2.7500
    2.2500    0.2500

If we add the constraint that all the components are nonnegative and the (1,2)-element is bounded above by 2.7, we can compute the projection by the following command.
>>  proj_hyperplane_box([-1,2;3,1],[1,1;-1,-1],0,0,[Inf,2.7;Inf,Inf])

ans =

         0    2.6667
    2.3333    0.3333


Usage: 

proj_halfspace_box(x,a,b,[l],[u])

Input:

x - point to be projected (vector/matrix)
a - vector/matrix
b - scalar
- lower bounds (vector/matrix/scalar) [default=-Inf]
u - upper bounds (vector/matrix/scalar) [default=Inf]

Method: the projection onto
is computed by the formula 
where  is a nonnegative solution of the equation 
The root is found by bisection.
   
Example: project the vector [1;2;2;-1] onto the halfspace
>> proj_halfspace_box([1;2;2;-1],[1;1;-1;-1],0)

ans =

    0.5000
    1.5000
    2.5000
   -0.5000

The projection can obviously be computed using the function proj_halfspace 
>> proj_halfspace([1;2;2;-1],[1;1;-1;-1],0)

ans =

    0.5000
    1.5000
    2.5000
   -0.5000

To project (1,2,2,-1)T onto the set 

execute
>> proj_halfspace_box([1;2;2;-1],[1;1;-1;-1],0,0,2)

ans =

    0.5000
    1.5000
    2.0000
         0
top of page


proj_simplex

Usage:

proj_simplex(x,[r],[flag_eq])

Input:

x - point to be projected (vector/matrix)
r - radius (positive scalar)  [default=1]
eq_flag - a flag indicating whether the constraint on the sum is an equality constraint ('eq') or an inequality constraint ('ineq') [default='eq']

Method: calls 
 proj_hyperplane_box(x,ones(size(x)),r,zeros(size(x))) if flag='eq' or 
 proj_halfspace_box(x,ones(size(x)),r,zeros(size(x))) if flag='ineq'

Example: project the vector [0;0.5;-0.1] onto the unit simplex

>> proj_simplex([0;0.5;-0.1])

ans =

    0.2000
    0.7000
    0.1000

projecting the same vector onto the unit full simplex gives a different result

>> proj_simplex([0;0.5;-0.1],[],'ineq')

ans =

         0
    0.5000
         0

The projection onto the 2-simplex set is computed as follows

>> proj_simplex([0;0.5;-0.1],2)

ans =

    0.5333
    1.0333
    0.4333
top of page


proj_product

Usage: 

proj_product(x,r)

Input:

x - point to be projected (vector/matrix)
r - positive scalar

Method: the projection onto
is computed by the formula 
where the parameter  is positive root of the function
The root is found by bisection.

Example: project the vector [2;1;-3] onto the set 

>> proj_product([2;1;-3],1)

ans =

    2.3717
    1.5638
    0.2696


proj_l1_ball

Usage: 

proj_l1_ball(x,[r])

Input:

x - point to be projected (vector/matrix)
r - radius (positive scalar) [default=1]

Method: calls
sign(x) .* proj_simplex(abs(x),r,'ineq') ;

Example: project the vector [10;-4;5] onto the l1 unit ball (no need to specify the radius as the default is 1)

>> proj_l1_ball([10;-4;5])

ans =

     1
     0
     0

Project the same point on the l1 ball with radius 10

>> proj_l1_ball([10;-4;5],10)

ans =

     7
    -1
     2

The function can also be used on matrices where the l1 norm means the sum of absolute values of all components of the matrix. To project [1,2,-1;2,1,1] onto the l1 ball with radius 2 the following should be executed

>> proj_l1_ball([1,2,-1;2,1,1],2)

ans =

     0     1     0
     1     0     0
top of page


proj_l1ball_box

Usage: 

proj_l1ball_box(x,[r],[w],[u])

Input:

x - point to be projected (vector/matrix)
r - radius (positive scalar) [default=1]
w - weights (vector/matrix) [default=vector/matrix of all ones]
u - bounds (vector/matrix/scalar) [defalut=Inf]

Method: the projection onto the set 
is computed by the formula 
where
and is a root of the function 

Example: project the vector [1;2;-3] onto the unit l1-norm ball

>> proj_l1ball_box([1;2;-3])

ans =

     0
     0
    -1

This can also be computed using proj_l1_ball

>> proj_l1_ball([1;2;-3])

ans =

     0
     0
    -1

The projection of [1;2;-3] onto the set 
is computed by 

>> proj_l1ball_box([1;2;-3],[],1,0.5)

ans =

         0
    0.5000
   -0.5000

projecting [1;2;-3] onto 
can be done by 

>> proj_l1ball_box([1;2;-3],[1;1;0],0.1,0.5)

ans =

         0
    0.1000
   -0.5000


proj_psd

Usage: 

proj_psd(X)

Input:

X - symmetric matrix to be projected 

Method: employs the formula 
where  
is a spectral decomposition of X. 

Example: the matrix [1,2;2,1] is not positive semidefinite

>> eig([1,2;2,1])

ans =

    -1
     3

Projecting it onto the cone of positive semidefinite matrices is done by the command 

>> proj_psd([1,2;2,1])

ans =

    1.5000    1.5000
    1.5000    1.5000

The resulting matrix is indeed a positive semidefinite matrix 

>> eig(ans)

ans =

         0
    3.0000


proj_spectral_box_sym

Usage: 

proj_spectral_box_sym(X,l,u)

Input:

X - symmetric matrix to be projected 
l - lower bound (scalar)
u - upper bound (scalar)

Method: the projection onto 
is computed by the formula 
where  
is a spectral decomposition of X. 

Example: the eigenvalues of the matrix  [1,2,1;2,1,2;1,2,1] are

>> X=[1,2,1;2,1,2;1,2,1];
>> eig(X)

ans =

   -1.3723
   -0.0000
    4.3723

To project the matrix onto the set of matrices with eigenvalues between -1 and 4, we execute

>> ans=proj_spectral_box_sym(X,-1,4)

ans =

    0.9676    1.7408    0.9676
    1.7408    1.0648    1.7408
    0.9676    1.7408    0.9676

The eigenvalues of the resulting matrix are indeed between -1 and 4

>> eig(ans)

ans =

   -1.0000
    0.0000
    4.0000


proj_spectral_ball

Usage: 

proj_spectral_ball(X,[r])

Input:

X - matrix to be projected 
r - radius (positive scalar) [default=1]

Method: employs 
the formula 
where  
is a singular value decomposition of X. 

Example: the singular values of the matrix [1,2,0;1,-1,1] are 

>> A=[1,2,0;1,-1,1];
>> svd(A)

ans =

    2.3268
    1.6080

The projection of the  matrix onto the spectral ball with radius 2 is 

>> proj_spectral_ball(A,2)

ans =

    0.9298    1.7105    0.0497
    1.0291   -0.8801    0.9794

The singular values of the resulting matrix are indeed smaller or equal to 2

>> svd(ans)

ans =

    2.0000
    1.6080


proj_nuclear_ball

Usage: 

proj_nuclear_ball(X,[r])

Input:

X - matrix to be projected 
r - radius (positive scalar) [default=1]

Method: employs 
the formula 
where  
is a singular value decomposition of X. 

Example: the singular values of the matrix [1,2,0;1,-1,1] are 

>> A=[1,2,0;1,-1,1];
>> svd(A)

ans =

    2.3268
    1.6080

The projection of the matrix on the nuclear norm ball with radius 1 is

>> proj_nuclear_ball(A)

ans =

    0.2284    0.7558   -0.0997
    0.0290   -0.3281    0.1287

As a sanity check, we can observe that the vector of singular values of the projected matrix sums up to 1

>> sum(svd(ans))

ans =

     1


proj_spectahedron

Usage:

proj_spectahedron(x,[r],[flag_eq])

Input:

X - symmetric matrix to be projected
r - radius (positive scalar)  [default=1]
eq_flag - a flag indicating whether the constraint on the sum is an equality constraint ('eq') or an inequality constraint ('ineq') [default='eq']

Method: calls
          V * diag(proj_simplex(diag(D),r,eq_flad)) * V' ; 
where [V,D]=eig(X)

Example: The projection onto the unit-spectahedron of the matrix [1,2,0;2,1,2;0,2,1] is 

>> A=[1,2,0;2,1,2;0,2,1];
>> proj_spectahedron(A)

ans =

    0.2500    0.3536    0.2500
    0.3536    0.5000    0.3536
    0.2500    0.3536    0.2500

The eigenvalues of the output matrix are, as expected, in the unit-simplex

>> eig(ans)

ans =

   -0.0000
    0.0000
    1.0000

To project the matrix onto the spectahedron with radius 3, execute

>> proj_spectahedron(A,3)

ans =

    0.7714    1.0303    0.6857
    1.0303    1.4571    1.0303
    0.6857    1.0303    0.7714