Skip to content

Commit

Permalink
fix: Minimisation needs to use negative profit
Browse files Browse the repository at this point in the history
This seems to have been the cause of a bug in which PGO performed worse
than PGD

Signed-off-by: Anirudh <anirudh@semiotic.ai>
  • Loading branch information
anirudh2 committed Apr 17, 2023
1 parent 0ced47f commit 470a72e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function optimize(::Val{:optimal}, Ω, ψ, σ, K, Φ, Ψ, g)
@warn "This uses the pairwise greedy algorithm, which is currently experimental."

# Helper function to compute profit
obj = x -> profit.(indexingreward.(x, Ω, ψ, Φ, Ψ), g) |> sum
obj = x -> -profit.(indexingreward.(x, Ω, ψ, Φ, Ψ), g) |> sum

# Preallocate solution vectors for in-place operations
_x = zeros(length(ψ), 1)
Expand All @@ -280,7 +280,7 @@ function optimize(::Val{:optimal}, Ω, ψ, σ, K, Φ, Ψ, g)
# Set up optimizer
function makeanalytic(x)
return AllocationOpt.AnalyticOpt(;
x=x, Ω=Ω, ψ=ψ, σ=σ, hooks=[StopWhen((a; kws...) -> kws[:i] > 1)]
x=x, Ω=Ω, ψ=ψ, σ=σ, hooks=[StopWhen((a; kws...) -> kws[:i] > 0)]
)
end
alg = PairwiseGreedyOpt(;
Expand All @@ -290,10 +290,10 @@ function optimize(::Val{:optimal}, Ω, ψ, σ, K, Φ, Ψ, g)
f=f,
a=makeanalytic,
hooks=[
StopWhen((a; kws...) -> kws[:f](kws[:z]) kws[:f](SemioticOpt.x(a)))
StopWhen((a; kws...) -> kws[:f](kws[:z]) kws[:f](SemioticOpt.x(a))),
StopWhen(
(a; kws...) -> length(kws[:z]) == length(SemioticOpt.nonzeroixs(kws[:z]))
)
),
],
)
sol = minimize!(obj, alg)
Expand Down

0 comments on commit 470a72e

Please sign in to comment.