Skip to content

Try to understand why we have a different solution with the two formulation #33

@amontoison

Description

@amontoison

It requires the branch gondzio-kkt.

using FFTW, CompressedSensingIPM, MadNLP
using LinearAlgebra, Test

Nt = 100
t = collect(0:(Nt-1))

x1 = 2 * cos.(2*pi*t*6/Nt)  .+ 3 * sin.(2*pi*t*6/Nt)
x2 = 4 * cos.(2*pi*t*10/Nt) .+ 5 * sin.(2*pi*t*10/Nt)
x3 = 6 * cos.(2*pi*t*40/Nt) .+ 7 * sin.(2*pi*t*40/Nt)
x = x1 .+ x2 .+ x3  # signal
y = x

rdft = true
w = fft(x) ./ sqrt(Nt)  # true DFT
DFTsize = size(x)  # problem dim
DFTdim = length(DFTsize)  # problem size
z0 = y

AT = Array
VT = Vector{Float64}

lambda = 0.0
index_missing = Int[]
parameters = FFTParameters(DFTdim, DFTsize, z0 |> AT, lambda, index_missing)
# Formulation 1
nlp = FFTNLPModel{VT}(parameters; rdft)

# Solve with MadNLP/CG
t1 = time()
solver = MadNLP.MadNLPSolver(
    nlp;
    max_iter=2000,
    kkt_system=FFTKKTSystem,
    nlp_scaling=false,
    print_level=MadNLP.INFO,
    dual_initialized=true,
    richardson_max_iter=0,
    tol=1e-8,
    richardson_tol=Inf,
)
results = CompressedSensingIPM.ipm_solve!(solver)
t2 = time()

beta_MadNLP = results.solution[1:Nt]
beta_true = CompressedSensingIPM.DFT_to_beta(DFTdim, DFTsize, w |> AT)
@test norm(beta_true - beta_MadNLP)  1e-6
# Formulation 2
nlp = GondzioNLPModel{VT}(parameters; rdft)

# Solve with MadNLP/CG
t1 = time()
solver = MadNLP.MadNLPSolver(
    nlp;
    max_iter=2000,
    kkt_system=GondzioKKTSystem,
    nlp_scaling=false,
    print_level=MadNLP.INFO,
    dual_initialized=true,
    richardson_max_iter=0,
    tol=1e-8,
    richardson_tol=Inf,
)
results = CompressedSensingIPM.ipm_solve!(solver)
t2 = time()

beta_MadNLP = results.solution[1:Nt] - results.solution[Nt+1:2*Nt]
beta_true = CompressedSensingIPM.DFT_to_beta(DFTdim, DFTsize, w |> AT)
@test norm(beta_true - beta_MadNLP)  1e-6

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions