11# Points
22x0 = [- 1.0 , 1.0 , - 1.0 ]
3- x1 = x0 + [1.0 , 1 .0 , 1.0 ]
3+ x1 = x0 + [1.0 , 0 .0 , 1.0 ]
44
55# Test functions
66# f(x) = x[1]^2 + x[2]^2 + x[3]^2
@@ -12,7 +12,7 @@ x1 = x0 + [1.0, 1.0, 1.0]
1212# h(x) = x[1]^2 * x[2] * x[3]^3
1313∇h (x) = [2 * x[1 ] * x[2 ] * x[3 ]^ 3 , x[1 ]^ 2 * x[3 ]^ 3 , 3 * x[1 ]^ 2 * x[2 ] * x[3 ]^ 2 ]
1414
15- @testset " Weak secant equation" begin
15+ @testset " Weak secant equation for Andrei update " begin
1616 for grad_fun in (:∇f , :∇g , ∇h)
1717 grad = eval (grad_fun)
1818 s = x1 - x0
@@ -23,30 +23,44 @@ x1 = x0 + [1.0, 1.0, 1.0]
2323 end
2424end
2525
26+ @testset " Weak secant equation for PSB update" begin
27+ for grad_fun in (:∇f , :∇g , ∇h)
28+ grad = eval (grad_fun)
29+ s = x1 - x0
30+ y = grad (x1) - grad (x0)
31+ B = DiagonalQN ([1.0 , - 1.0 , 1.0 ], true )
32+ push! (B, s, y)
33+ @test abs (dot (s, B * s) - dot (s, y)) <= 1e-10
34+ end
35+ end
36+
2637@testset " Hard coded test" begin
2738 for grad_fun in (:∇f , :∇g , :∇h )
2839 grad = eval (grad_fun)
2940 s = x1 - x0
3041 y = grad (x1) - grad (x0)
31- B = DiagonalQN ([1.0 , - 1.0 , 1.0 ])
32- if grad_fun == :∇f
33- Bref = [8 / 3 , 8 / 3 - 2 , 8 / 3 ]
34- elseif grad_fun == :∇g
35- Bref =
36- [1 + (sin (- 1 ) - exp (- 1 )) / 3 , - 1 + (sin (- 1 ) - exp (- 1 )) / 3 , 1 + (sin (- 1 ) - exp (- 1 )) / 3 ]
37- else
38- Bref = [- 2 / 3 , - 2 / 3 - 2 , - 2 / 3 ]
42+ for psb ∈ (false , true )
43+ B = DiagonalQN ([1.0 , - 1.0 , 1.0 ], psb)
44+ if grad_fun == :∇f
45+ Bref = psb ? [2 , - 1 , 2 ] : [2 , - 2 , 2 ]
46+ elseif grad_fun == :∇g
47+ Bref =
48+ psb ? [1 + (sin (- 1 ) - exp (- 1 ) - 1 ) / 2 , - 1 , 1 + (sin (- 1 ) - exp (- 1 ) - 1 ) / 2 ] :
49+ [(1 + sin (- 1 ) - exp (- 1 )) / 2 , - 2 , (1 + sin (- 1 ) - exp (- 1 )) / 2 ]
50+ else
51+ Bref = psb ? [- 5 / 2 , - 1 , - 5 / 2 ] : [- 5 / 2 , - 2 , - 5 / 2 ]
52+ end
53+ push! (B, s, y)
54+ @test norm (B. d - Bref) <= 1e-10
3955 end
40- push! (B, s, y)
41- @test norm (B. d - Bref) <= 1e-10
4256
4357 B = SpectralGradient (1.0 , 3 )
4458 if grad_fun == :∇f
4559 Bref = 2
4660 elseif grad_fun == :∇g
47- Bref = 1 / 3 * (1 - exp (- 1 ) + sin (- 1 ))
61+ Bref = (1 - exp (- 1 ) + sin (- 1 )) / 2
4862 else
49- Bref = - 4 / 3
63+ Bref = - 5 / 2
5064 end
5165 push! (B, s, y)
5266 @test abs (B. d - Bref) <= 1e-10
6074 u = similar (v)
6175 mul! (u, A, v)
6276 @test (@allocated mul! (u, A, v)) == 0
63- B = SpectralGradient ( rand (), 5 )
77+ B = DiagonalQN (d, true )
6478 mul! (u, B, v)
6579 @test (@allocated mul! (u, B, v)) == 0
80+ C = SpectralGradient (rand (), 5 )
81+ mul! (u, C, v)
82+ @test (@allocated mul! (u, C, v)) == 0
6683end
0 commit comments