I am trying to solve the following optimization problem in CVXR using MOSEK solver. Objective_Fn The input matrix is data_C2 (50 X 30) and clust_center_C2 is a column matrix ( 50 X 1). S_C2 is the matrix (50 X 50) that I am trying to minimize. This is my R code
library(CVXR)
N <- ncol(data_C2)
predictors <- nrow(data_C2)
ones <- matrix(1, nrow = predictors, ncol = 1)
lambda <- 20
#==================================================================#
# Optimization variable
S_C2 <- Variable(rows = predictors, cols = predictors)
X_C2 <- data_C2
# Constraint
constr_C2 <- list(norm1(S_C2 %*% ones) <= lambda_req, S_C2[,] >= 0, S_C2[,] <= 1)
# Objective Function
objective_C2 <- 0
for (i in 1:N) {
objective_C2 <- objective_C2 +
square(norm2(clust_center_C2 - S_C2 %*% X_C2[,i]))
}
# CVXR
prob_C2 <- Problem(Minimize(objective_C2), constr_C2)
CVXR_result_C2 <- solve(prob_C2, solver = "MOSEK", verbose = TRUE)
# solution status by solver
CVXR_result_C2$status
# optimal value of beta
cvxrBeta_C2 <- CVXR_result_C2$getValue(S_C2)
min(cvxrBeta_C2)
max(cvxrBeta_C2)
The output obtained in R console
> CVXR_result_C2$status
[1] "optimal"
> min(cvxrBeta_C2)
[1] -2.11832e-09
> max(cvxrBeta_C2)
[1] 0.4402582
Though the solver says that the answer is optimal, the lower bound is negative when the constraint says that it must lie between zero and one. Can anyone tell what's wrong with the code?