added metrics

This commit is contained in:
Andrew Clark 2020-08-16 17:38:50 -04:00
parent 2b216a7f81
commit 742c2dcf5c
17 changed files with 37177 additions and 409 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -112,7 +112,7 @@
"So in conviction voting we require that $\\alpha\\in [0,1)$. Technically it is legal to set $\\alpha = 0$ at which point this system simply $y_{t+1} = x_t$ sets the conviction to the amount of tokens staked at the current timestep. Although $x_t$ can still vary overtime, there is no accumulation. The choice of $\\alpha>0$ is made to create a \"leaky integrator\" which takes its name from a leaky bucket analogy.\n",
"![](https://i.imgur.com/JemMMlo.png)\n",
"\n",
"The leaky bucket analogy also helps us understand $\\alpha$ in terms of its relationshio to the \"half-life\" of the fluid in the bucket when we turn off the inflow. In this case there is some previously accumated conviction in our initial condition $y_0 >0$ but $x_t = 0$. In this case the dynamics are simply:\n",
"The leaky bucket analogy also helps us understand $\\alpha$ in terms of its relationship to the \"half-life\" of the fluid in the bucket when we turn off the inflow. In this case there is some previously accumated conviction in our initial condition $y_0 >0$ but $x_t = 0$. In this case the dynamics are simply:\n",
"\n",
"$y_{t+1} = \\alpha y_t$ \n",
"\n",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -15,8 +15,8 @@ from .parts.utils import *
sim_config = config_sim({
'N': 1,
'T': range(100), #day
'N': 1,
'M': params,
})

View File

@ -1,6 +1,7 @@
from .parts.system import *
from .parts.participants import *
from .parts.proposals import *
from .parts.metrics import *
# The Partial State Update Blocks
partial_state_update_blocks = [
@ -53,5 +54,21 @@ partial_state_update_blocks = [
'variables': {
'network': update_tokens
}
},
{
# metrics.py
'policies': {
'calculations': kpi_calculations
},
'variables':{
'fractionOfSupplyForVoting': kpi_fractionOfSupplyForVoting,
'fractionOfSupplyInPool': kpi_fractionOfSupplyInPool,
'fractionOfProposalStages':kpi_proposal_stages,
'fractionOfFundStages': kpi_fractionOfFundStages
}
}
]
]

View File

@ -0,0 +1,98 @@
import numpy as np
import pandas as pd
import networkx as nx
from .utils import *
# Behaviors
def kpi_calculations(params, step, sL, s):
'''
Behavior for assessing the health of the system
'''
# read in state variables
network = s['network']
effective_supply = s['effective_supply']
total_supply = s['total_supply']
funds = s['funds']
# calculate percentages
fractionOfSupplyForVoting = effective_supply/total_supply
fractionOfSupplyInPool = total_supply/funds
proposals = get_nodes_by_type(network, 'proposal')
# fraction of proposals in different stages
total_proposals = len(proposals)
active_proposals = len([j for j in proposals if network.nodes[j]['status']=='active'])
completed_proposals = len([j for j in proposals if network.nodes[j]['status']=='completed'])
killed_proposals = len([j for j in proposals if network.nodes[j]['status']=='killed'])
proposal_stages = {'percentageOfActive': active_proposals/total_proposals,
'percentageOfCompleted':completed_proposals/total_proposals,
'percentageOfKilled':killed_proposals/total_proposals}
#fraction of money in the different states
total_funds_requested = []
active_funds_requested = []
completed_funds_requested = []
killed_funds_requested = []
for i in proposals:
total_funds_requested.append(network.nodes[i]['funds_requested'])
if network.nodes[i]['status'] == 'active':
active_funds_requested.append(network.nodes[i]['funds_requested'])
if network.nodes[i]['status'] == 'completed':
completed_funds_requested.append(network.nodes[i]['funds_requested'])
if network.nodes[i]['status'] == 'killed':
killed_funds_requested.append(network.nodes[i]['funds_requested'])
money_stages = {'percentageOfActiveFundsRequested': sum(active_funds_requested)/sum(total_funds_requested),
'percentageOfCompletedFundsRequested':sum(completed_funds_requested)/sum(total_funds_requested),
'percentageOfKilledFundsRequested':sum(killed_funds_requested)/sum(total_funds_requested)}
return({'fractionOfSupplyForVoting':fractionOfSupplyForVoting,
'fractionOfSupplyInPool':fractionOfSupplyInPool,
'fractionOfProposalStages':proposal_stages,
'fractionOfFundStages':money_stages
})
# Mechanisms
def kpi_fractionOfSupplyForVoting(params, step, sL, s, _input):
'''
'''
key = 'fractionOfSupplyForVoting'
value = _input['fractionOfSupplyForVoting']
return (key, value)
def kpi_fractionOfSupplyInPool(params, step, sL, s, _input):
'''
'''
key = 'fractionOfSupplyInPool'
value = _input['fractionOfSupplyInPool']
return (key, value)
def kpi_proposal_stages(params, step, sL, s, _input):
'''
'''
key = 'fractionOfProposalStages'
value = _input['fractionOfProposalStages']
return (key, value)
def kpi_fractionOfFundStages(params, step, sL, s, _input):
'''
'''
key = 'fractionOfFundStages'
value = _input['fractionOfFundStages']
return (key, value)

View File

@ -67,6 +67,30 @@ def postprocessing(df, sim_ind=-1):
df['triggers_all'] = df.network.apply(lambda g: np.array([g.nodes[j]['trigger'] for j in get_nodes_by_type(g, 'proposal') ]))
df['conviction_share_of_trigger_all'] = df.conviction_all/df.triggers_all
# extract metrics
percentageOfActive = []
percentageOfCompleted = []
percentageOfKilled = []
for i in range(0,len(df.timestep)):
percentageOfActive.append(df.fractionOfProposalStages.values[i]['percentageOfActive'])
percentageOfCompleted.append(df.fractionOfProposalStages.values[i]['percentageOfCompleted'])
percentageOfKilled.append(df.fractionOfProposalStages.values[i]['percentageOfKilled'])
df['percentageOfActiveProposals'] = percentageOfActive
df['percentageOfCompletedProposals'] = percentageOfCompleted
df['percentageOfKilledProposals'] = percentageOfKilled
percentageOfActiveFundsRequested = []
percentageOfCompletedFundsRequested = []
percentageOfKilledFundsRequested = []
for i in range(0,len(df.timestep)):
percentageOfActiveFundsRequested.append(df.fractionOfFundStages.values[i]['percentageOfActiveFundsRequested'])
percentageOfCompletedFundsRequested.append(df.fractionOfFundStages.values[i]['percentageOfCompletedFundsRequested'])
percentageOfKilledFundsRequested.append(df.fractionOfFundStages.values[i]['percentageOfKilledFundsRequested'])
df['percentageOfActiveFundsRequested'] = percentageOfActiveFundsRequested
df['percentageOfCompletedFundsRequested'] = percentageOfCompletedFundsRequested
df['percentageOfKilledFundsRequested'] = percentageOfKilledFundsRequested
return df

View File

@ -5,7 +5,12 @@ state_variables = {
'network': 0, # will initialize during config.py
'funds':initial_values['initial_funds'],
'sentiment': initial_values['initial_sentiment'],
'effective_supply': (initial_values['supply']-initial_values['initial_funds'])*.8, #force some slack into the inequality
'total_supply': initial_values['supply']
'effective_supply': (initial_values['supply']-initial_values['initial_funds'])*.8,
'total_supply': initial_values['supply'],
# metrics variables
'fractionOfSupplyForVoting': 0,
'fractionOfSupplyInPool': 0,
'fractionOfProposalStages': 0,
'fractionOfFundStages': 0
}