Skip to content

Commit

Permalink
Fix optim maxsense
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhavdixit02 committed Nov 2, 2023
1 parent 29d5407 commit 3db7393
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/OptimizationOptimJL/src/OptimizationOptimJL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
if G !== nothing
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 163 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L163

Added line #L163 was not covered by tests
end
end
return _loss(θ)
Expand All @@ -170,22 +170,22 @@ function SciMLBase.__solve(cache::OptimizationCache{
hv = function (H, θ, v)
cache.f.hv(H, θ, v, cur...)
if cache.sense === Optimization.MaxSense
H .*= false
H .*= -one(eltype(H))
end
end
optim_f = Optim.TwiceDifferentiableHV(_loss, fg!, hv, cache.u0)
else
gg = function (G, θ)
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 181 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L181

Added line #L181 was not covered by tests
end
end

hh = function (H, θ)
cache.f.hess(H, θ, cur...)
if cache.sense === Optimization.MaxSense
H .*= false
H .*= -one(eltype(H))
end
end
u0_type = eltype(cache.u0)
Expand Down Expand Up @@ -273,7 +273,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
if G !== nothing
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 276 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L276

Added line #L276 was not covered by tests
end
end
return _loss(θ)
Expand All @@ -282,7 +282,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
gg = function (G, θ)
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 285 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L285

Added line #L285 was not covered by tests
end
end
optim_f = Optim.OnceDifferentiable(_loss, gg, fg!, cache.u0)
Expand Down Expand Up @@ -356,22 +356,22 @@ function SciMLBase.__solve(cache::OptimizationCache{
if G !== nothing
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 359 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L359

Added line #L359 was not covered by tests
end
end
return _loss(θ)
end
gg = function (G, θ)
cache.f.grad(G, θ, cur...)
if cache.sense === Optimization.MaxSense
G .*= false
G .*= -one(eltype(G))

Check warning on line 367 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L367

Added line #L367 was not covered by tests
end
end

hh = function (H, θ)
cache.f.hess(H, θ, cur...)
if cache.sense === Optimization.MaxSense
H .*= false
H .*= -one(eltype(H))
end
end
u0_type = eltype(cache.u0)
Expand Down

0 comments on commit 3db7393

Please sign in to comment.