# NOT RUN {
## a toy example
# generate parameters
C = matrix(c(1,2,3,2,9,0,3,0,7),nrow=3,byrow=TRUE)
A1 = matrix(c(1,0,1,0,3,7,1,7,5),nrow=3,byrow=TRUE)
A2 = matrix(c(0,2,8,2,6,0,8,0,4),nrow=3,byrow=TRUE)
A = list(A1, A2)
b = c(11, 19)
# run the algorithm
run = admm.sdp(C,A,b)
hst = run$history
# visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
plot(hst$objval, type="b", cex=0.25, main="objective value")
plot(hst$eps_pri, type="b", cex=0.25, main="primal feasibility")
plot(hst$eps_dual, type="b", cex=0.25, main="dual feasibility")
plot(hst$gap, type="b", cex=0.25, main="primal-dual gap")
par(opar)
# }
# NOT RUN {
## comparison with CVXR's result
require(CVXR)
# problems definition
X = Variable(3,3,PSD=TRUE)
myobj = Minimize(sum_entries(C*X)) # objective
mycon = list( # constraint
sum_entries(A[[1]]*X) == b[1],
sum_entries(A[[2]]*X) == b[2]
)
myp = Problem(myobj, mycon) # problem
# run and visualize
res = solve(myp)
Xsol = res$getValue(X)
opar = par(no.readonly=TRUE)
par(mfrow=c(1,2), pty="s")
image(run$X, axes=FALSE, main="ADMM result")
image(Xsol, axes=FALSE, main="CVXR result")
par(opar)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab