diff --git a/src/dfsane.jl b/src/dfsane.jl index e84169eec..b76e36af7 100644 --- a/src/dfsane.jl +++ b/src/dfsane.jl @@ -144,7 +144,7 @@ function perform_step!(cache::DFSaneCache{true}) # Line search direction @. cache.๐’น = -ฯƒโ‚™ * cache.fuโ‚™โ‚‹โ‚ - ฮท = alg.ฮทโ‚›(fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚€, n, cache.uโ‚™โ‚‹โ‚, cache.fuโ‚™โ‚‹โ‚) + ฮท = alg.ฮทโ‚›(fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚€, n, cache.uโ‚™โ‚‹โ‚, cache.fuโ‚™โ‚‹โ‚) fฬ„ = maximum(cache.โ„‹) ฮฑโ‚Š = ฮฑโ‚ @@ -154,7 +154,6 @@ function perform_step!(cache::DFSaneCache{true}) f(cache.fuโ‚™, cache.uโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ = sum(abs2, cache.fuโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ ^= (nโ‚‘โ‚“โ‚š / 2) - for _ in 1:(cache.alg.max_inner_iterations) ๐’ธ = fฬ„ + ฮท - ฮณ * ฮฑโ‚Š^2 * fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™โ‚‹โ‚ @@ -164,19 +163,19 @@ function perform_step!(cache::DFSaneCache{true}) (fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ + (T(2) * ฮฑโ‚Š - T(1)) * fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™โ‚‹โ‚), ฯ„โ‚˜แตขโ‚™ * ฮฑโ‚Š, ฯ„โ‚˜โ‚โ‚“ * ฮฑโ‚Š) - @. cache.uโ‚™ = cache.uโ‚™โ‚‹โ‚ - ฮฑโ‚‹ * cache.๐’น # correct order? + @. cache.uโ‚™ = cache.uโ‚™โ‚‹โ‚ - ฮฑโ‚‹ * cache.๐’น f(cache.fuโ‚™, cache.uโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ = sum(abs2, cache.fuโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ ^= (nโ‚‘โ‚“โ‚š / 2) - (fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ .โ‰ค ๐’ธ) && break + fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ .โ‰ค ๐’ธ && break ฮฑโ‚‹ = clamp(ฮฑโ‚‹^2 * fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™โ‚‹โ‚ / (fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ + (T(2) * ฮฑโ‚‹ - T(1)) * fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™โ‚‹โ‚), ฯ„โ‚˜แตขโ‚™ * ฮฑโ‚‹, ฯ„โ‚˜โ‚โ‚“ * ฮฑโ‚‹) - @. cache.uโ‚™ = cache.uโ‚™โ‚‹โ‚ + ฮฑโ‚Š * cache.๐’น # correct order? + @. cache.uโ‚™ = cache.uโ‚™โ‚‹โ‚ + ฮฑโ‚Š * cache.๐’น f(cache.fuโ‚™, cache.uโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ = sum(abs2, cache.fuโ‚™) fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚™ ^= (nโ‚‘โ‚“โ‚š / 2) @@ -193,7 +192,19 @@ function perform_step!(cache::DFSaneCache{true}) ฮฑโ‚Š = sum(abs2, cache.uโ‚™โ‚‹โ‚) @. cache.uโ‚™โ‚‹โ‚ = cache.uโ‚™โ‚‹โ‚ * cache.fuโ‚™โ‚‹โ‚ ฮฑโ‚‹ = sum(cache.uโ‚™โ‚‹โ‚) - cache.ฯƒโ‚™ = ฮฑโ‚Š / (ฮฑโ‚‹ + T(1e-5)) + cache.ฯƒโ‚™ = ฮฑโ‚Š / ฮฑโ‚‹ + + # Spectral parameter bounds check + if abs(cache.ฯƒโ‚™) > ฯƒโ‚˜โ‚โ‚“ || abs(cache.ฯƒโ‚™) < ฯƒโ‚˜แตขโ‚™ + test_norm = sqrt(sum(abs2, cache.fuโ‚™โ‚‹โ‚)) + if test_norm > 1 + cache.ฯƒโ‚™ = 1.0 + elseif testnorm < 1e-5 + cache.ฯƒโ‚™ = 1e5 + else + cache.ฯƒโ‚™ = 1.0 / test_norm + end + end # Take step @. cache.uโ‚™โ‚‹โ‚ = cache.uโ‚™ @@ -219,7 +230,7 @@ function perform_step!(cache::DFSaneCache{false}) # Line search direction @. cache.๐’น = -ฯƒโ‚™ * cache.fuโ‚™โ‚‹โ‚ - ฮท = alg.ฮทโ‚›(fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚€, n, cache.uโ‚™โ‚‹โ‚, cache.fuโ‚™โ‚‹โ‚) + ฮท = alg.ฮทโ‚›(fโ‚โ‚™โ‚’แตฃโ‚˜โ‚Žโ‚€, n, cache.uโ‚™โ‚‹โ‚, cache.fuโ‚™โ‚‹โ‚) fฬ„ = maximum(cache.โ„‹) ฮฑโ‚Š = ฮฑโ‚ @@ -268,7 +279,19 @@ function perform_step!(cache::DFSaneCache{false}) ฮฑโ‚Š = sum(abs2, cache.uโ‚™โ‚‹โ‚) @. cache.uโ‚™โ‚‹โ‚ = cache.uโ‚™โ‚‹โ‚ * cache.fuโ‚™โ‚‹โ‚ ฮฑโ‚‹ = sum(cache.uโ‚™โ‚‹โ‚) - cache.ฯƒโ‚™ = ฮฑโ‚Š / (ฮฑโ‚‹ + T(1e-5)) + cache.ฯƒโ‚™ = ฮฑโ‚Š / ฮฑโ‚‹ + + # Spectral parameter bounds check + if abs(cache.ฯƒโ‚™) > ฯƒโ‚˜โ‚โ‚“ || abs(cache.ฯƒโ‚™) < ฯƒโ‚˜แตขโ‚™ + test_norm = sqrt(sum(abs2, cache.fuโ‚™โ‚‹โ‚)) + if test_norm > 1 + cache.ฯƒโ‚™ = 1.0 + elseif testnorm < 1e-5 + cache.ฯƒโ‚™ = 1e5 + else + cache.ฯƒโ‚™ = 1.0 / test_norm + end + end # Take step @. cache.uโ‚™โ‚‹โ‚ = cache.uโ‚™