• No results found

A prolog implementation of distance-based rules for social network creation

N/A
N/A
Protected

Academic year: 2021

Share "A prolog implementation of distance-based rules for social network creation"

Copied!
19
0
0

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

Hele tekst

(1)

A Prolog implementation of

distance based rules for social

network creation

talhaTheCreator.pl Leila F.C. Talha 10756922 Bachelor thesis Credits: 18 EC

Bachelor Opleiding Kunstmatige Intelligentie University of Amsterdam Faculty of Science Science Park 904 1098 XH Amsterdam Supervisor dr. F.R. Velazquez Quesada

Institute for Logic, Language and Computation Faculty of Research University of Amsterdam Science Park 107 1098 XG Amsterdam Supervisor prof. dr. S.J.L. Smets

Institute for Logic, Language and Computation Faculty of Research

University of Amsterdam Science Park 107 1098 XG Amsterdam

(2)

Contents

1 Introduction 3

2 Definitions 4

2.1 The basic model . . . 4

2.2 Distance measures . . . 4 2.3 Update strategies . . . 5 2.4 Further requirements . . . 6 3 Approach 7 3.1 Python . . . 7 3.2 Prolog . . . 7 4 Implementation details 9 4.1 Completed features . . . 9 4.2 Missing features. . . 9 5 Conclusion 10 5.1 Discussion . . . 10 5.2 Future work . . . 10 References 11

A Pseudocode for updating an EXSNM 12

(3)

Abstract

Within the logic community several studies on social influence have been conducted [Christoff and Hansen, 2015, Zhen and Seligman, 2011, Apt et al.,2016], but the creation and evolution of the underlying structures (i.e., social networks) have only recently received attention [Smets and Vel´azquez-Quesada, 2017, 2018a,b]. The purpose of this bachelor’s the-sis project was to implement the mechanisms proposed by Smets and Vel´azquez, which succeeded partially. Most of the intended features were implemented, realising an increase in both the complexity of the exam-ple models and the speed with which their updates can be analysed. The epistemic versions of the update mechanism are missing in the final imple-mentation, but astep-by-step guidefor future implementation is provided.

1

Introduction

When describing who we are as a person, we will probably mention our hobbies, musical taste and political views or perhaps some other personal preferences along that line. But whatever they may be, most of our personality traits are affected by the presence of others. Notwithstanding the role that genetics might play, Social influence [Turner, 1991] is a strong determinant for who we come to be in our adult lives [Boomsma et al., 1999, Bouchard and Loehlin, 2001, Bouchard and McGue,2003] – all the more so since the rise of the internet and the increasing popularity of online social media.

Social phenomena such as socialisation, conformity, compliance and obedi-ence have been studied not only by empirical sciobedi-ences (e.g., sociology and social psychology), but also by theoretical sciences (e.g., graph and network theory). Within the logic community this is traditionally done by quantitative modelling, but recently also qualitative tools such as dynamic epistemic logic1 have been

deployed in logical studies on social influence [Christoff and Hansen,2015,Zhen and Seligman, 2011, Apt et al., 2016]. However, the creation and evolution of the structures that allow for any of the named phenomena and its subtler forms to occur (i.e., social networks) have received far less attention2 from the logic

community, that is, until recently [Smets and Vel´azquez-Quesada, 2018b]. Smets and Vel´azquez-Quesada have proposed several distance based mecha-nisms for social network creation [Smets and Vel´azquez-Quesada,2017,2018a,b]. The aim of this bachelor’s thesis project is to implement these proposals, prefer-ably supplemented with a graphical representation of both the initial and up-dated network. The hard requirements for the final implementation are:

− Clear and easy to revise code in case of any elaborations or alterations on the current theories.

− Elegant and intuitive code is preferred over highly efficient code. Hard to understand, and therefore hard to update, but efficient code that could theoretically handle more complex models than it practically will, is use-less.

− User friendly (e.g., easy to feed a social network model description to the program and a clear visualisation of the input and output networks). 1Explanation of DEL:

https://homepages.cwi.nl/~jve/papers/13/pdfs/del.pdf 2Some exceptions are [Bringmann et al.,2010], [Leskovec et al.,2008]

(4)

The relevance of the described implementation is threefold. First, as previ-ously mentioned, within the logic community several studies on social influence have been conducted, but studies on the creation of social groups are excep-tional. However, this project builds upon three recently published papers that do focus on the logical structure behind social network creation and provides a common ground between each of them. Second, the intended program helps analysing the in the literature proposed definitions and their consequences in a more systematic way, allows for an increase in both the size and complexity of the social network models and it makes iterative updating easier – which is useful for determining long-term network behaviour. Finally, when combining the former two contributions, the program could prove itself useful in the long run with respect to making predictions or deciding what interventions to make on a realistic scale. With knowledge of how a virus, for instance, spreads across a social network and how that network will change, predictions about future contamination could be made. Or, by simulating specific adjustments in a net-work, it could be decided who should be put in quarantine to prevent the disease from spreading further.

The following sections will expound on the three papers and the mechanisms therein that form the foundation of this project, elucidate the approach taken to implement the provided theories and discuss the program’s results in terms of requirement satisfaction. Then concluding the article, remarks on the final product and suggestions for future work will be made.

2

Definitions

2.1

The basic model

In order to make the reader familiar with the mechanisms proposed by Smets and Vel´azquez, this section will briefly elaborate on the definitions provided in their referenced papers. Starting with the most basic setting, that of an agent representation in terms of binary features (e.g., likes painting: true, likes Tyler the Creator: true and likes Trump: false) and a single social network model. Definition 2.1 (Social network model) Let A denote a finite non-empty set of agents and P a set of features each agent might or might not have. Then a social network model (SNM) is a tuple M = hA, S, V i where S ⊆ A × A is the social relation (Sab indicates that agent a is socially connected to agent b) and

V :→ ℘(P ) is a feature function (p ∈ V (A) indicates that agent a has feature p).

2.2

Distance measures

Having defined an SNM, it must be decided how to assert relations between the agents in that model. The literature at hand has chosen a similarity approach: the more similar two agents are, the more likely it will be that they will get acquainted – other approaches, such as a complementary approach could have been decided on, as some say that opposites attract. In order to determine the similarity between two agents, several distance measures have been proposed throughout the papers.

(5)

Definition 2.2 (Distance) Let M = hA, S, V i be an SNM; define the set of features distinguishing agents a, b ∈ A in M as msmtchM(a, b) := (V (a)\V (b))∪

(V (b) \ V (a)). The function distM

: A × A → N, indicating the distance in M between two agents, is given by:

distM(a, b) := |msmtchM(a, b)|

Definition 2.3 (Q-Distance) Let M = hA, S, V i be an SNM; let Q ⊆ P be a set of features. The Q-distance between a and b in M (that is, the distance between a and b in M relative to features in Q) is given by:

distM(a, b) := |msmtchM(a, b) ∩ Q|

Heretofore an agent was simply represented as a set of binary preference choices regarding the features in P . But a more realistic representation would be one in which an agent’s features are ordered by priority, also allowing for the ordering to differ across agents. Hence, the introduction of the extended social network model.

Definition 2.4 (Extended social network model) An extended SNM (XSNM) is a tuple M = hA, S, {4a}a∈A, V i, where M = hA, S, V i is an SNM and each

4a⊆ (P × P ) is a total preorder on features (p 4a q indicates that, for agent a,

feature p is at most as important as feature q).

Having defined an XSNM, it has become possible to calculate a subjective dis-tance between agents as the weighted sum of the features in which they differ. Definition 2.5 (Subjective distance) let M = hA, S, {4a}a∈A, V i be an XSNM.

For defining a subjective distance between agents, note first how each 4ainduces

an ordered sequence of subsets of P (Pa

0, P1a, ...), each one containing features

that are, from a’s perspective, equally important (Pa

0 contains a’s most

impor-tant features). Moreover P is finite, so only a finite number of such sets (say, ]a) will be non-empty. Then, by using a function assigning weight to features in

each Pa

k (say, weighta(k) := ]a− k, so while the weight of the most important

features –those in Pa

0– is ]a, that of the least important –those in P]aa−1– is 1),

the distance between agents b1 and b2in M according to agent a is given by:

distM a (b1, b2) := ]a−1 P k=0 (|msmtchM(b 1, b2) ∩ Pka| · weighta(k))

2.3

Update strategies

Across the provided papers two strategies for social group creation have been proposed. A threshold update asserts a relation between two agents a and b if they are similar enough (i.e., their mutual distance is smaller than the threshold θ).

Definition 2.6 (Threshold update) Let M = hA, S, V i be an SNM; take θ ∈ N. The threshold-similarity update of M generates the SNM M θ =

hA, S θ, V i, with its social relation given by:

(6)

The drawback of this group creation strategy is that an agent a who is very similar to the rest of the agents in A could end up with more relationships than a could ever maintain. Or on a sadder note, an agent who only just falls by the wayside could end up entirely friendless. Thus, another interesting and quite natural update mechanism would be one that takes the size of an agent’s social space into consideration [Dunbar, 1992]. Because then an agent could keep expanding its social network (even including very dissimilar agents) as long as the maximum group size is not reached, and not stay forever alone.

Definition 2.7 (Group-size update) Let M = hA, S, V i be a SNM; take λ ∈ N. The function dist induces an ordered sequence of subsets of A (Aa−1, Aa0, Aa1, ...),

with all but the first containing agents equally distant from agent a (Aa0contains

the closest ones), and the first an empty set used for technical reasons. More-over, denote by \a(λ) the ’last’ layer of contacts a ∈ A can add to her network

without going above λ. The group-size similarity update of M generates the SNM M./λ = hA, S./λ, V i, with its social relation given by:

S./λ := {(a, b) ∈ A × A : b ∈ ]a(λ) S k=−1 Aa k}

2.4

Further requirements

Now that the strategies to creating and updating a social network are clear, an interesting addition to the mechanisms would be to lay claim on social re-quirements, such as the existence of a middleman, or on epistemic requirements before asserting a social relation to the updated model.

Definition 2.8 (Middleman threshold update) Let M = hA, S, V i be a SNM; take θ ∈ N. The middleman threshold-similarity update of M generates the SNM M bθ= hA, S bθ, V i, with its social relation given by:

S bθ:= {(a, b) ∈ A × A : distM(a, b) ≤ θ, ∃c ∈ A s.t. Sac∧ Scb}

or

S bθ:= {(a, b) ∈ A × A : distM(a, b) ≤ θ, ∃c ∈ A s.t. Sca∧ Scb}

or

S bθ:= {(a, b) ∈ A × A : distM(a, b) ≤ θ, ∃c ∈ A s.t. Sac∧ Sca∧ Sbc∧ Scb},

depending on the preferred type of social requirement between agent a and b. Definition 2.9 (Epistemic social network model) An epistemic social net-work model (ESNM) is a standard multi-agent relational (possible worlds) model [Hintikka, 1962] in which each possible worls w stands for a SNM hA, Sw, Vwi

and the epistemic relations ∼i are equivalence relations.

Definition 2.10 (Knowledge-based threshold update) Let M = hW, A, ∼ , S, V i be an ESNM; take θ ∈ N. The knowledge-based threshold similarity up-date operation generates the ESNM M Kθ = hW, A, ∼, S Kθ , V i, with:

(S K

(7)

3

Approach

Since the crucial concepts for this project have been presented in the previous section, it is time to take a closer look at the approach taken to implement them.

3.1

Python

Let us recall the hard requirements set on the intended final product:

i. Clear and easy to revise code in case of any elaborations or alterations on the current theories.

ii. Elegant and intuitive code is preferred over highly efficient code. Hard to understand, and therefore hard to update, but efficient code that could theoretically handle more complex models than it practically will is useless. iii. User friendly (e.g., easy to feed a social network model description to the

program and a clear visualisation of the input and output networks). Taking into account these conditions, an OOPL3such as Java or Python seems as an unequivocal choice. Code written in either one of these languages is effort-lessly comprhensible to most developers, because both are immensely popular4

(i); also, an object oriented language lends itself for the implementation of both the specific instances of a general concept and that concept itself – as is the case for an SNM, XSNM, ESNM and EXSNM respectively – in just one class (ii) and for both Java and Python there exist packages for reading files and mak-ing graphical user interfaces, which are useful for meetmak-ing the requirement of user friendliness (iii). Because of these reasons and the fact that Python’s syn-tax is less strict than Java’s, making the language less frustrating to beginning developers, the initial implementation was done in Python.

However, the Python implementation deadlocked mostly on the second de-mand of elegant and intuitive code. Intuitively an E(X)SNM should be the par-ent of an (X)SNM. Implempar-enting it as such is, however, impossible as the child classes inherit all methods from the parent class. The features of an E(X)SNM should be the same as those of an (X)SNM with a few more added and not vice versa.

3.2

Prolog

Consequently a new programming language had to be chosen in order to achieve the goals set out for this project. This time the logical programming language Prolog was chosen instead of the functional Python. This decision was made because Prolog also supports dynamic predicates, which can be helpful when trying to implement a DEL.

3OOPL: Object oriented programming language

4Stack Overflow Developer Survey 2018: https://insights.stackoverflow.com/survey/ 2018/#technology-programming-scripting-and-markup-languages

(8)

To keep the Prolog code concise and intuitive, a common ground had to be determined between the variety of formal agent representations presented throughout the literature – an agent being a single entity calls for a single, comprehensive representation rather than a switch between several context de-pendent representations. To that end agents were anthropomorhphised: con-sidering agents as actual human beings has led to a single agent representation that stores all information necessary for the application of each of the update mechanisms, but is only used accordingly – much like humans who prefer a close circle of actual friends (i.e., a threshold update with a small θ) but will add as much virtual friends as Facebook permits (i.e., a group-size update with a large λ). This way of representing an agent has multiple advantages:

− Only one type of agent facts will have to be stored. Making the code more general.

− It is possible to use (more realistic) agent specific parameters instead of merely model specific parameters, as per the literature at hand. If model specific parameters are desired, simply apply the same parameters to each agent.

− It allows for a mapping between a set of feature atoms and a set of weighted features, making it possible to not only implement the suggested distance measures, but others too. Also, this representation makes it easy to update the code in such a way that the distance can easily be measured with respect to logical expressions instead of merely atoms, as is currently the case.

Likewise, both predicates for calculating thedistance between two agentsand for finding out if a certainmiddlemanrequirement is met, have been implemented in a more general manner than defined in the previous section. Instead of implementing separate predicates for calculating a regular distance and a Q-distance, only the latter is included in the code as its definition contains the former for Q = P . The requirements that can be laid down on the coming about of a social relationship between two agents, have also been generalised in the sense that not merely one middleman can justify a relation, but also the more general case of middlemen[Smets and Vel´azquez-Quesada,2018b], as illustrated in Figure1.

(a) Themiddlemancases as defined (b) The general middlemen cases

Figure 1: The middleman cases as defined (1a) and their generalisations (1b). All other concepts were implemented as similar as possible to their formal defini-tions and will either be discussed in the next section or can be found in appendix talhaTheCreator.pl.

(9)

4

Implementation details

Following is a more in-depth illustration of the project’s final implementation. First it will be established which concepts have been realised successfully, then proceeding with an elaboration on relevant but missing features.

4.1

Completed features

As most concepts have been implemented as intended, a speed-up in updating (extended) social network models with respect to manual updating has been achieved. Moreover, the program is able to handle more complex models and distance calculations than a human comfortably could (e.g., models containing more than ten agents and the calculation of a subjective distance with respect to more than twenty features).

The demand of elegant and intuitive code over efficient code has also strongly been warranted, as supported by the switch from Python to Prolog and the inherently inefficient reassigning of values to clearer variable names, for example: the base case get group ([], , Acc, Acc). is more efficient but less clear than the actually implemented get group ([], , Acc, Group) :− Group = Acc. .

Globally thecodeis clear-cut and easy to update. The program keeps on the names and symbols from the literature as much as possible, probably making it more comprehensible to other developers when they simultaneously compare it against the papers it was based on. This feature, combined with the facts that the code is constructed such that future update predicates can be passed as a parameter to the general predicate for updating, and that more sophisticated set operations have been implemented (e.g., there now exists a predicate that re-turns the symmetric difference between two sets and a predicate intersection /2 that returns the intersection between a list of sets instead of merely between two sets, as the built-in predicate intersection /3 does), contributes to the ease with which others can revise the current implementation.

4.2

Missing features

The overall user friendliness of the final product does not live up to the project’s intentions. Currently a social network model has to be entered in the program manually, but a feature that reads in a file with a model description would be more convenient. Also, even though the initial implementation was done in Python partly because of its packages for GUI5 building, code for an actual

graphical representation of the initial and updated network is missing. The knowledge based versions of the update mechanisms are likewise lacking, but an implementation description is provided in appendixPseudocode for updating an EXSM.

The next section will conclude this article in terms of several remarks on the current implementation and suggestions for future work.

(10)

5

Conclusion

Summarising the above content: this project succeeded partially. Most of the intended features were implemented in a straightforward and intuitive manner, realising an increase in both the complexity of the example models and the speed with which their updates can be analysed. Moreover, the final product is especially designed to ease further development. The code’s user friendliness, however, leaves quite some room for improvement. Besides, the knowledge based versions of the update mechanisms are missing in the current implementation, but pseudocodefor a future implementation is provided.

5.1

Discussion

The referenced pseudocode merely handles a de dicto6 approach for the

epis-temic update of a social network model, yet the literature also proposes a de re6 approach. These two approaches do result in different updated models for

the same input model, therefore a realisation of a de re approach to updating an EXSNM is also desirable.

Additionally, in the enclosed pseudocode the epistemic burden for a mid-dleman update lies with the updating agent, but shifting this burden to the middleman has been proposed too [Smets and Vel´azquez-Quesada, 2017]. A notion of how this could be implemented is therefore also worthwhile.

Whilst repeating Smets and Velazquez definitions, it was discovered that the current code for calculating a subjective distance between two agents a and b slightly deviates from its formal definition. Currently the distance is measured objectively between the subjectively weighted features (i.e., feature priorities differ across agents) of a and b, but it should be measured subjectively according to a third agent c. However, this faulty implementation can easily be corrected by passing agent c’s feature weights to the current predicate and by multiplying them accordingly with the return value of symmetric difference/4, with the feature atoms of both a and b as input.

5.2

Future work

As stated earlier, the user friendliness of the final program leaves much to be desired. Besides a feature that reads in a text file with a social network model description and then translates it to the dictated Prolog representation, a graph-ical representation of both the initial network and updated network would also be nice to add.

To that end, the output of the Prolog code at hand could be written to a Python or Java script for constructing a GUI consisting of merely two classes, since only a visual distinction between agents and networks (regardless of whether it is an SNM, XSNM, ESNM or EXSNM) is necessary. Another, maybe bet-ter, possibility is to plug the current program’s output into an existing network drawer such as the Modal Logic Playground7

Finally, implementing the option of complex features (meaning logical ex-pressions) as proposed in [Smets and Vel´azquez-Quesada,2018b] seems a viable, yet interesting challenge.

6Explanation of de dicto and de re:http://maloni.humanities.uva.nl/tesi/belief.pdf 7The Modal Logic Playground: https://rkirsling.github.io/modallogic/

(11)

References

Krzysztof R Apt, Davide Grossi, and Wiebe van der Hoek. Epistemic protocols for distributed gossiping. arXiv preprint arXiv:1606.07516, 2016.

Dorret I Boomsma, Eco JC De Geus, G Caroline M Van Baal, and Judith R Koopmans. A religious upbringing reduces the influence of genetic factors on disinhibition: evidence for interaction between genotype and environment on personality. Twin Research and Human Genetics, 2(2):115–125, 1999. Thomas J Bouchard and John C Loehlin. Genes, evolution, and personality.

Behavior genetics, 31(3):243–273, 2001.

Thomas J Bouchard and Matt McGue. Genetic and environmental influences on human psychological differences. Developmental Neurobiology, 54(1):4–45, 2003.

Bj¨orn Bringmann, Michele Berlingerio, Francesco Bonchi, and Arisitdes Gionis. Learning and predicting the evolution of social networks. IEEE Intelligent Systems, 25(4):26–35, 2010.

Zo´e Christoff and Jens Ulrik Hansen. A logic for diffusion in social networks. Journal of Applied Logic, 13(1):48–77, 2015.

Robin IM Dunbar. Neocortex size as a constraint on group size in primates. Journal of human evolution, 22(6):469–493, 1992.

Jaakko Hintikka. Knowledge and belief: An introduction to the logic of the Two Notions. Cornell University Press, Ithaca, N.Y., 1962. ISBN 1-904987-08-7. Jure Leskovec, Lars Backstrom, Ravi Kumar, and Andrew Tomkins.

Micro-scopic evolution of social networks. In Proceedings of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining, pages 462– 470. ACM, 2008.

Sonja I.L. Smets and Fernando R. Vel´azquez-Quesada. How to make friends: A logical approach to social group creation. pages 377–390, 2017.

Sonja I.L. Smets and Fernando R. Vel´azquez-Quesada. The creation and change of social networks: A logical study based on group size. pages 171–184, 2018a. Sonja I.L. Smets and Fernando R. Vel´azquez-Quesada. A logical perspective on

social group creation. 2018b.

John C Turner. Social influence. Thomson Brooks/Cole Publishing Co, 1991. Liang Zhen and Jeremy Seligman. A logical model of the dynamics of peer

pressure. Electronic Notes in Theoretical Computer Science, 278:275–288, 2011.

(12)

A

Pseudocode for updating an EXSNM

Given M = hW, A, ∼, S, V, i

∀a ∈ A :

− Get all worlds accessible by agent a, P Wa.

P Wa:= {w ∈ W, access(a, w)}

− Update P Wa according to a’s parameters and the selected update

mech-anism (i.e.,threshold updateorgroup-size update), obtaining

Ma= hWa, A, ∼, Sa, V i.

Then again, ∀a ∈ A : ∀wa∈ Wa :

∀b ∈ A, b 6= a :

− findall wa, wb s.t. (Sa)wa= (Sb)wb.

− merge each equivalent wa and wb into one world v.

− provide access to merged v to both a and b. − replace wa and wb with v.

Then, if desired, uniquely change each world’s name to a convenient title for clarity.

(13)

B

talhaTheCreator.pl

:− u s e m o d u l e ( l i b r a r y ( l i s t s ) ) . :− dynamic ( r e l a t i o n / 3 ) . % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−−−−−−MODEL DESCRIPTION−−−−−−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % A l l p o s s i b l e w o r l d s c o n t a i n e d i n exsnm M. w o r l d ( v ) . w o r l d (w ) . % Complete f e a t u r e s e t P . f e a t u r e s ( [ p , q , r , s , t ] ) . % R e l e v a n t f e a t u r e s e t Q, w h i c h i s a s u b s e t o f P . r e l f e a t u r e s ( [ p , q , r , s , t ] ) . % R e p r e s e n t a t i o n o f an a g e n t : % a g e n t ( name , t h e t a , lambda , f e a t u r e w e i g h t s , c u r r e n t w o r l d ) a g e n t ( a l i c e , 1 , 1 0 0 , [ 1 , 1 , 0 , 0 , 0 ] , v ) . a g e n t ( bob , 1 , 1 0 0 , [ 1 , 0 , 0 , 0 , 0 ] , v ) . a g e n t ( c h a r l e s , 1 , 1 0 0 , [ 0 , 1 , 0 , 0 , 0 ] , v ) . a g e n t ( a l i c e , 1 , 1 0 0 , [ 1 , 1 , 0 , 0 , 0 ] , w ) . a g e n t ( bob , 1 , 1 0 0 , [ 1 , 0 , 0 , 0 , 0 ] , w ) . a g e n t ( c h a r l e s , 1 , 1 0 0 , [ 0 , 1 , 1 , 0 , 0 ] , w ) . % S o c i a l r e l a t i o n o f an a g e n t : % S (w) ab ==> r e l a t i o n ( a , b , w ) . % A c c e s s a b i l i t y r e l a t i o n o f an a g e n t : % v ˜ ( a ) w => a c c e s s ( v , a , w ) . a c c e s s ( a l i c e , v ) . a c c e s s ( a l i c e , w ) . % c l e a r d b /0 r e t r a c t s a l l f a c t s a s s e r t e d d u r i n g run−t i m e . c l e a r d b :− r e t r a c t a l l ( r e l a t i o n ( , , ) ) , r e t r a c t a l l ( exsnm ( , ) ) . % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−FUNCTIONS, MAPPINGS & RESTRICTIONS−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % get W /1 c o l l e c t s a l l p o s s i b l e w o r l d s i n t h e c u r r e n t model i n a l i s t .

get W (W): −

(14)

% g e t A /1 c o l l e c t s a l l a g e n t s i n t h e c u r r e n t model i n a l i s t . g e t A (A) :−

w o r l d ( World ) ,

f i n d a l l ( Agent , a g e n t ( Agent , , , , World ) , A ) , ! .

% r e p e a t /3 r e p e a t s L , t h e i n p u t l i s t , N t i m e s and r e t u r n s l i s t LN = L∗N. % i s u s e d i n t h e u p d a t e p r e d i c a t e s t o s i m u l a t e A A t r h o u g h r e c u r s i o n . repeat ( L , 1 , L ) . repeat ( L , N, LN) :− N2 i s N−1 , repeat ( L , N2 , R) , f l a t t e n ( [ L | R ] , LN ) . % g e t d i s t a n c e /6 r e t u r n s t h e d i s t a n c e b e t w e e n two a g e n t s a and b i n % w o r l d w , r e l a t i v e t o a r e l e v a n c e f e a t u r e s u b s e t Q and a c c o r d i n g t o % t h e d i s t a n c e measure p r o v i d e d a s t h e f i f t h p a r a m e t e r .

g e t d i s t a n c e ( Agent a , Agent b , Q, World , msmtch , D i s t a n c e ) :− d i s t a n c e m s m t c h ( Agent a , Agent b , Q, World , D i s t a n c e ) . g e t d i s t a n c e ( Agent a , Agent b , Q, World , e u c l i d e a n , D i s t a n c e ) :−

f e a t u r e s (P ) ,

f e a t s t o i n d i c e s (Q, P , I ) ,

d i s t a n c e e u c l i d e a n ( Agent a , Agent b , I , World , D i s t a n c e ) . % f e a t s t o i n d i c e s /3 r e t r i e v e s t h e i n d i c e s i n f e a t u r e s e t P o f t h e % r e l e v a n t f e a t u r e s u b s e t Q, n e c e s s a r y t o s e l e c t t h e ( r e l e v a n t ) w e i g h t s % t h a t w i l l b e u s e d f o r c a l c u l a t i o n i n d i s t a n c e e u c l i d e a n / 5 . f e a t s t o i n d i c e s ( [ ] , , [ ] ) . f e a t s t o i n d i c e s ( [QH|QT] , P , [ IH | IT ] ) :− nth0 ( IH , P , QH) , f e a t s t o i n d i c e s (QT, P , IT ) . % d i s t a n c e m s m t c h /5 r e t u r n s t h e d i s t a n c e b e t w e e n two a g e n t s a and b % a s t h e number o f mismatches b e t w e e n t h e i r f e a t u r e s e t s .

d i s t a n c e m s m t c h ( Agent a , Agent b , Q, World , M) :− g e t v a l u a t i o n ( Agent a , World , F e a t u r e s a ) , g e t v a l u a t i o n ( Agent b , World , F e a t u r e s b ) , s y m m e t r i c d i f f e r e n c e ( F e a t u r e s a , F e a t u r e s b , Q, SD ) , length (SD , M) . % g e t v a l u a t i o n /3 r e t u r n s , g i v e n an a g e n t a and w o r l d w , % t h e v a l u a t i o n V( a )w o f t h a t a g e n t i n t h e s p e c i f i e d w o r l d . g e t v a l u a t i o n ( Agent , World , V) :−

a g e n t ( Agent , , , Weights , World ) , f e a t u r e s (P ) ,

(15)

% w e i g h t s t o f e a t s /3 c o n v e r t s a f e a t u r e −w e i g h t v e c t o r t o % a l i s t o f a c t u a l f e a t u r e −atoms , n e c e s s a r y f o r g e t v a l u a t i o n / 3 : % [ 1 , 1 , 0 , 1 , 0 ] => [ p , q , s ] , w i t h P = [ p , q , r , s , t ] w e i g h t s t o f e a t s ( [ ] , [ ] , [ ] ) . w e i g h t s t o f e a t s ( [WH|WT] , [ PH| PT ] , [ PH| F ] ) :− WH \= 0 , w e i g h t s t o f e a t s (WT, PT, F ) . w e i g h t s t o f e a t s ( [WH|WT] , [ |PT] , F) :− WH == 0 , w e i g h t s t o f e a t s (WT, PT, F ) . % s y m m e t i c d i f f e r e n c e /4 r e t u r n s t h e s y m m e t r i c d i f f e r e n c e b e t w e e n % two s e t s S1 and S2 r e l a t i v e t o a r e l e v a n c e s e t Q. s y m m e t r i c d i f f e r e n c e ( S1 , S2 , Q, SD): − s u b t r a c t ( S1 , S2 , D12 ) , s u b t r a c t ( S2 , S1 , D21 ) , u n i o n ( D12 , D21 , D) , i n t e r s e c t i o n (D, Q, SD ) . % d i s t a n c e e u c l i d e a n /5 r e t u r n s t h e d i s t a n c e b e t w e e n two a g e n t s % a and b a s t h e e u c l i d e a n d i s t a n c e b e t w e e n t h e i r f e a t u r e −w e i g h t % v e c t o r s , by t a k i n g t h e s q u a r e r o o t from e u c l i d e a n a c c / 3 ’ s % r e t u r n v a l u e .

d i s t a n c e e u c l i d e a n ( Agent a , Agent b , I , World , E) :− a g e n t ( Agent a , , , Weights a , World ) ,

a g e n t ( Agent b , , , Weights b , World ) ,

i n d i c e s t o w e i g h t s ( I , Weights a , QWeights a ) , i n d i c e s t o w e i g h t s ( I , Weights b , QWeights b ) , e u c l i d e a n a c c ( QWeights a , QWeights b , Acc ) , E i s s q r t ( Acc ) . % i n d i c e s t o w e i g h t s /3 s e l e c t s t h e w e i g h t s from a f e a t u r e −w e i g h t % v e c t o r , a t t h e i n d i c e s p r o v i d e d ( by f e a t s t o i n d i c e s / 3 ) . i n d i c e s t o w e i g h t s ( [ ] , , [ ] ) . i n d i c e s t o w e i g h t s ( [ IH | IT ] , Weights , [QH|QT] ) :− nth0 ( IH , Weights , QH) , i n d i c e s t o w e i g h t s ( IT , Weights , QT) . % e u c l i d e a n a c c /3 a c c u m u l a t e s t h e sum o f ( x i −y i ) ˆ 2 , % f o r i i n r a n g e 0 t o n , w i t h n = #f e a t u r e s i n f e a t u r e s e t P . e u c l i d e a n a c c ( [ ] , [ ] , 0 ) . e u c l i d e a n a c c ( [XH|XT] , [YH|YT] , Acc ) :− e u c l i d e a n a c c (XT, YT, Cumsum ) , Acc i s Cumsum + (XH−YH) ∗ (XH−YH) .

(16)

% a g e n t a and b t h a t s a t i s f i e s t h e s e l e c t e d c o n d i t o n a s 4 t h p a r a m e t e r . middleman ( , , , 0 ) . % no middleman r e s t r i c t i o n

middleman ( Agent a , Agent b , World , 1 ) :−

middleman I ( Agent a , Agent b , World , [ ] ) . middleman ( Agent a , Agent b , World , 2 ) :−

m i d d l e m a n I I ( Agent a , Agent b , World ) . middleman ( Agent a , Agent b , World , 3 ) :−

m i d d l e m a n I I I ( Agent a , Agent b , World , [ ] ) .

% m i d d l e m a n I /3 c h e c k s i f , i n w o r l d w , t h e r e e x i s t s a middleman b e t w e e n % a g e n t a and b t h a t s a t i s f i e s t h e g e n e r a l i s a t i o n o f ’ S (w) ca ˆ S (w) c b ’ .

middleman I ( Agent a , Agent b , World , ) :− r e l a t i o n ( Agent a , Agent c , World ) , r e l a t i o n ( Agent c , Agent b , World ) .

middleman I ( Agent a , Agent b , World , E x p l o r e d ) :− r e l a t i o n ( Agent a , Agent c , World ) ,

\+member ( Agent c , E x p l o r e d ) ,

middleman I ( Agent c , Agent b , World , [ A g e n t c | E x p l o r e d ] ) .

% m i d d l e m a n I I /3 c h e c k s i f , i n w o r l d w , t h e r e e x i s t s a middleman b e t w e e n % a g e n t a and b t h a t s a t i s f i e s t h e g e n e r a l i s a t i o n o f ’ S (w) ac ˆ S (w) c b ’ .

m i d d l e m a n I I ( Agent a , Agent b , World ) :− r e l a t i o n ( Agent c , Agent a , World ) , r e l a t i o n ( Agent c , Agent b , World ) . m i d d l e m a n I I ( Agent a , Agent b , World ) :−

r e l a t i o n ( Agent c1 , Agent a , World ) , r e l a t i o n ( Agent c2 , Agent b , World ) ,

m i d d l e m a n I I I ( Agent c1 , Agent c2 , World , [ ] ) .

% m i d d l e m a n I I I /3 c h e c k s i f , i n w o r l d w , t h e r e e x i s t s a middleman % b e t w e e n a g e n t a and b t h a t s a t i s f i e s t h e g e n e r a l i s a t i o n o f % ’ S (w) ac ˆ S (w) ca ˆ S (w) c b ˆ S (w) b c ’ .

m i d d l e m a n I I I ( Agent a , Agent b , World , ) :− r e l a t i o n ( Agent a , Agent c , World ) , r e l a t i o n ( Agent c , Agent a , World ) , r e l a t i o n ( Agent c , Agent b , World ) , r e l a t i o n ( Agent b , Agent c , World ) .

m i d d l e m a n I I I ( Agent a , Agent b , World , E x p l o r e d ) :− r e l a t i o n ( Agent a , Agent c , World ) ,

\+member ( Agent c , E x p l o r e d ) ,

r e l a t i o n ( Agent c , Agent a , World ) ,

m i d d l e m a n I I I ( Agent c , Agent b , World , [ A g e n t c | E x p l o r e d ] ) . % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

(17)

% −−−−−−−−−−−−−−−−−−−−−CODE FOR SIMILARITY UPDATE−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % s i m i l a r i t y u p d a t e /5 p e r f o r m s t h e ( k n o w l e d g e b a s e d ) % s i m i l a r i t y u p d a t e on t h e model , r e l a t i v e t o a r e l e v a n c e f e a t u r e s e t Q % and i n a c c o r d a n c e w i t h t h e s e l e c t e d middleman c o n d i t i o n . s i m i l a r i t y u p d a t e ( [ ] , , , , ) . s i m i l a r i t y u p d a t e ( [WH|WT] , A, Q, Measure , Middleman ) :− length (A,N) ,

repeat (A, N, AxA) ,

u p d a t e r e l a t i o n s s (AxA, WH, Q, Measure , Middleman ) , s i m i l a r i t y u p d a t e (WT, A, Q, Measure , Middleman ) .

% u p d a t e r e l a t i o n s s /5 u p d a t e s t h e r e l a t i o n s b e t w e e n t h e a g e n t s i n t h e % s e l e c t e d w o r l d o f t h e c u r r e n t model , i n a c c o r d a n c e w i t h t h e s e l e c t e d % d i s t a n c e measure and middleman c o n d i t i o n .

%

% ORDER IS IMPORTANT HERE, DO NOT CHANGE! u p d a t e r e l a t i o n s s ( [ ] , , , , ) .

% R e l a t i o n e x i s t s , b u t c o n f l i c t s w i t h mechanism : r e t r a c t r e l a t i o n . u p d a t e r e l a t i o n s s ( [AH|AT] , World , Q, Measure , ) :−

Agent a = AH,

a g e n t ( Agent a , Theta a , , , World ) , a g e n t ( Agent b , , , , World ) ,

r e l a t i o n ( Agent a , Agent b , World ) ,

g e t d i s t a n c e ( Agent a , Agent b , Q, World , Measure , D i s t a n c e ) , D i s t a n c e > Theta a ,

r e t r a c t ( r e l a t i o n ( Agent a , Agent b , World ) ) , u p d a t e r e l a t i o n s s (AT, World , Q, Measure , ) . % R e l a t i o n d o e s n o t y e t e x i s t , b u t s h o u l d : a s s e r t r e l a t i o n

u p d a t e r e l a t i o n s s ( [AH|AT] , World , Q, Measure , Middleman ) :− Agent a = AH,

a g e n t ( Agent a , Theta a , , , World ) , a g e n t ( Agent b , , , , World ) ,

\+ r e l a t i o n ( Agent a , Agent b , World ) ,

middleman ( Agent a , Agent b , World , Middleman ) ,

g e t d i s t a n c e ( Agent a , Agent b , Q, World , Measure , D i s t a n c e ) , D i s t a n c e =< Theta a ,

a s s e r t z ( r e l a t i o n ( Agent a , Agent b , World ) ) ,

u p d a t e r e l a t i o n s s (AT, World , Q, Measure , Middleman ) . % R e l a t i o n e x i s t s i n a c c o r d a n c e w i t h mechanism : do n o t h i n g

u p d a t e r e l a t i o n s s ( [AH|AT] , World , Q, Measure , Middleman ) :− Agent a = AH,

a g e n t ( Agent a , Theta a , , , World ) , a g e n t ( Agent b , , , , World ) ,

(18)

middleman ( Agent a , Agent b , World , Middleman ) ,

g e t d i s t a n c e ( Agent a , Agent b , Q, World , Measure , D i s t a n c e ) , D i s t a n c e =< Theta a ,

u p d a t e r e l a t i o n s s (AT, World , Q, Measure , Middleman ) .

% −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−CODE FOR GROUP SIZE UPDATE−−−−−−−−−−−−−−−−−−−−−−−− % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− % b o u n d e d s i m i l a r i t y u p d a t e /5 p e r f o r m s t h e ( k n o w l e d g e b a s e d ) bounded % s i m i l a r i t y u p d a t e on t h e model , r e l a t i v e t o a r e l e v a n c e f e a t u r e s e t Q % and i n a c c o r d a n c e w i t h t h e s e l e c t e d middleman c o n d i t i o n . b o u n d e d s i m i l a r i t y u p d a t e ( [ ] , , , , ) . b o u n d e d s i m i l a r i t y u p d a t e ( [WH|WT] , A, Q, Measure , Middleman ) :− u p d a t e r e l a t i o n s b (A, WH, Q, Measure , Middleman ) ,

b o u n d e d s i m i l a r i t y u p d a t e (WT, A, Q, Measure , Middleman ) .

% u p d a t e r e l a t i o n s b /5 u p d a t e s t h e r e l a t i o n s b e t w e e n t h e a g e n t s i n t h e % s e l e c t e d w o r l d o f t h e c u r r e n t model , i n a c c o r d a n c e w i t h t h e s e l e c t e d % d i s t a n c e measure and middleman c o n d i t i o n , b u t bounded by lambda .

u p d a t e r e l a t i o n s b ( [ ] , , , , ) .

u p d a t e r e l a t i o n s b ( [AH|AT] , World , Q, Measure , Middleman ) :− Agent a = AH,

a g e n t ( Agent a , , Lambda , , World ) ,

g e t l a y e r s ( Agent a , World , Q, Measure , Middleman , L a y e r s ) , g e t g r o u p ( L a y e r s , Lambda , Group ) ,

c h e c k r e l a t i o n s ( Agent a , Group , World , T o A s s e r t , T o R e t r a c t ) , a s s e r t r e l a t i o n s ( Agent a , T o A s s e r t , World ) ,

r e t r a c t r e l a t i o n s ( Agent a , T o R e t r a c t , World ) ,

u p d a t e r e l a t i o n s b (AT, World , Q, Measure , Middleman ) .

% g e t l a y e r s /6 r e t r i e v e s a g e n t a ’ s d i s t a n c e l a y e r s : n e s t e d l i s t , where % e a c h i n n e r l i s t s t o r e s a g e n t s t h a t a r e e q u a l l y d i s t a n t from a , i n c l a . % The n e s t e d l i s t s a r e o r d e r e d on a s c e n d i g d i s t a n c e , w i t h an empty l i s t % a s head ( r e p r e s e n t s Aa( − 1 ) ) .

g e t l a y e r s ( Agent a , World , Q, Measure , Middleman , [ [ ] | L a y e r s ] ) :− Goal = ( a g e n t ( Agent b , , , , World ) ,

middleman ( Agent a , Agent b , World , Middleman ) ,

g e t d i s t a n c e ( Agent a , Agent b , Q, World , Measure , D) ) , f i n d a l l ( Layer , g r o u p b y (D, Agent b , Goal , Layer ) , L a y e r s ) . % g e t g r o u p /3 c o m b i n e s t h e o u t p u t o f g e t l a y e r s /6 w i t h t h a t a g e n t ’ s % maximum g r o u p s i z e i n o r d e r t o r e t r i e v e i t s s o c i a l g r o u p .

g e t g r o u p ( L a y e r s , Lambda , Group ) :−

g e t g r o u p ( L a y e r s , Lambda , [ ] , Group ) .

(19)

% s t o r e d i n t h e , i n i t i a l l y empty , a c c u m u l a t o r Acc . g e t g r o u p ( [ LH | LT ] , Lambda , Acc , Group ) :−

length (LH,N) , Lambda−N >= 0 ,

Lambda new i s Lambda−N, append ( Acc , LH, Acc new ) ,

g e t g r o u p (LT, Lambda new , Acc new , Group ) . g e t g r o u p ( [ LH | ] , Lambda , Acc , Group ) :−

length (LH,N) , Lambda−N < 0 , Group = Acc . g e t g r o u p ( [ ] , , Acc , Group ) :− Group = Acc . % c h e c k r e l a t i o n s /5 t e s t ’ s what ( c u r r e n t ) r e l a t i o n s s h o u l d b e r e t r a c t e d % and a s s e r t e d a c c o r d i n g t o t h e a g e n t ’ s g r o u p o b t a i n e d by g e t g r o u p / 3 .

c h e c k r e l a t i o n s ( Agent a , Group , World , T o A s s e r t , T o R e t r a c t ) :−

f i n d a l l ( Agent b , r e l a t i o n ( Agent a , Agent b , World ) , R e l a t i o n s ) , s u b t r a c t ( Group , R e l a t i o n s , T o A s s e r t ) , s u b t r a c t ( R e l a t i o n s , Group , T o R e t r a c t ) . % a s s e r t r e l a t i o n s /3 r e c u r s i v e l y a s s e r t s t h e r e l a t i o n s b e t w e e n t h e % s p e c i f i e d a g e n t a s f i r s t p a r a m a t e r and a l i s t o f a g e n t s a s s e c o n d % parameter , i n t h e w o r l d s p e c i f i e d a s t h i r d p a r a m e t e r a s s e r t r e l a t i o n s ( , [ ] , ) .

a s s e r t r e l a t i o n s ( Agent a , [TAH|TAT] , World ) :− Agent b = TAH,

a s s e r t ( r e l a t i o n ( Agent a , Agent b , World ) ) , a s s e r t r e l a t i o n s ( Agent a , TAT, World ) .

% r e t r a c t r e l a t i o n s /3 r e c u r s i v e l y r e t r a c t s t h e r e l a t i o n s b e t w e e n t h e % s p e c i f i e d a g e n t a s f i r s t p a r a m a t e r and a l i s t o f a g e n t s a s s e c o n d % parameter , i n t h e w o r l d s p e c i f i e d a s t h i r d p a r a m e t e r . r e t r a c t r e l a t i o n s ( , [ ] , ) . r e t r a c t r e l a t i o n s ( Agent a , [TRH|TRT] , World ) :− Agent b = TRH,

r e t r a c t ( r e l a t i o n ( Agent a , Agent b , World ) ) , r e t r a c t r e l a t i o n s ( Agent a , TRT, World ) .

Referenties

GERELATEERDE DOCUMENTEN

To test whether the different circumstances affect the acceptability of snitching, repeated measures ANOVA’s were conducted with the general opinion on snitching (the baseline)

[r]

Universiteit Utrecht Mathematisch Instituut 3584 CD Utrecht. Measure and Integration

The prior international experience from a CEO could be useful in the decision making of an overseas M&amp;A since the upper echelons theory suggest that CEOs make

According to the author of this thesis there seems to be a relationship between the DCF and Multiples in that the DCF also uses a “multiple” when calculating the value of a firm.

They rejected independence for Bophuthatswana because they maintained that the area of land allocated to the Tswana people in terms of the South African Black Trust and Land

• You must not create a unit name that coincides with a prefix of existing (built-in or created) units or any keywords that could be used in calc expressions (such as plus, fil,

Note that as we continue processing, these macros will change from time to time (i.e. changing \mfx@build@skip to actually doing something once we find a note, rather than gobbling