From 7e651f24b4f611a38823ba86d948204828f5621b Mon Sep 17 00:00:00 2001 From: Anirudh Date: Sat, 15 Apr 2023 14:38:54 -0700 Subject: [PATCH] feat: Indexing reward computed for ixs An alternative formulation of the indexing reward for use with Pairwise Greedy Optimisation. --- src/domain.jl | 42 +++++++++++++++++++++++++++++++++++++++++- test/domain.jl | 24 +++++++++++++++++++----- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/domain.jl b/src/domain.jl index 7b8739d..2cea802 100644 --- a/src/domain.jl +++ b/src/domain.jl @@ -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}, diff --git a/test/domain.jl b/test/domain.jl index 332791f..fe58fbe 100644 --- a/test/domain.jl +++ b/test/domain.jl @@ -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 @@ -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