Skip to content

Instantly share code, notes, and snippets.

@loiseaujc
Last active February 16, 2021 12:02
Show Gist options
  • Save loiseaujc/bbcb6679dd088ce37b4e5c002749258c to your computer and use it in GitHub Desktop.
Save loiseaujc/bbcb6679dd088ce37b4e5c002749258c to your computer and use it in GitHub Desktop.
using LinearAlgebra
using Convex, SCS
# --> Direct resolution of the measurement equation.
lstsq(Θ, y) = Θ \ y
# --> Constrained least-squares formulation.
function cstrnd_lstsq(Θ, y, Σ)
# --> Optimization variable.
a = Convex.Variable(length(Σ))
# --> Objective function to be minimized.
prob = minimize( sumsquares(Θ * a - y) )
# --> Linear inequality constraints.
prob.constraints += abs(a) <= 2Σ
# --> Solve the problem using the SCS solver.
solve!(prob, SCS.Optimizer())
return Convex.evaluate(a)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment