|
515 | 515 | α = hzls_u3(dmp, gs, 1, η) |
516 | 516 | @test α > 0 |
517 | 517 | end |
| 518 | + @testset "U3 (b) trigger test" begin |
| 519 | + M = Euclidean(1) |
| 520 | + # Force U3 (b) in _hz_u3: |
| 521 | + # 1) At d=0.5 we need df < 0 and f(d) <= f(0) + ϵₖ with no termination, |
| 522 | + # so i_a_bar gets updated to i_d. |
| 523 | + # 2) On the next U3 iteration we return from the loop. |
| 524 | + function f_u3b(M, q) |
| 525 | + return 0.0 |
| 526 | + end |
| 527 | + |
| 528 | + function grad_f_u3b(M, q) |
| 529 | + v = q[1] |
| 530 | + if isapprox(v, 0.0; atol = 1.0e-12) |
| 531 | + return [-1.0] |
| 532 | + elseif isapprox(v, 1.0; atol = 1.0e-12) |
| 533 | + return [1.0] |
| 534 | + elseif isapprox(v, 0.5; atol = 1.0e-12) |
| 535 | + return [-1.0] |
| 536 | + elseif isapprox(v, 0.75; atol = 1.0e-12) |
| 537 | + return [1.0] |
| 538 | + end |
| 539 | + return [0.0] |
| 540 | + end |
| 541 | + |
| 542 | + dmp = DefaultManoptProblem(M, ManifoldGradientObjective(f_u3b, grad_f_u3b)) |
| 543 | + p = [0.0] |
| 544 | + η = [1.0] |
| 545 | + hzls_u3b = Manopt.HagerZhangLinesearchStepsize(M; max_function_evaluations = 4) |
| 546 | + Manopt.initialize_stepsize!(hzls_u3b) |
| 547 | + Manopt._hz_evaluate_next_step(hzls_u3b, M, dmp, p, η, 0.0) |
| 548 | + Manopt._hz_evaluate_next_step(hzls_u3b, M, dmp, p, η, 1.0) |
| 549 | + |
| 550 | + (i_a, i_b, f_eval, f_wolfe) = Manopt._hz_u3(hzls_u3b, M, dmp, p, η, 1, 2) |
| 551 | + @test (i_a, i_b) == (3, 4) |
| 552 | + @test f_eval |
| 553 | + @test !f_wolfe |
| 554 | + end |
518 | 555 | @testset "U3 (c) info trigger test" begin |
519 | 556 | M = Euclidean(1) |
520 | 557 | # Force U3 (c) inside _hz_u3 by making the mid-point have |
|
575 | 612 | @test !f_eval |
576 | 613 | @test !f_wolfe |
577 | 614 | end |
| 615 | + @testset "U0 out-of-bracket early return" begin |
| 616 | + M = Euclidean(1) |
| 617 | + f(M, p) = sum(p .^ 2) |
| 618 | + grad_f(M, p) = 2 .* p |
| 619 | + dmp = DefaultManoptProblem(M, ManifoldGradientObjective(f, grad_f)) |
| 620 | + p = [0.0] |
| 621 | + η = [1.0] |
| 622 | + |
| 623 | + hzls_u0 = Manopt.HagerZhangLinesearchStepsize(M; max_function_evaluations = 5) |
| 624 | + Manopt.initialize_stepsize!(hzls_u0) |
| 625 | + Manopt._hz_evaluate_next_step(hzls_u0, M, dmp, p, η, 0.0) |
| 626 | + Manopt._hz_evaluate_next_step(hzls_u0, M, dmp, p, η, 1.0) |
| 627 | + |
| 628 | + last_eval_before = hzls_u0.last_evaluation_index |
| 629 | + |
| 630 | + # c is left of bracket [0, 1] -> U0 early return |
| 631 | + @test (1, 2, -1, false, false) == Manopt._hz_update(hzls_u0, M, dmp, p, η, 1, 2, -0.1) |
| 632 | + @test hzls_u0.last_evaluation_index == last_eval_before |
| 633 | + |
| 634 | + # c is right of bracket [0, 1] -> U0 early return |
| 635 | + @test (1, 2, -1, false, false) == Manopt._hz_update(hzls_u0, M, dmp, p, η, 1, 2, 1.1) |
| 636 | + @test hzls_u0.last_evaluation_index == last_eval_before |
| 637 | + end |
578 | 638 |
|
579 | 639 | @testset "S2 trigger test" begin |
580 | 640 | M = Euclidean(1) |
|
633 | 693 | # 3. Secant gives c=0.2. At c, df=-0.1 and f=0 -> U2. |
634 | 694 |
|
635 | 695 | function f_s3(M, q) |
636 | | - v = q[1] |
637 | | - if isapprox(v, 0.0; atol = 1.0e-12) |
638 | | - return 0.0 |
639 | | - elseif isapprox(v, 1.0; atol = 1.0e-12) |
640 | | - return 0.0 |
641 | | - elseif isapprox(v, 0.2; atol = 1.0e-12) |
642 | | - return 0.0 |
643 | | - end |
644 | 696 | return 0.0 |
645 | 697 | end |
646 | 698 |
|
|
0 commit comments