Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including jvp for radius update schemes #172

Merged
merged 12 commits into from
Apr 3, 2023
11 changes: 11 additions & 0 deletions src/jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,14 @@ function jacobian_autodiff(f, x::AbstractArray, nonlinfun, alg)
jac_prototype = jac_prototype, chunksize = chunk_size),
num_of_chunks)
end

function jvp(cache::TrustRegionCache{false})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a ! on there because it's mutating.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are actually not modifying the cache, we are just returning the jvp. Should that still be done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are modifying the cache in one of them

@unpack f, u, fu = cache
auto_jacvec(f, u, fu)
end

function jvp(cache::TrustRegionCache{true})
@unpack g, f, u, fu = cache
auto_jacvec!(g, f, u, fu)
g
end
9 changes: 5 additions & 4 deletions src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,18 @@ function trust_region_step!(cache::TrustRegionCache)
elseif r >= cache.expand_threshold && cache.internalnorm(step_size) > cache.trust_r / 2
cache.p1 = cache.p3 * cache.p1
end
@unpack p1, fu, f, J = cache
#cache.trust_r = p1 * cache.internalnorm(jacobian!(J, cache) * fu) # we need the gradient at the new (k+1)th point WILL THIS BECOME ALLOCATING?


if r > cache.step_threshold
take_step!(cache)
cache.loss = cache.loss_new
cache.make_new_J = true
else
cache.make_new_J = false
end


@unpack p1= cache
cache.trust_r = p1 * cache.internalnorm(jvp(cache)) # we need the gradient at the new (k+1)th point WILL THIS BECOME ALLOCATING?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment can be removed.


if iszero(cache.fu) || cache.internalnorm(cache.fu) < cache.abstol || cache.internalnorm(g) < cache.ϵ # parameters to be defined
cache.force_stop = true
end
Expand Down