-
Notifications
You must be signed in to change notification settings - Fork 35
LSR1Operator(1) fails the secant equation #225
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Is every update accepted? https://github.com/JuliaSmoothOptimizers/LinearOperators.jl/blob/main/src/lsr1.jl#L150 |
The conditions for the update are fulfilled in the code above. The strange thing is that in some cases the update happens, and in other cases it does not happen. B = LSR1Operator(1)
s = [0.5809871055619441]
y = [0.8263178027435335]
push!(B, s, y) #1×1 Matrix{Float64}: 1.4222653047425207 produces an updated To extend the analysis, I tried the n = 1
r = 0.0
cpt = 0
cpt_approx_null = 0
for i = 1:100
B = LSR1Operator(n)
global r
global cpt
global cpt_approx_null
s = rand(n)
y = rand(n)
ϵ = eps(eltype(y))
ymBs = y - B * s
well_defined(ymBs, s) = abs(dot(ymBs, s)) ≥ ϵ + ϵ * norm(ymBs) * norm(s, 2)
sufficient_curvature(s, y) = abs(dot(y, s)) >= ϵ * norm(y, 2) * norm(s, 2)
scaling_factor(s, y) = dot(y, s) / dot(y, y)
scaling_condition(s, y) = norm((y - s) / scaling_factor(s, y), 2) >= ϵ * norm(y, 2) * norm(s, 2)
if well_defined(ymBs, s) && scaling_condition(s, y) && sufficient_curvature(s, y)
push!(B, s, y)
cpt += 1
ymBs = y - B*s
norm_ymBs = norm(ymBs, 2)
# @show norm_ymBs
r += norm_ymBs
if isapprox(norm_ymBs, 0., atol=1e-10)
cpt_approx_null += 1
end
end
# println(Matrix(B))
end
r, cpt, cpt_approx_null # (22.107767681026328, 100, 29) Usually, every pair |
I have new examples of failures for lsr1 = LSR1Operator(2)
y = [-5., -5.]
s = [-1., -1.]
push!(lsr1, s ,y)
Matrix(lsr1) # indentity matrix The vectors y = [-5., -4.]
s = [-1.25, -1.]
push!(lsr1, s ,y)
Matrix(lsr1) # still the identity and i get the same result. The test LinearOperators.jl/src/lsr1.jl Line 150 in e663e47
fails, because the scaling condition LinearOperators.jl/src/lsr1.jl Line 146 in e663e47
is false. If we suppose When I saw this, I tried again the loop test that I made previously and I spotted an error in my numerical test scaling_condition(s, y) = norm((y - s) / scaling_factor(s, y), 2) >= ϵ * norm(y, 2) * norm(s, 2) which should be scaling_condition(s, y) = norm(y - s / scaling_factor(s, y), 2) >= ϵ * norm(y, 2) * norm(s, 2) I restarted the same loop with the modified using LinearOperators, LinearAlgebra
n = 1
r = 0.0
cpt = 0
cpt_approx_null = 0
for i = 1:100
B = LSR1Operator(n)
global r
global cpt
global cpt_approx_null
s = rand(n)
y = rand(n)
ϵ = eps(eltype(y))
ymBs = y - B * s
well_defined(ymBs, s) = abs(dot(ymBs, s)) ≥ ϵ + ϵ * norm(ymBs) * norm(s, 2)
sufficient_curvature(s, y) = abs(dot(y, s)) >= ϵ * norm(y, 2) * norm(s, 2)
scaling_factor(s, y) = dot(y, s) / dot(y, y)
scaling_condition(s, y) = norm(y - s / scaling_factor(s, y), 2) >= ϵ * norm(y, 2) * norm(s, 2)
if well_defined(ymBs, s) && scaling_condition(s, y) && sufficient_curvature(s, y)
@show s, y # that way you can try the pairs that you get
push!(B, s, y)
cpt += 1
ymBs = y - B*s
norm_ymBs = norm(ymBs, 2)
r += norm_ymBs
if isapprox(norm_ymBs, 0., atol=1e-10)
cpt_approx_null += 1
end
end
end
r, cpt, cpt_approx_null # (0.0, 25, 25) Out of 100 random pairs of vectors of size 1, only 25 passed the numerical tests (mainly (s, y) = ([0.49377733218773445], [0.11429787904158029]) This pair passes the norm(y - s / scaling_factor(s, y), 2) # 5.551115123125783e-17 a numerical 0 superior to ϵ * norm(y, 2) * norm(s, 2) # 1.2531687196363857e-17 And all the other pairs I don't know if this is an expected behaviour, because the collinear pairs satisfy the LinearOperators.jl/src/lsr1.jl Line 137 in e663e47
I made several tests on my SR1 implementation using collinear pairs I'm not sure how to test the collinear vectors, but here is a try s = [1., 2.]
y = [2., 4.]
myand(a,b) = a && b
s_y = (s ./ y)
collinear = (length(s) == 1) || mapreduce(i-> i == s_y[1], myand, s_y) # true
|
Thank you for this analysis.
How does your implementation differ? |
My SR1 implementation is very simple, it doesn't have as many numerical conditions as LinearOperators.jl/src/lsr1.jl Line 150 in e663e47
It does not implement the LinearOperators.jl/src/lsr1.jl Line 143 in e663e47
LinearOperators.jl/src/lsr1.jl Line 146 in e663e47
The PR #235 sets |
In fact, I don't remember where |
Hello all,
I did test the LSR1 operators for myself, and it seems that there is a problem with the LSR1Operator of dimension 1.
In my work, I generate automatically several LSR1Operators, and some of them are of dimension 1.
Here is an example to replicate the issue:
If you replace
n=1
byn=2
thenr = 1e-14
.The problem does not occur with the LBFGSOperators.
The text was updated successfully, but these errors were encountered: