• No results found

Analysing the dynamics of scrip systems using threshold strategies

N/A
N/A
Protected

Academic year: 2021

Share "Analysing the dynamics of scrip systems using threshold strategies"

Copied!
37
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

Analysing the dynamics of scrip systems using

threshold strategies

Bachelor Thesis (18 EC)

Winand Renkema (10643478)

BSc Artificial Intelligence

University of Amsterdam

Faculty of Science

Science Park 904

1098 XH Amsterdam

Supervised by:

Jan van Eijck

Centrum Wiskunde & Informatica

Science Park 123

1098 XG Amsterdam

(2)

Abstract

A reproduction study was conducted of the scrip system described by [Kash et al., 2015], which uses artifical currency and utility to model transactions between agents. In such a multi-agent system, one agent is chosen ran-domly to request a service and other agents use strategies to determine whether they should volunteer to provide that service or not. The model was implemented in Haskell, after which simulations could be run. It was hypothesised that a sound implementation would agree with the character-istics of the scrip system as postulated by Kash et al. Most importantly, the existence of non-trivial Nash equilibria in which agents all use threshold strategies as their best-reply function to other agents’ strategy. Second, the convergence of the distribution of wealth across agents towards an opti-mum distribution which minimizes the relative entropy. Both of these main points came forward during the simulations and subsequent analyses. The results that were obtained are in accordance with the observations of Kash et al. regarding the main characteristics and dynamics of the scrip system. Thus, the implementation of the model described in this thesis can be re-garded as an accurate reproduction of the scrip system. However, it might be beneficial to develop alternative methods to assess if a system is in equilibrium, because convergence was insufficient to discriminate between the calculated Nash equilibria and similar threshold strategies. Further re-search and development can be done to the use of this implementation with different types of agents or multiple services – i.e. to analyse peer-to-peer systems or to model resource allocation.

(3)

Contents

1 Introduction 1 2 Related Work 3 3 Method 4 3.1 Agent types . . . 4 3.2 Population . . . 5 3.3 Game . . . 5 3.4 States . . . 6 3.5 Distribution of scrip . . . 7 3.6 Strategy . . . 8 4 Results 9 5 Discussion 14 6 Conclusion 17

Appendix A: Calculating ε-Nash equilibria 20

(4)

1

Introduction

The time of metal coins with intrinsic value is long behind us. Meanwhile, fully artificial cur-rencies like BitCoin become more popular at a fast pace. It raises the question: “what is money exactly?”. Traditionally, coins were valued based on both the commodity it was made of, e.g. gold or silver, and its use as medium of exchange. In the 21st century economy there is a lot more money in circulation than there is intrinsic value of gold stored in banks to support it. The value that money represents, is obtained through the balance between credit and debt and not through its intrinsic value. Money is made when loans are made and can be seen as credit or debt depending on the perspective you take [Van Eijck and Elsas, 2013]. From this point, the step towards a fully artificial currency is quite a small one.

Artificial currency, also called ‘scrip’, was originally used to create local economies when money was not or insufficiently available, e.g. in mining towns, on oil platforms and during economic crises. There are also examples of the usage of scrip when real money was not appro-priate, because a closed economy was wished for. A famous example of such a scrip system is the Capitol Hill Baby Sitting Co-op [Sweeney and Sweeney, 1977], in which couples provide the service of babysitting and get scrip in return. The artificial currency was used to enforce a certain fairness into the group, because each unit of scrip represented a certain amount of babysitting time. An interesting aspect is the fact that the system suffered a recession at some point, due to a great number of people wanting to save up scrip for an evening out. This caused a chain-reaction in which users stayed home in order to accumulate scrip and the request for babysitters declined, therefore it became harder to earn any scrip. Eventually, the system stalled and it was no longer possible to fulfil requests.

More recently, the interest in scrip systems has been increasing in the field of computer science. A common usage can be found in the analyses and optimization of certain aspects of peer-to-peer systems. This introduces the component of currency into a network, which acts as an incentive and counteracts selfish behaviour. It prevents agents from using the system unfairly. An advantage of scrip systems is their limited scope and dynamics, which makes it possible to form a comprehensible local economy, which can be influenced by an administrator. It makes it possible to model and simulate the dynamics on a computer as a multi-agent system. Agents in such systems are often said to be self-interested: they are modelled to maximize their well-being and not necessarily that of the entire system. A measure for this well-being is called ’utility’, which is used in game theoretical sense [Shoham and Leyton-Brown, 2008].

During simulation of a scrip system, agents request a ‘service’ from another agent, whom they pay a fee for providing that service. In consequence, the requesting agent loses scrip, but gains utility due to the service it receives. On its turn, the agent providing the service, loses utility and receives scrip. A micro-economy comes into existence when such a simulation is ran over a significant number of rounds. This economy exists by the virtue of the agents receiving and providing services at random. Studying this behaviour with various agent strategies might tell something about real economies and peer-to-peer systems.

In the paper “An equilibrium analysis of scrip systems” by [Kash et al., 2015], a game-theoretic model of a scrip system is described and its characteristics are analysed. Agents in the described system make use of a threshold to determine whether they should volunteer in case they are selected to provide a service. This so-called threshold strategy determines whether the earned scrip after providing a service justifies the lost utility. It can be seen as the act of deciding whether it makes sense to earn scrip by working now, based on the expectation of spending that scrip in the future.

The main conclusion of the paper by Kash et al. is that there exist equilibria when all agents use threshold strategies as a best-reply function. These equilibria can be seen as states of the system in which the behaviour of an agent is the best possible behaviour given the behaviour of other agents. A more specific finding is that the system can reach a non-trivial Nash equilibrium. If a system is in such an equilibrium, then for all agents applies [Shoham and Leyton-Brown,

(5)

2008]: (1) the agent is aware of the equilibrium strategy of other agents, and (2) its strategy is the best response to strategies used by other agents. However, it is important to note that a Nash equilibrium is not necessarily optimal in respect to the total utility of all agents, but rather agents use a strategy that optimizes their own utility. This aspect can be illustrated by the prisoner’s dilemma, in which there are two prisoners who need to decide whether they will betray the other or remain silent [Shoham and Leyton-Brown, 2008]. In case both betray each other, they will both serve 2 years in prison. When only one decides to speak up, he will be set free and the other will get a 3 years sentence. If both remain silent, they will both only serve 1 year. When taking the well-being of both prisoners into account, remaining silent is the optimal solution. However, this is not a Nash equilibrium as one prisoner can improve its situation by betraying the other, if he is certain the other would remain silent. In the prisoner’s dilemma, the only Nash equilibrium is when both prisoners decide to betray the other. Assuming the other will still betray him, a prisoner cannot improve the situation by changing their strategy to remaining silent.

There are trivial Nash equilibria which can easily be found, for example when all agents use a threshold of zero and no-one ever provides a service. The intuition behind this is that an agent is not able to gain utility from changing its strategy, because it is unable to spend the earned scrip. This means that the optimal strategy of each agent remains unchanged, when taking into account that all other agents make use of threshold zero. There are also non-trivial Nash equilibria in scrip systems, which can be found by the method described in the paper and appendix A. In this case, agents use non-zero thresholds and a viable economy comes into existence.

An important additional characteristic of the described scrip system is the distribution of wealth across agents. When the system is in Nash equilibrium, the distribution of wealth is close to a certain optimal distribution. Kash et al. makes use of this property by showing that the system converges towards this optimum when all agents use threshold strategies.

The aim of this thesis is to replicate the findings of Kash et al. regarding the characteristics of the scrip system described in the paper. This has led to the following research question: “What are the characteristics of the scrip system described in the paper by Kash et al., when it is in a non-trivial Nash equilibrium?”

First, an elaborate system architecture was based on the formal model described in the first paper with additions from the companion paper “Optimizing Scrip Systems: Crashes, Altruists, Hoarders, Sybils and Collusion” [Kash et al., 2012]. The model was implemented in Haskell, based on which simulations could be run.

The hypothesis of this thesis is that a sound implementation of the scrip system will give very similar results and observations regarding the dynamics of the scrip system as stated in [Kash et al., 2015]. The first and foremost being the establishment of non-trivial Nash equilibria when all agents use threshold strategies. More specifically, using threshold values 5 and 10 which followed from calculations (described in appendix A) by Kash et al. Second, the distribution of wealth across agents is expected to converge towards an optimum distribution d∗, of which the formal description is provided in the Method section. Kash et al. makes use of a graph to show this property for a specific simulation, the aim is to obtain the same result in those conditions. Third, more detailed characteristics that are only briefly discussed in the paper are also expected to be reproducible if the original model is implemented successfully. In addition, further analyses were conducted to research the role of the different parameters in the system’s behaviour – a subject that was left untouched by the first paper.

(6)

2

Related Work

History shows a number of cases where a scrip system has been used as a complementary currency system. A famous example of a very successful scrip system can be found in the case of the W¨orgl experiment [Lietaer, 2013]. In the specific case a village in Austria lacked national currency to pay its workers. To solve this problem the local government paid their employees with scrip instead. Because there was an overall lack of money, the scrip was soon used as a replacement for national currency. This circulation resulted in a multiplication of the scrip’s value by a factor of twelve. It shows that scrip in the real world can lead to a functional micro-economy and it suggests that scrip systems behave the same as regular currency systems. A more recent example [Chun et al., 2005] of a scrip system in use, can be found in the instance of the resource allocation system called ‘Mirage’. This system uses virtual currency to enable users to divide the use of machinery at Intel. Through an auction, users bid on the usage of a specific machine for a specific time and purpose. The highest bidder receives the allocation of the machine and pays the corresponding amount of scrip. In this system the users do not earn scrip, but receive it based on a uniform redistribution of the profit of each auction. This example shows that scrip can be a suitable method of implementing fairness into allocations of goods or services.

Kash et al. researches scrip systems in a micro-economic sense. Research into scrip is also done as a method to resolve problems which might occur in internet-based peer-to-peer networks. In these networks an arbitrary number of computers supply each other files or some other form of data through a virtual graph-like network.

A fundamental problem for peer-to-peer networks, like BitTorrent, is the ‘free rider prob-lem’. To solve this problem, a variant of a traditional scrip system is proposed [Rahman et al., 2010]. In traditional systems the equal distribution of scrip will lead to less contributions being made. It also becomes a problem when users only contribute and thus absorb all the available scrip. The proposed alternative is based on the presence of selfish agents, which only contribute when they require files. To create a stable scrip system, a regular intervention is done which consists of either making downloading free or let uploading go without pay.

For the distribution of tasks over multiple agents at the same time, an extension to traditional scrip systems is described [Alechina et al., 2016]. It is intended as a solution for networks in which multiple agents are required to achieve a certain goal, such as Tor networks. The system ensures that contributions are evenly distributed over the present peers. This is done by using a traditional scrip system relying on the presence of utility and threshold strategies. A non-trivial Nash equilibrium has been found and the network seems stable enough for the approach to be regarded as a viable solution for the given problem.

To regulate inter-network traffic, [Wang et al., 2010] has proposed a method which mirrors the usage of resources in the real world through a scrip system. Traffic between networks can be demanding on the infrastructure and can lead to extra costs. To prevent this problem, a payment of scrip is required for downloading bytes, which is based on the actual predetermined costs of the associated traffic. A request is done at the peer that provides the highest utility. The utility is based on the fact that a peer is within the network and therefore serves the bytes at the lowest cost.

This array of examples of real-world usages of scrip systems displays the diversity of con-texts and possible applications. The model of the scrip system that is described and implemented in this thesis consists of ubiquitously seen elements like service request and provision, agent’s behaviour being determined by utility and the existence of (Nash) equilibria. This makes it both theoretically and practically useful.

(7)

3

Method

In the paper ”An Equilibrium Analysis of Scrip Systems” by Kash et al. an algorithm is de-scribed and used to model a scrip system. It is comparable with the exchange system from the baby sitting example described in the introduction and could therefore be used to analyse the dynamics of such a system. The system can be considered a multi-agent system that runs a number of discrete rounds in which random agents interact. In each round an agent is selected at random to request provision of service. Next, a number of agents are selected at random and ‘asked’ whether they are willing to satisfy the request, hence volunteer. From the agents that volunteer, one agent is selected at random to provide the service to the requesting agent. It consequently receives a unit of scrip from the requesting agent, after there has been provision of service. An important detail is the fact that for simplicity, only one type of service exists in the system used for this thesis. The decision whether an agent volunteers to provide service depends on the strategy it uses. In the model a threshold strategy is used, which is based on the fact that the amount of scrip combined with the parameters of an agent determines whether it will volunteer. This strategy enables agents to optimize their utility, by predicting when an agent is expected to run out of scrip before it gets another chance at earning some.

In this section the structure of the model is described in detail. First, the formal repre-sentation of agents will be discussed. After that, the way in which they are integrated in the population will be described. Then the structure and flow of the actual simulation will be put apart. Next the distribution of scrip, which can be used for analysis, is discussed. Finally, the implementation of the threshold strategy is described.

Readers who are interested in the actual implementation in Haskell can consult appendix B.

3.1

Agent types

In the model each agent is of a certain type which is represented by specific parameters. The ranges of these parameters were defined in [Kash et al., 2015] and the values used to run simu-lations were derived from the complementary paper [Kash et al., 2012].

Each type t is represented by a tuple containing five different parameters: t= (α, β, γ, δ, ρ, χ)

Parameter Range Meaning

α ∈ R > 0 Utility lost when providing a service to another agent. β ∈ R 0 ≤ β ≤ 1 Probability of providing a service to another agent. γ ∈ R > α Utility gained when being provided a service by another

agent.

δ ∈ R 0 < δ < 1 Rate at which an agent discounts utility. ρ ∈ N > 0 Rate at which an agent requests for service. χ ∈ N > 0 Relative likelihood of an agent to be chosen when it

volunteers to provide service.

An important derived parameter ω ∈ R describes the expectation of an agent of type t to obtain one unit of currency:

ω =β · χ

(8)

3.2

Population

There can be one or more types of agents in a simulation, which can be defined in the population of the model.

Each population p is defined by a tuple containing a set T of types and a vector ~f defining the fraction of each type in a population:

p= (T, ~f)

An important constraint on this definition is the fact that vector ~f should be of dimension |T |. It is also important to note that the sum of values of ρ (service request rate) over different types in a population should lead to one:

t∈T

ρtft= 1 This can be achieved by normalizing ρ using the formula:

ρt= ρt

∑ t

ρtft

3.3

Game

Each simulation consists of a game that is played for a number of rounds, which is represented in the model.

Each game G is defined by a tuple containing five parameters, of which the first two, repre-senting a specific population, are defined in the previous subsection:

G= (T, ~f, h, m, n)

Parameter Range Meaning

h∈ N > 0 Base number of each type of agent.

n∈ N > 0 Number of replicas of the base number of agents. m∈ R+ > 0 Average amount of currency per agent.

An important restriction on the base number h, is the fact that is should not lead to decimal numbers when applied to the fraction ~f of agents:

∀t ∈ T ( fth∈ N)

In addition, the average amount of currency times the base number should not lead to decimal numbers:

mh∈ N

The total number of agents in a game can be computed by multiplying the base number h by the number of replicas n. Each individual agent in a game can be identified by a number i between 1 and hn. This follows from the distribution of agent types:

ti= (

1 . . . fi(hn), if i = 1

(9)

3.4

States

During a simulation there are different states which describe the progression of a game. Each state s is represented with the following tuple consisting of five parameters:

s= (r, p,~x, i,V )

Parameter Range Meaning

r∈ N ≥ 0 Round in the game.

p∈ N 1 ≤ p ≤ 4 Phase of round r.

~x ∈ R+ ∀x

i∈ [1 . . . hn] (i ≥ 0) Currency of each agent.

i∈ N ≥ 0 Agent that is requesting provision of service.

V ⊆ N ∀v ∈ V (v ∈ [1 . . . hn]) Set of agents selected for provision of service. Flow

The transition between different states is illustrated in the flow chart (figure 1). It must be noted that tuples in the figure are abbreviated for readability; they unfold to their right.

start (0, 1) (0, 1,~x) (r, 2,~x, i) (r, 3,~x, i,V ) (r, 4,~x, i,V0) (r + 1, 1,~x) finish 1 2 3 4 5 6

Figure 1: Simulation flow

Each transition consists of the following:

1. The available currency is allocated at random in a uniform manner. This means that each agent has a equal chance of receiving a unit of currency.

2. An agent i is selected to request provision of service using the probability (where ρ is normalized):

P(agent i requests) =ρτ(i) hn

3. Agents V are selected to provide a service (with the exception of agent i) using the prob-ability:

P(agent j can provide) =βτ( j) hn

4. Agents V0 are the agents in V that choose to volunteer based on their strategy. In the subsection Strategy the exact definition of this is described.

5. An agent j is selected from V0using the probability: P(agent j provides) = χτ( j)

∑ j0∈V0χτ

( j0)

When an agent j is selected, a transaction of 1 unit of scrip from agent i to agent j takes place, which leads to a transition to the state (r + 1, 1,~x0).

In case of V0= /0, the next round is started by making a transition to the state (r + 1, 1,~x). If the predefined maximum number of rounds is reached, the game ends.

(10)

3.5

Distribution of scrip

During a simulation the actual distribution d is compared with the optimal distribution d∗of scrip. The distribution d∗is defined as the distribution of scrip with minimal relative entropy to the distribution q. The euclidean distance between the actual distribution and the optimal distribution is computed to determine to which extent the actual distribution has converged to the minimal relative entropy situation.

The current distribution d is defined by the set of fractions d(t, l) of agents of type t with amount of currency l:

d(t, l) =agents of type t with l currency total number of agents

Due to the character of d(t, l), the elements in d should sum up to their fraction ft for a specific type and to 1 for all types.

To compute the optimal distribution d∗, the expectation q of type t for obtaining l units of currency needs to be defined first:

q(t, l) = (ωt) l ∑ t kt ∑ m=0 (ωt)m

Note that this formula simply uses ωt, which stands for the expectation of an agent of type t having one unit of currency, and multiplies it by itself for l times. To normalize the expectation, it then is divided by the total sum of expectations.

Based on the values of q the distribution d∗is computed for all types and amounts of currency, using the following formula:

d∗(t, i) = ftλ iq(t, i) kt ∑ j=0 λjq(t, j)

Using λ the weight of d∗can be regulated such that the following applies:

t kt

l=0 ld∗(t, l) = m

When both the current distribution d and the optimal distribution d∗are computed, the euclidean distance between each corresponding point can be computed:

t

l

|d(t, l) − d∗(t, l)|2

The euclidian distance indicates the degree of convergence to the optimal distribution for a particular state in the game. This is also used as indication for reaching a Nash equilibrium, as will be elaborated on in the Results section.

(11)

3.6

Strategy

During a simulation, an agent uses a strategy to make the decision whether it will volunteer or not. In this model, a so-called threshold strategy is used, which means that each agent makes use of a dynamic threshold to make this decision. It relies on the utility of providing a service and hence earning a unit of scrip. The value of this threshold is important, because the threshold strategy fully determines the agent’s behaviour.

An agent will try to compute the utility of a unit of scrip based on the best response possible when taking into account other agents. It uses the optimal distribution d∗ to determine the fraction of agents with a certain amount of scrip, as the actual distribution is expected not to deviate far from d∗. The utility of a unit of scrip will be the highest if an agent will run out of scrip before it gets a chance for earning any money.

The number of rounds J when an agent is expected to run out of scrip is calculated based on the units of currency k, and the probabilities u of earning and d of losing money: +

J(k, u, d) = (

1, if k < 1

J(k + u − d, u, d) + 1, otherwise

The probability u of earning one unit of currency is computed by multiplying the probability that some other agent is chosen, by the probability that the agent itself will be chosen. The former is calculated by taking the sum of the request rate ρt0 times the fraction of agents with

at least one unit of scrip. The latter depends on the relative likelihood of being chosen when volunteering (χt) and the probability of offering to provide a service (βt), which is normalized by the likelihood that other agents that volunteer are chosen.

Pu=

t0 ρt0( ft0− d∗(t0, 0)) !  χtβt ∑ t χt0νt0  

On the right side of the previous formula, ν indicates the expectation of a specific type t to vol-unteer. This depends on the probability of providing a service (βt), multiplied with the fraction of agents which have less scrip than their threshold kt. This probability is then multiplied by the total number n of agents, resulting in the number of agents of type t which are expected to volunteer.

νt= βt( ft− d∗(t, kt))n

The probability d of being chosen to perform a request is computed by dividing the relative request rate by the number of agents.

Pd= ρt

n

Using J, a particular agent computes the highest threshold for which the utility of volunteering is greater than or equal to the utility αt lost for providing a service. The utility gain γt and discount for future utility δt are also taken into account. The threshold is calculated by finding the highest value of κ for which the following condition applies:

αt≤ E[(1 − (1 − δt)/n)J(κ,Pu,Pd)]γt

In case the value of κ is greater than the current amount of scrip k, an agent volunteers to provide a service. It implies that an agent expects to run out of scrip within a number of rounds, before it gets the chance to earn some more scrip.

(12)

4

Results

The model of the scrip system described in the Method of this thesis has been composed ac-cording to the model described in [Kash et al., 2015]. No adjustments or simplifications were made, thus it is expected that very similar results will be obtained. In the upcoming section certain essential characteristics of the scrip system described by Kash et al. will be proven and illustrated.

All simulations described were conducted with a total number of 1000 agents and an average amount of scrip of 2. Each one was started from a extreme distribution of wealth in which each agent either had 0 or 5 units of scrip. A single type of agent was used which was configured with the following parameters: α = 0.05, γ = 1, δ = 0.95, β = 1, ρ = 1, χ = 1. These parameters were derived from the complementary paper [Kash et al., 2015].

Convergence to d

from an extreme distribution for s

5

To illustrate the convergence of the distribution of the observed distribution d and the optimal distribution d∗, a simulation was run with 1000 agents for 4000 rounds using a threshold of 5. The resulting average of 10 runs is shown in figure 2.

0 0.01 0.02 0.03 0.04 0.05 0.06 0 500 1000 1500 2000 2500 3000 3500 4000 Euclidian distance Number of rounds

Figure 2: Euclidean distance between d∗and d for threshold 5.

It can be observed from figure 2 that the system converged after at approximately 4000 rounds. At this point it reached an euclidean distance of 0.001 between d and d∗.

To confirm the persistence of the convergence figure 6 should be consulted. It illustrates amongst other the same simulation with threshold 5 for 10.000 rounds.

(13)

Distributions q and d

To visualize the distribution q and d∗data was acquired from a simulation with a single type of agent with threshold 5. Based on this figure 3 was made of the distribution of wealth across agents, which the scrip system converges to when it reaches a Nash equilibrium. This emerges from the fact that the system will be very close to d∗when it is reaches such a equilibrium.

0 1 2 3 4 5 0 0.1 0.2 0.3 Scrip Fraction (a) Distribution q 0 1 2 3 4 5 0 0.1 0.2 0.3 Scrip Fraction (b) Distribution d∗

Figure 3: Distributions q and d∗of wealth for threshold 5

In figure 3a can be seen that the appropriate distribution q is uniform. Next to it in figure 3b the shape of distribution d∗can be seen, which minimizes the relative entropy to q.

Fraction of agents volunteering

In order to illustrate the distribution of the fraction of volunteers per 1000 rounds figure 4 was composed. This was done based on a simulation of 10.000 rounds with threshold 5. Each round the fraction of volunteering agents was registered. Consequently the data was binned per 1000 rounds. The fractions were averaged for 10 runs.

The graph should be interpreted as follows; The first column shows that circa 55% of the time – during 550 rounds – all agents that are selected, chose to volunteer. In the same bin can be seen that about 10% of the time – 100 rounds – 12 of the agents volunteer. Finally it can be seen that about 20% – 200 rounds – no agents were found to volunteer.

Analogous to the convergence which can be seen in figure 2, the fractions of volunteers remains approximately the same after 5000 rounds. It is also visibile that circa 80% of the time all agents chose to volunteer and the percentage of rounds in which no agent volunteers dropped to 10%.

(14)

2,000 4,000 6,000 8,000 10,000 0 0.2 0.4 0.6 0.8 1 Number of rounds Distrib ution of v olunteering per 1000 rounds Fraction 1.00 0.66 0.50 0.33 0.00 Other

Figure 4: Distribution of the fraction of volunteers averaged over 1000 rounds for threshold 5

Nash equilibria of other threshold strategies

To illustrate the effect of other threshold strategies, simulations were run for 10.000 rounds with different thresholds ranging from 0 to 10. The average per 10 runs is shown in figure 5 and 6.

0 0.2 0.4 0.6 0.8 0 2,000 4,000 6,000 8,000 10,000 Euclidian distance Number of rounds Threshold 0 1 2 3 4

Figure 5: Euclidean distance between d and d∗for threshold 0 to 4.

In figure 5 the results for threshold strategies s0to s4 are shown. It can be observed that the euclidean distance between d and d∗is constant and equal to the euclidean distance at the

(15)

beginning of the simulation. 0 0.02 0.04 0.06 0 2,000 4,000 6,000 8,000 10,000 Euclidian distance Number of rounds Threshold 5 6 7 8 9 10

Figure 6: Euclidean distance between d and d∗threshold 5 to 10

The results in figure 6 shown the dynamics of the scrip system for threshold strategies s5to s10. It shows that the system is found to converge to the same euclidean distance of approxi-mately 0.001 for all thresholds strategies.

Social welfare

≤ 4 5 6 7 8 9 10 0 10 2600 2700 2800 Threshold W elf are

Figure 7: Social welfare of threshold 0 to 10 In order to illustrate the effect of individual

thresholds on the social welfare, data was col-lected for the thresholds ranging from 0 to 10. In figure 7 the averages of 10 runs are shown. It is important to note that the social wel-fare is dependant of the occurrence transac-tions between agents, which are inherently probabilistic. This means that the results might be more pronounced when the proba-bility of a transaction increases.

From the figure it becomes clear that for threshold strategies s0to s4, a value of 0 was calculated for the social welfare. Also it can be seen that threshold strategy s5resulted in the highest social welfare.

(16)

Varying parameters α and γ

To obtain insight in the dynamics of α and γ a number of simulations were run for varying values. This was done because no values were specified in [Kash et al., 2015], while these parameters are used for the threshold strategy. The analysis of these parameters was conducted by varying α between 0.05 and 0.5, combined with γ between 1 and 0.5.

0 0.01 0.02 0.03 0.04 0.05 0.06 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 Euclidian distance Number of rounds α 0.05 0.30 0.50

Figure 8: Euclidean distance between d and d∗. Comparison of simulations ran with α = 0.05, α = 0.3 and α = 0.5.

The results of the different simulations showed that the systems seems to be robust for these changes for γ as no differences were observed.

In case α ≥ 0.25 then the system seems to converge faster towards d∗ in the first 3000 rounds, but then drifts away again. This effect becomes more pronounced with higher values of α. The figure shows the difference between a simulation with the default α = 0.05 and runs with α = 0.3 and α = 0.5.

(17)

5

Discussion

One of the most prominent characteristics of script systems discussed by [Kash et al., 2015], is the existence of a non-trivial Nash equilibrium when all agents play threshold strategies. It is hypothesised that the social welfare is optimal in case of s5, hence the overall utility is opti-mal. A Nash equilibrium is said to exist when all agents use a best-reply strategy and take the strategies of others into account. The model by Kash et al. conforms to this requirement, be-cause other agents’ strategies are incorporated into the threshold strategy formula. It is however not possible to directly prove that agents do not change their strategy at a given moment. This applies especially to large systems, as an agent can only volunteer on average once in every n rounds.

Proving whether a system is in equilibrium can only be done indirectly according to Kash et al. This follows from the fact that their paper describes a formal proof that states that the distribution of wealth converges to a distribution d∗ and only minimally deviates from it. In addition it is postulated that the fraction of volunteers remains constant when the system is in Nash equilibrium.

Convergence to d

from an extreme distribution for s

5

In order to demonstrate the validity of the Haskell implementation of the scrip system, figure 3 of the paper was reproduced in figure 10. For explanatory reasons the figure from the original paper has been included in figure 9.

Figure 9: Figure 3 from [Kash et al., 2015]

The result in figure 10 shows that the system convergences to d∗in approximately 4000 rounds. When comparing it with figure 9 by Kash et. al. it becomes clear that the obtained result seems to match the original strongly. This match can be regarded as confirmation of the validity of the implementation. It can be considered proof that the system reaches the s5Nash equilibrium fairly quickly, like postulated in the paper.

(18)

0 0.002 0.004 0.006 0.008 0.01 2000 2500 3000 3500 4000 Euclidian distance Number of rounds

Figure 10: Euclidean distance between d∗and d for threshold 5, adapted from 2

Distributions q and d

To visualize the distribution of wealth across agents that is established in Nash equilibrium, the distributions q and d∗are shown in figure 3a and 3b respectively. These figures are complemen-tary to the original paper, because it only provided equations of these distributions.

The distribution q is considered the appropriate distribution, it is based on the derived pa-rameter ωt which describes the expectation of an agent to obtain one unit of currency. Due to its structure it is uniform within a type of agent, but also within the scope of this thesis because there is only a single type of agent used.

To minimize the relative entropy of the appropriate distribution d∗is applied on it. This is done because in the model not each state - or distribution of wealth - is equally likely due to the so called ’concentration phenomenon’. This is the observation that there are more possible distributions with high than low entropy. It means that the desired distribution is one which min-imizes the relative entropy to the uniform distribution, which is in fact the same as maximizing the entropy of the distribution of wealth across agents.

Fraction of agents volunteering

Another prediction of Kash et al. about non-trivial Nash equilibria is that there is a constant percentage of volunteers when the system is in such an equilibrium. The results from the sim-ulation are shown in figure 4 for threshold strategy s5. This confirms that the systems behaves according to that prediction.

Nash equilibria of other threshold strategies

The Nash equilibria in Kash et al.’s paper were calculated using Tarski’s fixed point theorem, which resulted in the following three equilibria: s0, s5and s10. In appendix A is described how this was done and the formal proof is given for the assumption that all agents use threshold strategies.

Threshold strategy s0is a trivial Nash equilibrium in which agents never decide to volunteer, like described in the introduction. This results in no transactions between agents and thus no convergence to d∗will take place. It was hypothesised that this is also the case for s1to s4,

(19)

because s5 is a unstable equilibrium. When looking at figure 5 it becomes clear that for the strategies s0to s4the euclidean distance remains constant over multiple rounds. From the lack of convergence can be derived that threshold strategies s1to s4result in similar behaviour as s0. To confirm that this was due to the absence of transactions taking place, the social welfare was used. This was in all cases 0, hence no transactions took place.

Threshold strategy s5is hypothesised to be the first non-trivial Nash equilibrium and s10the second one. For thresholds higher than 5 is expected that they are similar to s10in their dynam-ics. The results in figure 6 show that the system converges to d∗for the threshold strategies s5 to s10, but all with differences in dynamics and starting point.

From the calculations in the paper followed that s5and s10are non-trivial Nash equilibria, and the thresholds in between should converge to s10. The strategies s6to s9should not result in Nash equilibria, because the condition BRG(k) = k does not hold according to the calculations of Kash et al. (appendix A). However, no clear distinction can be made with figure 6 between the nature of thresholds 5, 10 and the numbers in between. It seems to be the case that the system does reach a non-trivial Nash equilibrium, because of the convergence to d∗. Also, the social welfare is still quite high as can be seen in the next section, which is indicative of lots of transactions between the agents. In conclusion, the analyses conducted are insufficient to differentiate between the nature of the equilibria established in threshold strategies s5to s10.

Social welfare

The paper by [Kash et al., 2012] regarding the optimisation of scrip systems made use of the concept ‘social welfare’ to asses the efficiency or healthiness of the system as a whole. It is defined as the total utility of all the agents in the system it accumulative over rounds.

The social welfare in figure 7) was determined for the threshold strategies s0 to s10 over 10.000 rounds. From the results can be concluded that in s0 to s4 no transactions between agents took place. This confirms the hypothesis that behaviour of the agents is the same for thresholds 1 to 4 as for threshold 0, or that the s5non-trivial Nash equilibrium is unstable. The highest social welfare was found for s5, which confirms the findings of Kash et al. However, because of the theoretical instability of this threshold strategy, as concluded by Kash et al., the greatest non-trivial Nash equilibrium s10 is used to conduct further analyses into optimizing scrip systems [Kash et al., 2012].

Varying parameters α and γ

The original paper from Kash et al. provides no values for the parameters α and γ which are the utility cost and gain per transaction, respectively. These parameters are used in the threshold strategy calculations, so they are hypothesised to be important for the system dynamics. (Within the scope of this thesis values were used originating from [Kash et al., 2012], thus α = 0.05 and γ = 1.) To analyse the robustness of the system concerning these parameters, α was varied between 0.05 and 0.5, while γ was varied between 1 and 0.5. The results obtained are displayed in figure 8. According to these simulations, changing γ had no effect but α ≥ 0.25 disrupted the convergence. Large values of α were found to cause faster convergence towards d∗followed by bending off towards a larger euclidean distance. Increasing this value means increasing the cost of providing a service in terms of losing utility. The drifting away again from d∗could be indicative of a failure to reach an equilibrium, but it could also indicate a large oscillation whilst in equilibrium. Further analyses should be conducted to precisely characterize the influence of α and γ on the establishment of a Nash equilibrium.

(20)

6

Conclusion

The aspiration of this thesis was to replicate the findings of Kash et al. in the paper [Kash et al., 2015]. Therefore the research question aimed at the characteristics of the described scrip system. In particular it is targeted at proving the existence of non-trivial Nash-equilibria.

In order to conduct simulations and analyses, an implementation in Haskell was made. It was hypothesised that if this implementation is sound, it is expected to result in very similar behaviour of the system dynamics as described by Kash et al.

The results in this thesis confirm all hypotheses that are proposed by Kash et al. The dy-namics as discussed in the paper were obtained, which resulted in a very similar graph using the same parameters. Most importantly, the scrip system was found to converge to d∗for threshold strategies s5to s10. This convergence was found to be quite robust for changes in the utility gain parameter γ, but more vulnerable for too large values of utility cost α. In addition, the social welfare was confirmed to be optimal for s5and the fraction of volunteers also remained constant after convergence.

However, it was not possible to assess whether a certain threshold strategy is a Nash equi-librium based on its convergence. Threshold strategies s5to s10all converge to 0.001 of d∗, but only s5 and s10 are calculated to be true non-trivial Nash equilibria. The threshold strategies in between do behave similarly, because s10 is stable and nearby points converge towards it. Nevertheless, as e.g. s6does not comply to all requirements stated in appendix A, it cannot be considered a true Nash equilibrium. This raises the question whether the convergence to d∗is a reliable indication of the establishment of a Nash equilibrium for certain parameters. It might be beneficial to develop alternative methods to assess if a system is in equilibrium. For example, a derivative of an agent’s previously played threshold strategies in order to measure more directly if it is a best-reply function and remains consistent over time.

It is important to note that the simulations were conducted for a single type of agent, because this simplification was also made in the paper. It would be interesting to study the influence of different types of agents on the equilibrium and social welfare. The current implementation in Haskell also allows multiple agent types being specified. It also forms a framework for extensions like multiple types of service or with differences in fee. While it provides a sound basis for experiments it proved to be very memory consuming, so it might be a good idea to convert it to a more memory efficient program.

Further down the lane, simulations like this can be used for the analysis and subsequent man-agement of peer-to-peer systems. Also, this implementation of a scrip system can be adapted to be used for resource allocation: the distribution of tasks over multiple agents at the same time.

More research into the dynamics of scrip systems would be valuable for both their theoretical and practical applications. There are still a lot of unanswered questions, like how external perturbations affect the establishment and maintainance of Nash equilbria.

(21)

References

[Alechina et al., 2016] Alechina, N., Halpern, J. Y., Kash, I. A., and Logan, B. (2016). Decen-tralised norm monitoring in open multi-agent systems. arXiv preprint arXiv:1602.06731. [Chun et al., 2005] Chun, B. N., Buonadonna, P., AuYoung, A., Ng, C., Parkes, D. C.,

Shneid-man, J., Snoeren, A. C., and Vahdat, A. (2005). Mirage: A microeconomic resource alloca-tion system for sensornet testbeds. Institute of Electrical and Electronics Engineers.

[Kash et al., 2012] Kash, I. A., Friedman, E. J., and Halpern, J. Y. (2012). Optimizing scrip sys-tems: crashes, altruists, hoarders, sybils and collusion. Distributed Computing, 25(5):335– 357.

[Kash et al., 2015] Kash, I. A., Friedman, E. J., and Halpern, J. Y. (2015). An equilibrium analysis of scrip systems. ACM Transactions on Economics and Computation, 3(3):13. [Lietaer, 2013] Lietaer, B. (2013). The future of money, chapter Work-Enabling Currencies.

Random House.

[Rahman et al., 2010] Rahman, R., Hales, D., Vinko, T., Pouwelse, J., and Sips, H. (2010). No more crash or crunch: Sustainable credit dynamics in a p2p community. In High Perfor-mance Computing and Simulation (HPCS), 2010 International Conference on, pages 332– 340. IEEE.

[Shoham and Leyton-Brown, 2008] Shoham, Y. and Leyton-Brown, K. (2008). Multiagent sys-tems: Algorithmic, game-theoretic, and logical foundations. Cambridge University Press. [Sweeney and Sweeney, 1977] Sweeney, J. and Sweeney, R. J. (1977). Monetary theory and the

great capitol hill baby sitting co-op crisis: comment. Journal of Money, Credit and Banking, 9(1):86–89.

[Van Eijck and Elsas, 2013] Van Eijck, J. and Elsas, P. (2013). What is money?

[Wang et al., 2010] Wang, C., Wang, H., Lin, Y., and Chen, S. (2010). A currency-based p2p incentive mechanism friendly with isp. In Computer Design and Applications (ICCDA), 2010 International Conference on, volume 5, pages V5–403. IEEE.

(22)

Appendix A: Calculating ε-Nash equilibria

The paper by [Kash et al., 2015] describes an formal algorithm for analysing scrip systems, which key feature is proving the existence of non-trivial Nash equilibria. This was used to analyse the model defined in the paper, which was found to have two non-trivial Nash equilibria where all agents use threshold strategies. To calculate these Tarski’s fixed point theorem was used, resulting in the threshold strategies s5and s10. In this appendix, the premises and reasoning behind this is described and more formal proof is given for the statement that the usage of threshold strategies can lead to the establishment of Nash equilibria.

First of all, a short summary of the definition of a Nash equilibrium [Shoham and Leyton-Brown, 2008]:

If the system is in Nash equilibrium, then for all agents applies that: (1) the agent is aware of the equilibrium strategy of other agents, and (2) it does not gain utility by changing its strategy. Hence, a strategy used by an agent whilst in Nash equilibrium is by definition the ‘best-reply’ function to the other strategies used, because of (2).

Instead of a strict Nash equilibrium, an approximate or ε-Nash equilibrium was used in the paper. This is a game-theoretical detail that was left out of this thesis because of the limited scope. An ε-Nash equilibrium (ε-NE) is less strict on condition (2), it allows an agent to gain an ε amount of utility when he deviates from his strategy. A regular (or strict) Nash equilibrium has ε = 0. Using the ε-NE makes computations more tractable compared to the strict version.

When the system is in ε-NE, the agents all use ε-best-reply strategies. It is thought to be an ε-best-reply to the strategy profile of agents other than himself, when the utility of that particular strategy plus some factor ε is higher than that of other possible strategies. This is formally stated as:

Ui(S00i, ~S−i) ≤ Ui(S0i,~S−i) + ε

The utility Uiof agent i is considered when it uses strategy Si0, if agents other than himself use strategy profile ~S−i.

This optimal response to the strategies of other agents can be reduced to finding an optimal policy in the ‘Markov decision process’. The behaviour of this process depends on puand pd, respectively the probability of gaining and losing a unit of scrip. Kash et al. formally proves in his paper that the ε-best-reply is a threshold strategy, of which the threshold kt0is calculated with the designated formula containing αt, γtand J (see Method section). Only if an agent has less scrip than this threshold kt0, it will choose to volunteer for providing service.

The ε-best-reply function is defined as BRG(~k) =~kt0. This describes that in a game G, the op-timal strategy of an agent is to use k0tas threshold, when other agents use strategy profile ~S−i(~k) This BRGfunction can be used to compute the Nash equilibria of the scrip system. First, Kash et al. formally proves that BRGis monotone (non-decreasing), which means that it ‘preserves the order’ and will only increase but never decrease. In other words: if some agents change their strategy by increasing the threshold, then other agents cannot gain anything by lowering their threshold. This means that the decisions of the agents mutually reinforce one another, something that is called ‘strategic complements’.

The monotonicity guarantees that BRG(BRG(~k)) ≥ BRG(~k) This property of BRG allows Tarski’s fixed point theorem to be used to iteratively compute a ’greatest’ point which should be a non-trivial (Nash) equilibrium of the scrip system. A state of a system in which conforms to BRG(~k) =~k, is called a fixed point. The least fixed point is the lowest value of ~k for which this holds and the greatest fixed point the highest value of ~k. This greatest fixed point was be computed by starting with a strategy profile where everyone always volunteers (s∞) and then iteratively computing the ε-best-reply profile until it converges to an ε-Nash equilibrium.

In the scrip system used, there is only one type of agent so BRG: N → N. As a consequence of all agents being of the same type, the possible equilibria have to comply to BRG(k) = k. This

(23)

means that the best-reply threshold value of one agent would be the same as the threshold value of the other agents. Kash et al. found three Nash equilibria which comply to this: s0, s5and s10. The first one, s0, is a trivial Nash equilibrium in which no transactions occur, which therefore can be disregarded for further optimisation and analysis. The second one, s5, was found to have the best outcome in terms of utility for the system as a whole (social welfare). However, s10 was found to be more stable in the way that other converge towards it, and away from s5. In the companion paper [Kash et al., 2012] this greatest fixed point ε-NE is used as starting point for optimizing the scrip system.

(24)

Appendix B: Haskell Implementation

1 import qualified Data.Vector as V

2 import qualified Data.Text as T

3 import Data.Configurator as C 4 import Data.List 5 import System.Environment 6 import System.IO 7 import System.Random 8 9 import Debug.Trace 10 11 -- Helper functions

12 isNatural :: Double -> Bool

13 isNatural n = n >= 0 && n == fromInteger (round n) 14

15 writeTuples :: (Show a, Show a1) => [Char] -> [(a, a1)] -> IO () 16 writeTuples f l =

17 do

18 outh <- openFile filename WriteMode

19 hPutStrLn outh $ concat $ map

20 (\(x,y) -> (show x) ++ "," ++ (show y) ++ "\n")

21 l

22 hClose outh

23 where

24 filename = "data/" ++ f ++ ".csv" 25

26 writeTriples :: (Show a, Show a1, Show a2) => [Char] -> [(a, a1, a2)]

-> IO ()

,→

27 writeTriples f l =

28 do

29 outh <- openFile filename WriteMode

30 hPutStrLn outh $ concat $ map

31 (\(x,y,z) -> (show x) ++ "," ++ (show y) ++ "," ++ (show z) ++

"\n") ,→ 32 l 33 hClose outh 34 where 35 filename = "data/" ++ f ++ ".csv" 36

37 -- Generate random ints in range with seed 38 randomInts :: (Int, Int) -> Int -> Int -> [Int]

39 randomInts range element seed = (randomRs range (mkStdGen s)) :: [Int]

40 where s = ((seed*10) + element)

41

42 -- Data types 43 data Type = Type {

44 utility_lost :: Double,

45 provide_probability :: Double,

46 utility_gain :: Double,

47 discount_rate :: Double,

(25)

49 volunteer_likelyhood :: Int

50 } deriving (Eq, Show)

51

52 data Population = Population {

53 types :: [Type],

54 omega :: [Double],

55 fraction :: V.Vector Double,

56 strategies :: V.Vector Double

57 } deriving (Eq, Show)

58

59 data Game = Game {

60 population :: Population, 61 base_number :: Int, 62 replicas :: Int, 63 average_currency :: Double 64 } deriving (Eq, Show) 65

66 data Configuration = Configuration {

67 mode :: Int,

68 rounds :: Int,

69 runs :: Int,

70 interval :: Int,

71 lambda_offset :: Maybe Double,

72 currency :: Maybe [Double],

73 seed_offset :: Maybe Int

74 } deriving (Eq, Show)

75

76 data Data = Data {

77 game :: Game,

78 hn :: Int,

79 seed :: Int,

80 random_probabilities :: [V.Vector Double],

81 random_agents :: V.Vector Int,

82 lambda :: Double,

83 type_per_agent :: V.Vector Int,

84 threshold_per_agent :: V.Vector Double,

85 provide_probability_per_agent :: V.Vector Double,

86 ds_distribution :: V.Vector (Int, Double, Double)

87 } deriving (Eq, Show)

88

89 -- Program specific function

90 initializeType :: Double -> Double -> Double -> Double -> Double ->

Int -> Type

,→

91 initializeType a b y d p x = (Type a b y d p x) 92

93 initializePopulation :: [Type] -> V.Vector Double -> V.Vector Double

-> Population

,→

94 initializePopulation t f x

95 | length t /= V.length f

96 = error "The number of elements in f should be equal to |T|"

97 | otherwise = (Population t_normalized o f x)

(26)

99 -- Compute total of all request rates

100 denominator = V.foldl1 (+) $

101 V.zipWith (\x y -> x*(request_rate y)) f $ V.fromList t 102 -- Computing normalized request rate

103 t_normalized = map (\x -> (

104 x {request_rate = (request_rate x/denominator)})

105 ) t

106 -- Computing omega

107 o = map (\t -> (

108 (provide_probability t) *

109 (fromIntegral $ volunteer_likelyhood t)::Double

110 ) / (request_rate t)

111 ) t_normalized

112

113 isType :: Data -> Int -> Int 114 isType gd i = (\(Just i) -> i) $ 115 V.findIndex (>fromIntegral i) $ 116 V.scanl1 (+) $

117 V.map (* (fromIntegral $ hn gd))

118 (fraction (population $ game gd))

119

120 allocateCurrency :: Configuration -> Data -> V.Vector Double 121 allocateCurrency c gd =

122

123 if (currency c == Nothing) then

124 -- When no currency is set, allocate it at random

125 allocateRandomThreshold

126 else

127 -- When currency is set, allocate chunks

128 allocateChunk

129 where

130 allocateChunk = if (isNatural number_of_chunks) then

131 (V.fromList $ concat [

132 chunk | x <- [1.. n / fromIntegral (length chunk)]

133 ])

134 else

135 error "The given currency chunk does not fit!"

136 where

137 chunk = (\(Just i) -> i) (currency c)

138 number_of_chunks = n / fromIntegral (length chunk)

139 -- Number of agents in the system

140 n = fromIntegral $ hn gd

141 -- Total amount of currency in the system.

142 m = truncate $ (average_currency $ game gd) * n

143 -- Generate random id for each individual piece of

currency

,→

144 random_ids = V.map (\x -> (fromIntegral x)::Double) $

145 -- V.take m $ V.drop m $ random_agents gd

146 V.fromList $ take m $ randomInts (0, truncate n-1) 4 (seed

gd)

,→

147 -- Allocate currency at random over all agents

(27)

149 (\z -> ((fromIntegral (V.length $ V.filter (==z)

random_ids)))::Double)

,→

150 (V.fromList [0.. n-1])

151 -- Allocate currency at random to threshold over all

agents ,→ 152 allocateRandomThreshold = dealCurrency 153 gd (V.fromList [ 0::Double | x <- [0..n-1] ]) strategy_per_agent m 0 (seed gd) ,→ 154 p = population $ game gd

155 number_of_agents_per_type = map (\x -> round $ x*n) $ V.toList $

fraction $ p

,→

156 strategy_per_agent = V.fromList $ concat [

157 [ V.head $ V.drop t $ strategies p | x

<-[1..(number_of_agents_per_type !! t)] ] |

,→

158 t <- [0..((V.length $ strategies p)-1)]

159 ]

160

161 dealCurrency :: Data -> V.Vector Double -> V.Vector Double -> Int

-> Int -> Int -> V.Vector Double

,→

162 dealCurrency _ x _ 0 _ _ = x

163 dealCurrency gd x t m r s = if ((V.head $ V.drop random_id x) < (V.head $

V.drop random_id t)) then

,→

164 dealCurrency gd (

165 (V.take random_id x) V.++

166 V.fromList [((V.head $ V.drop random_id x) + 1.0)] V.++ 167 (V.drop (random_id + 1) x)

168 ) t (m-1) (r+1) s

169 else

170 dealCurrency gd x t (m-1) (r+1) s

171 where

172 -- Number of agents in the system

173 -- random_id = head $ drop r $ randomInts (0, (V.length

x) - 1) 5 s

,→

174 random_id = V.head $ V.drop r $ random_agents gd

175

176 initializeGame :: Population -> Int -> Int -> Double -> Game 177 initializeGame p h n m

178 | correctBaseNumber == False

179 = error $ "The base number should be a multiple of " ++

180 (takeWhile (/=’.’) $ show $ 1.0 / (V.minimum $ fraction p))

181 | correctAverage == False

182 = error "An incorrect average amount of currency is used"

183 | otherwise = (Game p h n m)

184 where

185 hn = (fromIntegral h) * (fromIntegral n)

186 -- Check whether parts of fraction result in natural

numbers only

,→

187 correctBaseNumber = V.foldr (\x y ->

188 isNatural (x * fromIntegral h) && y

189 ) True $ fraction p

190 correctAverage = isNatural $ m * hn

(28)

192 selectRequestingAgent :: Data -> V.Vector Double -> Int -> Int 193 selectRequestingAgent gd x r = index

194 where

195 -- Minimum amount of currency for an agent to be

requesting

,→

196 m = 1.0

197 -- Population in the game

198 p = population $ game gd

199 -- Number of agents in the game

200 n = fromIntegral $ hn gd

201 -- Number of agents per type in the game

202 n_per_type = V.map (*n) $ fraction p

203 -- Request probability per type in the game

204 request_prob_per_type =

205 V.fromList $ map (\x -> (request_rate x)/n) (types p) 206 -- Random real between 0 and 1

207 -- random_real = (randomDoubles (0,1) 0 (seed gd)) !! r

208 random_real = V.head $ V.drop r (random_probabilities gd !! 0)

209 -- Probability distribution per agent

210 distribution = V.zipWith (*) n_per_type request_prob_per_type

211 -- Type associated with probability

212 u = case (V.findIndex (>random_real) $ V.scanl1 (+) distribution)

of

,→

213 Just r -> r

214 Nothing -> (V.length distribution)- 1

215

--216 sumTakeV n v = V.foldl (+) 0 $ V.take n v

217 -- Lower boundary of type

218 lower = sumTakeV u n_per_type

219 -- Upper boundary of type

220 upper = sumTakeV (u+1) n_per_type

221 -- Lower boundary of probability of type

222 lower_p = sumTakeV u distribution

223 upper_p = sumTakeV (u+1) distribution

224 rel_p = (random_real - lower_p) / (upper_p - lower_p)

225 -- Calculate local index value

226 calculated_index = floor $ (rel_p*(upper - lower)) + lower

227 -- Get tuple of an agent with at least m currency

228 index = if (V.head $ V.drop calculated_index x) > 0 then

229 calculated_index

230 else

231 -1

232

233 selectProvidingAgents :: Data -> Int -> Int -> V.Vector Int 234 selectProvidingAgents gd r i = indices

235 where

236 -- Number of agents in the game

237 n = hn gd

238 -- Random real between 0 and 1 for each agent

239 random_reals = V.take n $ V.drop

(29)

241 -- Compose list of selected agents which are going to

provide

,→

242 indices = V.filter (> -1) $

243 V.zipWith3 (\x y z -> if (x/=i && y<z) then x else -1) 244 (V.fromList [0..n-1]) random_reals

245 $ provide_probability_per_agent gd

246

247 selectVolunteeringAgents :: Data -> V.Vector Double -> V.Vector Int

-> V.Vector Int

,→

248 selectVolunteeringAgents gd x v = volunteers

249 where

250 -- Number of agents in the game

251 n = (fromIntegral $ hn gd)

252 -- Types of agents

253 types_list = (types $ population $ game gd)

254 -- Type per agent in V

255 type_per_agent_in_v = V.map (isType gd) v

256 -- Threshold per agent in V

257 threshold_per_agent = V.map

258 (\t -> V.head $ V.drop t $ strategies $ population $ game gd)

259 type_per_agent_in_v

260 -- Currency per agent in V

261 currency_per_agent = V.map (\i -> V.head $ V.drop i x) v

262 -- Tuple containing id, type, currency, threshold,

utility gain/alpha,

,→

263 -- discount rate/delta and utility discount/gamma

264 parameters_per_agent = V.zipWith4 (\i t x k ->

265 (i, t, x, k,

266 (utility_lost $ types_list !! t),

267 (discount_rate $ types_list !! t),

268 (utility_gain $ types_list !! t)

269 ))

270 v type_per_agent_in_v currency_per_agent threshold_per_agent

271 d_zero_per_type = V.toList $ V.map (\(_,_,f) -> f) $ 272 V.filter (\(_,k,_) -> k == 0) $ ds_distribution gd 273 -- Find volunteers that are at threshold

274 volunteers = V.filter (> -1) $

275 V.map (\(i, t, x_i, k, alpha, delta, gamma) ->

276 if (x_i < case (find (\(kappa1, cond) -> cond == True)

$

,→

277 [ (kappa, alpha <=

278 ((1.0 - (1.0 - delta)/n)ˆ

279 (j kappa (p_u gd d_zero_per_type t) (p_d gd t)

0))*gamma) |

,→

280 kappa <- reverse [0..k] ]) of

281 Just (kappa2,True) -> kappa2

282 Nothing -> 0

283 ) then i else -1

284 ) parameters_per_agent

285

286 selectProvidingAgent :: Data -> Int -> V.Vector Int -> Int 287 selectProvidingAgent gd r v = agent

(30)

288 where

289 -- Likelyhood per agent in v

290 likelyhood_per_agent =

291 V.map (\x -> (fromIntegral

292 (volunteer_likelyhood

293 ((types $ population $ game gd) !! (isType gd x)))

294 )::Double) v

295 -- Total likelyhood of agents in v

296 likelyhood_total = V.foldl1 (+) likelyhood_per_agent

297 -- Probability per agent in v

298 probability_per_agent = V.map (/likelyhood_total)

likelyhood_per_agent

,→

299 -- Random real between 0 and 1

300 random_real = V.head $ V.drop r (random_probabilities gd !! 2)

301 -- random_real = (randomDoubles (0,1) 2 (seed gd)) !! r 302 -- Distribution of probabilities

303 distribution = V.scanl1 (+) probability_per_agent

304 -- Index corresponding to real number

305 agent = V.head $ V.drop ((\(Just i) -> i) $

306 V.findIndex (>random_real) $ distribution) v 307

308 transferCurrency :: Data -> V.Vector Double -> Double -> Int -> Int

-> V.Vector Double

,→

309 transferCurrency gd x c i j = V.update x $ V.fromList

310 [(i, (V.head $ V.drop i x)-c), (j, (V.head $ V.drop j x)+c)]

311 where

312 t = types $ population $ game gd

313

314 computeWelfare gd w i j = w + (1 - xi)*(gamma - alpha)

315 where

316 p = population $ game gd

317 alpha = utility_lost $ (types p) !! isType gd i

318 gamma = utility_gain $ (types p) !! isType gd j

319 xi = sum [ ds p (lambda gd) t 0 | t <- [0.. length (types p) - 1]]

320

321 nextRound :: Data -> (Int, Int, V.Vector Double) -> Double ->

(V.Vector Double, Double)

,→

322 nextRound gd (r, p, x) w = nextPhase gd (r, 1, x, -1, V.fromList []) w 323

324 nextPhase :: Data -> (Int, Int, V.Vector Double, Int, V.Vector Int)

-> Double -> (V.Vector Double, Double)

,→

325 nextPhase gd (r, p, x, i, v) w = case p of

326 -- Phase 1 consists of selecting an agent i

327 1 -> nextPhase gd (r, 2, x, selectRequestingAgent gd x r, v) w 328 -- Phase 2 consists of selecting agents V that might provide 329 2 -> if i > -1 then

330 nextPhase gd (r, 3, x, i, (selectProvidingAgents gd r i)) w

331 else

332 (x, w)

333 -- Phase 3 consists of selecting agents ’V than are

volunteering.

,→

(31)

335 nextPhase gd (r, 4, x, i, selectVolunteeringAgents gd x v) w

336 else

337 (x, w)

338 -- Phase 4 consists of selecting agent j that will provide 339 4 -> if (V.length v > 0) then 340 (\j -> (transferCurrency gd x 1 i j, computeWelfare gd w i j)) 341 (selectProvidingAgent gd r v) 342 else 343 (x, w) 344

345 playRounds :: Data -> V.Vector Double -> Int -> Int -> Double ->

(V.Vector Double, Double)

,→ 346 playRounds gd x 1 r w = nextRound gd (r, 1, x) w 347 playRounds gd x n r w = nextRound gd (r, 1, x2) w2 348 where 349 (x2, w2) = playRounds gd x (n-1) (r+1) w 350

351 distance :: Data -> V.Vector Double -> Double 352 distance gd x = V.foldl1 (+) (V.zipWith

353 (\(t1,l1,d) (t2,l2,ds) -> (abs $ d - ds)ˆ2) d $

354 ds_distribution gd) / (fromIntegral $ V.length d)

355 where

356 -- Number of agents in the game

357 n = hn gd

358 -- Currency per type of agent

359 currency_per_type = map (\l -> ((\(u,v) -> (u,v, length l)) $

head l)) $

,→

360 group $ sort $ V.toList $ V.zip (type_per_agent gd) x

361 -- Composing distribution of d using the distribution of

d*

,→

362 d = V.map (\(t1,l1,c1) ->

363 case (find (\(t2,l2,c2) -> t1 == t2 && l1 == l2)

currency_per_type) of

,→

364 -- Computing fraction of agents of type t with

l currency

,→

365 Just (t3,l3,c3) -> (t1,l1, (fromIntegral

c3)/(fromIntegral n))

,→

366 -- No agents are present with l currency 367 Nothing -> (t1,l1,0)

368 ) $ ds_distribution gd

369

370 nu :: Population -> Int -> Double -> Int -> Double

371 nu p n lambda t = b * (f - (ds p lambda t k)) * (fromIntegral n)

372 where

373 -- Fraction of given type 374 f = (V.toList $ fraction p) !! t

375 b = provide_probability $ ((types p) !! t)

376 k = (V.toList (strategies p)) !! t 377

378 p_u :: Data -> [Double] -> Int -> Double 379 p_u gd dz i = p_j*p_i

Referenties

GERELATEERDE DOCUMENTEN

De kunststof dubbeldeks kas (Floridakas, incl. insectengaas) laat bij Ficus, trostomaat, en Kalanchoë een beter netto bedrijfsresultaat zien dan de referentiekas; bij radijs

Wanneer een veehouder de gecomposteerde mest zou terugnemen om aan te wenden op zijn eigen bedrijf en het stikstofconcentraat dat tijdens de intensieve compostering wordt gevormd niet

superciliosus Alopias exigua Alopias latidens Alopias vulpinus Familie Cetorhinidae Cetorhinus maximus Orde Carcharhiniformes Familie Carcharhinidae Galeocerdo aduncus.

, Mondelingse oorlewering tydens 'Sharpeville oral workshop', Vaal Teknorama, Vereeniging, 20.02.1999 {Oud inwoner van Toplokasie, steeds inwoner van Sharpeville,

ii ABSTRACT The focus of this research, PIL 72 Building institutional capacity through staff development was active at the Eastern Cape Technikon ECT, a tertiary institution of

(Ongevallen met zware voertuigen; Tweede Europese Workshop een succes; Jaarver- slag 1987; Studiedagverslag; Harde aanpak rijden onder invloed in regio Leiden;

Met dit model zullen de momenten en krachten in de elementen wordenberekend, waardoor een redelijk betrouwbare schat- ting wordt verkregen van de grootte van de