Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple example "Low-rank matrix completion" #3888

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/src/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ @article{Peng2007
doi = {10.1137/050641983},
}

@article{RechtFazelParrilo2010,
author = {Recht, Benjamin and Fazel, Maryam and Parrilo, Pablo A.},
title = {Guaranteed Minimum-Rank Solutions of Linear Matrix Equations via Nuclear Norm Minimization},
journal = {SIAM Review},
volume = {52},
number = {3},
pages = {471--501},
year = {2010},
issn = {0036-1445},
url = {https://www.jstor.org/stable/20780168},
}

@article{Zimmerman2011,
author = {Zimmerman, Ray Daniel and Murillo-Sánchez, Carlos Edmundo and Thomas, Robert John},
journal = {IEEE Transactions on Power Systems},
Expand Down
27 changes: 27 additions & 0 deletions docs/src/tutorials/conic/simple_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ S, T = solve_max_cut_sdp([0 5 7 6; 5 0 0 1; 7 0 0 1; 6 1 1 0])

S, T = solve_max_cut_sdp([0 1 5 0; 1 0 0 9; 5 0 0 2; 0 9 2 0])

# ## Low-rank matrix completion

# The matrix completion problem seeks to find the missing entries of a matrix
# with a given (possibly random) subset of fixed entries, such that the completed
# matrix has the lowest attainable rank.
#
# For more details, see [RechtFazelParrilo2010](@cite).

function example_matrix_completion(; svdtol = 1e-6)
rng = Random.MersenneTwister(1234)
n = 20
mask = rand(rng, 1:25, n, n) .== 1
B = randn(rng, n, n)
model = Model(SCS.Optimizer)
@variable(model, X[1:n, 1:n])
@constraint(model, X[mask] .== B[mask])
@variable(model, t)
@constraint(model, [t; vec(X)] in MOI.NormNuclearCone(n, n))
@objective(model, Min, t)
optimize!(model)
@assert is_solved_and_feasible(model)
## Return the approximate rank of the completed matrix to a given tolerance:
return sum(LinearAlgebra.svdvals(value.(X)) .> svdtol)
end

example_matrix_completion()

# ## K-means clustering via SDP

# Given a set of points ``a_1, \ldots, a_m`` in ``\mathbb{R}^n``, allocate them to ``k`` clusters.
Expand Down
Loading