[*] functions marked by [*] operate on mxn matrices in the same way they operate on the corresponding m*n-length column vector. Remarks:
Functions in alphabetical order
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 proj_box
Usage: proj_box(x,l,u)
Input:
x - point to be projected (vector/matrix)
l - 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 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 Usage: proj_halfspace(x,a,b)
Input:
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 Usage: proj_two_halfspaces(x,a1,b1,a2,b2)
Input:
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 Usage: proj_Lorentz(x)
Input:
Usage:
proj_hyperplane_box(x,a,b,[l],[u])
Input:
x - point to be projected (vector/matrix)
a - vector/matrix b - scalar l - 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
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:
execute
>> 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 l - 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
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 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
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 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
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
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 Usage:
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]
is computed by the formula
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 Usage:
Input:
X - symmetric matrix to be projected
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:
Input:
X - symmetric matrix to be projected
l - lower bound (scalar)
u - upper bound (scalar)
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:
Input:
X - matrix to be projected
r - radius (positive scalar) [default=1]
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:
Input:
X - matrix to be projected
r - radius (positive scalar) [default=1]
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 >> sum(svd(ans)) ans = 1 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 |