From 1ac9da26d31c55f126a59438891a0b5d966db3b2 Mon Sep 17 00:00:00 2001 From: Anirudh Date: Tue, 14 Mar 2023 12:53:28 -0700 Subject: [PATCH] feat: Indexing reward Signed-off-by: Anirudh --- src/domain.jl | 20 ++++++++++++++++++++ test/domain.jl | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/domain.jl b/src/domain.jl index bda22d3..dc9dd60 100644 --- a/src/domain.jl +++ b/src/domain.jl @@ -375,3 +375,23 @@ function newtokenissuance(n::FlexTable, config::Dict) newtokens = p*(r^t - 1.0) return newtokens end + +""" + indexingreward(x, Ω, ψ, Φ, Ψ) + +The indexing rewards for the allocation vector `x` given signals `ψ`, the existing +allocations on subgraphs `Ω`, token issuance `Φ`, and total signal `Ψ`. + +```julia +julia> ψ = [0.0, 1.0] +julia> Ω = [0.0, 0.0] +julia> Φ = 1.0 +julia> Ψ = 2.0 +julia> x = [0.0, 1.0] +julia> AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) +``` +""" +function indexingreward(x, Ω, ψ, Φ, Ψ) + sr = Φ * ψ / Ψ + return sum(sr .* x ./ (x .+ Ω)) +end diff --git a/test/domain.jl b/test/domain.jl index c075d7a..2f350cb 100644 --- a/test/domain.jl +++ b/test/domain.jl @@ -154,4 +154,27 @@ @test AllocationOpt.newtokenissuance(n, config) == 1 end + @testset "indexingreward" begin + ψ = [0.0, 1.0] + Ω = [1.0, 1.0] + Φ = 1.0 + Ψ = 2.0 + x = [1.0, 0.0] + @test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.0 + + ψ = [0.0, 1.0] + Ω = [1.0, 1.0] + Φ = 1.0 + Ψ = 2.0 + x = [0.0, 1.0] + @test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.25 + + ψ = [1.0, 1.0] + Ω = [1.0, 1.0] + Φ = 1.0 + Ψ = 2.0 + x = [1.0, 1.0] + @test AllocationOpt.indexingreward(x, Ω, ψ, Φ, Ψ) == 0.5 + end + end