1
1
# Points
2
2
x0 = [- 1.0 , 1.0 , - 1.0 ]
3
- x1 = x0 + [1.0 , 1 .0 , 1.0 ]
3
+ x1 = x0 + [1.0 , 0 .0 , 1.0 ]
4
4
5
5
# Test functions
6
6
# f(x) = x[1]^2 + x[2]^2 + x[3]^2
@@ -12,7 +12,7 @@ x1 = x0 + [1.0, 1.0, 1.0]
12
12
# h(x) = x[1]^2 * x[2] * x[3]^3
13
13
∇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 ]
14
14
15
- @testset " Weak secant equation" begin
15
+ @testset " Weak secant equation for Andrei update " begin
16
16
for grad_fun in (:∇f , :∇g , ∇h)
17
17
grad = eval (grad_fun)
18
18
s = x1 - x0
@@ -23,30 +23,44 @@ x1 = x0 + [1.0, 1.0, 1.0]
23
23
end
24
24
end
25
25
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
+
26
37
@testset " Hard coded test" begin
27
38
for grad_fun in (:∇f , :∇g , :∇h )
28
39
grad = eval (grad_fun)
29
40
s = x1 - x0
30
41
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
39
55
end
40
- push! (B, s, y)
41
- @test norm (B. d - Bref) <= 1e-10
42
56
43
57
B = SpectralGradient (1.0 , 3 )
44
58
if grad_fun == :∇f
45
59
Bref = 2
46
60
elseif grad_fun == :∇g
47
- Bref = 1 / 3 * (1 - exp (- 1 ) + sin (- 1 ))
61
+ Bref = (1 - exp (- 1 ) + sin (- 1 )) / 2
48
62
else
49
- Bref = - 4 / 3
63
+ Bref = - 5 / 2
50
64
end
51
65
push! (B, s, y)
52
66
@test abs (B. d - Bref) <= 1e-10
60
74
u = similar (v)
61
75
mul! (u, A, v)
62
76
@test (@allocated mul! (u, A, v)) == 0
63
- B = SpectralGradient ( rand (), 5 )
77
+ B = DiagonalQN (d, true )
64
78
mul! (u, B, v)
65
79
@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
66
83
end
0 commit comments