Skip to content

Commit f321c92

Browse files
committed
retrospective step func
1 parent ada7d8d commit f321c92

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/trustRegion.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,30 @@ function perform_step!(cache::TrustRegionCache{false})
401401
return nothing
402402
end
403403

404+
function retrospective_step!(cache::TrustRegionCache{true})
405+
@unpack J, fu_prev, fu, u_prev, u = cache
406+
jacobian!(J, cache)
407+
mul!(cache.H, J, J)
408+
mul!(cache.g, J, fu)
409+
cache.stats.njacs += 1
410+
@unpack H, g, step_size = cache
411+
412+
return -(get_loss(fu_prev) - get_loss(fu)) /
413+
(step_size' * g + step_size' * H * step_size / 2)
414+
end
415+
416+
function retrospective_step!(cache::TrustRegionCache{false})
417+
@unpack J, fu_prev, fu, u_prev, u, f = cache
418+
J = jacobian(cache, f)
419+
cache.H = J * J
420+
cache.g = J * fu
421+
cache.stats.njacs += 1
422+
@unpack H, g, step_size = cache
423+
424+
return -(get_loss(fu_prev) - get_loss(fu)) /
425+
(step_size' * g + step_size' * H * step_size / 2)
426+
end
427+
404428
function trust_region_step!(cache::TrustRegionCache)
405429
@unpack fu_new, step_size, g, H, loss, max_trust_r, radius_update_scheme = cache
406430
cache.loss_new = get_loss(fu_new)

0 commit comments

Comments
 (0)