second policy "check_progress"implemented; moved and renamed most policy/state variable functions over to network_helpers
This commit is contained in:
parent
8f214ed043
commit
71c242104d
|
|
@ -65,6 +65,21 @@ def add_proposals_and_relationships_to_network(n: nx.DiGraph, proposals: int, fu
|
|||
n = initial_conflict_network(n, rate = .25)
|
||||
n = initial_social_network(n, scale = 1)
|
||||
return n
|
||||
|
||||
def update_collateral_pool(params, step, sL, s, _input):
|
||||
commons = s["commons"]
|
||||
s["collateral_pool"] = commons._collateral_pool
|
||||
return "collateral_pool", commons._collateral_pool
|
||||
|
||||
def update_token_supply(params, step, sL, s, _input):
|
||||
commons = s["commons"]
|
||||
s["token_supply"] = commons._token_supply
|
||||
return "token_supply", commons._token_supply
|
||||
|
||||
def update_funding_pool(params, step, sL, s, _input):
|
||||
commons = s["commons"]
|
||||
s["funding_pool"] = commons._funding_pool
|
||||
return "funding_pool", commons._funding_pool
|
||||
# =========================================================================================================
|
||||
def gen_new_participant(network, new_participant_tokens):
|
||||
i = len([node for node in network.nodes])
|
||||
|
|
@ -135,7 +150,7 @@ def calc_median_affinity(network):
|
|||
median_affinity = np.median(affinities)
|
||||
return median_affinity
|
||||
|
||||
def driving_process(params, step, sL, s):
|
||||
def gen_new_participants_proposals_funding_random(params, step, sL, s):
|
||||
network = s['network']
|
||||
commons = s['commons']
|
||||
funds = s['funding_pool']
|
||||
|
|
@ -223,3 +238,99 @@ def add_participants_proposals_to_network(params, step, sL, s, _input):
|
|||
value = network
|
||||
|
||||
return (key, value)
|
||||
|
||||
def new_participants_and_new_funds_commons(params, step, sL, s, _input):
|
||||
commons = s["commons"]
|
||||
if _input['new_participant']:
|
||||
tokens, realized_price = commons.deposit(_input['new_participant_investment'])
|
||||
# print(tokens, realized_price, _input['new_participant_tokens'])
|
||||
if _input['funds_arrival']:
|
||||
commons._funding_pool += _input['funds_arrival']
|
||||
return "commons", commons
|
||||
# =========================================================================================================
|
||||
def make_proposals_pass_or_fail_random(params, step, sL, s):
|
||||
network = s['network']
|
||||
proposals = get_proposals(network)
|
||||
|
||||
completed = []
|
||||
failed = []
|
||||
for j in proposals:
|
||||
if network.nodes[j]['status'] == 'active':
|
||||
grant_size = network.nodes[j]['funds_requested']
|
||||
base_completion_rate=params[0]['base_completion_rate']
|
||||
likelihood = 1.0/(base_completion_rate+np.log(grant_size))
|
||||
|
||||
base_failure_rate = params[0]['base_failure_rate']
|
||||
failure_rate = 1.0/(base_failure_rate+np.log(grant_size))
|
||||
if np.random.rand() < likelihood:
|
||||
completed.append(j)
|
||||
elif np.random.rand() < failure_rate:
|
||||
failed.append(j)
|
||||
return({'completed':completed, 'failed':failed})
|
||||
|
||||
def get_sentimental(sentiment, force, decay=0):
|
||||
mu = decay
|
||||
sentiment = sentiment*(1-mu) + force
|
||||
if sentiment > 1:
|
||||
sentiment = 1
|
||||
return sentiment
|
||||
|
||||
def sentiment_decays_wo_completed_proposals(params, step, sL, s, _input):
|
||||
network = s['network']
|
||||
proposals = get_proposals(network)
|
||||
completed = _input['completed']
|
||||
failed = _input['failed']
|
||||
|
||||
grants_outstanding = np.sum([network.nodes[j]['funds_requested'] for j in proposals if network.nodes[j]['status']=='active'])
|
||||
grants_completed = np.sum([network.nodes[j]['funds_requested'] for j in completed])
|
||||
grants_failed = np.sum([network.nodes[j]['funds_requested'] for j in failed])
|
||||
|
||||
sentiment = s['sentiment']
|
||||
|
||||
if grants_outstanding>0:
|
||||
force = (grants_completed-grants_failed)/grants_outstanding
|
||||
else:
|
||||
force=1
|
||||
|
||||
mu = params[0]['sentiment_decay']
|
||||
if (force >=0) and (force <=1):
|
||||
sentiment = get_sentimental(sentiment, force, mu)
|
||||
else:
|
||||
sentiment = get_sentimental(sentiment, 0, mu)
|
||||
|
||||
key = 'sentiment'
|
||||
value = sentiment
|
||||
|
||||
return (key, value)
|
||||
|
||||
def complete_proposal(params, step, sL, s, _input):
|
||||
network = s['network']
|
||||
participants = get_participants(network)
|
||||
proposals = get_proposals(network)
|
||||
competitors = get_edges_by_type(network, 'conflict')
|
||||
completed = _input['completed']
|
||||
for j in completed:
|
||||
network.nodes[j]['status']='completed'
|
||||
|
||||
for c in proposals:
|
||||
if (j,c) in competitors:
|
||||
conflict = network.edges[(j,c)]['conflict']
|
||||
for i in participants:
|
||||
network.edges[(i,c)]['affinity'] = network.edges[(i,c)]['affinity'] *(1-conflict)
|
||||
|
||||
for i in participants:
|
||||
force = network.edges[(i,j)]['affinity']
|
||||
sentiment = network.nodes[i]['sentiment']
|
||||
network.nodes[i]['sentiment'] = get_sentimental(sentiment, force, decay=0)
|
||||
|
||||
failed = _input['failed']
|
||||
for j in failed:
|
||||
network.nodes[j]['status']='failed'
|
||||
for i in participants:
|
||||
force = -network.edges[(i,j)]['affinity']
|
||||
sentiment = network.nodes[i]['sentiment']
|
||||
network.nodes[i]['sentiment'] = get_sentimental(sentiment, force, decay=0)
|
||||
|
||||
key = 'network'
|
||||
value = network
|
||||
return (key, value)
|
||||
|
|
|
|||
101
simulation.ipynb
101
simulation.ipynb
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue