Skip to content

Commit

Permalink
feat: Indexing reward computed for ixs
Browse files Browse the repository at this point in the history
An alternative formulation of the indexing reward for use with Pairwise
Greedy Optimisation.
  • Loading branch information
anirudh2 committed Apr 17, 2023
1 parent 3a1b116 commit 7e651f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
42 changes: 41 additions & 1 deletion src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,47 @@ function newtokenissuance(n::FlexTable, config::Dict)
end

"""
function indexingreward(
indexingreward(
ixs::AbstractVector{Integer},
x::AbstractVector{Real},
Ω::AbstractVector{Real},
ψ::AbstractVector{Real},
Φ::Real,
Ψ::Real
)
The indexing rewards for the allocation vector `x` given signals `ψ`, the existing
allocations on subgraphs `Ω`, token issuance `Φ`, and total signal `Ψ`. Here `ixs`
is a vector of indices `Ω`, and `ψ`. `x` will be filtered by `SemioticOpt`, so we
don't do this here.
```julia
julia> using AllocationOpt
julia> using AllocationOpt
julia> ixs = Int32[2]
julia> ψ = [0.0, 1.0]
julia> Ω = [1.0, 1.0]
julia> Φ = 1.0
julia> Ψ = 2.0
julia> x = [0.0, 1.0]
julia> AllocationOpt.indexingreward(ixs, x, Ω, ψ, Φ, Ψ)
0.25
````
"""
function indexingreward(
ixs::AbstractVector{I},
x::AbstractVector{T},
Ω::AbstractVector{T},
ψ::AbstractVector{T},
Φ::Real,
Ψ::Real,
) where {T<:Real,I<:Integer}
return indexingreward(x, Ω[ixs], ψ[ixs], Φ, Ψ)
end

"""
indexingreward(
x::AbstractVector{Real},
Ω::AbstractVector{Real},
ψ::AbstractVector{Real},
Expand Down
24 changes: 19 additions & 5 deletions test/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@

@testset "availablestake" begin
x = flextable([
Dict(
"stakedTokens" => 10,
"delegatedTokens" => 20,
"lockedTokens" => 5,
),
Dict("stakedTokens" => 10, "delegatedTokens" => 20, "lockedTokens" => 5)
])
@test AllocationOpt.availablestake(Val(:indexer), x) == 25
end
Expand Down Expand Up @@ -258,6 +254,24 @@
x = [1.0, 1.0]
@test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.5
end

@testset "specifying ixs" begin
ixs = Int32[2]
ψ = [0.0, 1.0]
Ω = [1.0, 1.0]
Φ = 1.0
Ψ = 2.0
x = [0.0, 1.0]
@test AllocationOpt.indexingreward(ixs, x, Ω, ψ, Φ, Ψ) == 0.25

ixs = Int32[1]
ψ = [0.0, 1.0]
Ω = [1.0, 1.0]
Φ = 1.0
Ψ = 2.0
x = [0.0, 1.0]
@test AllocationOpt.indexingreward(ixs, x, Ω, ψ, Φ, Ψ) == 0.0
end
end

@testset "profit" begin
Expand Down

0 comments on commit 7e651f2

Please sign in to comment.