-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactors.py
48 lines (35 loc) · 1.46 KB
/
actors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import random as r
from utils.Identifers import Identifier
class Actor:
def __init__(self, interests):
self._id = Identifier.get_id("Actor")
self._interests = np.array(interests)
self._social_norm = np.array(interests)
self._social_integrity = 0.0
self._social_desirability = False
def magnitude(self):
return np.linalg.norm(self._interests)
def interests(self):
if not self._social_desirability:
result = self._interests
else:
result = np.array([x if r.random() <= self._social_integrity else y
for x, y in zip(self._interests, self._social_norm)])
return result
def orientation_of_action(self, other):
a, b = self.interests(), other.interests()
return np.dot(a, 0.5 * (a + b))
def orientation(self, other):
a, b = self.interests(), other.interests()
_a, _b = self.magnitude(), other.magnitude()
return np.dot(a, b) / (_a * _b)
def obeys_social_pressure(self):
return self._social_desirability
def set_social_desirability(self, p, d, norm):
self._social_norm = np.array(norm)
self._social_integrity = (p - d) + r.random()*2*d
self._social_integrity = 1.0 if self._social_integrity >= 1.0 else self._social_desirability
self._social_desirability = True
def __str__(self):
return "Actor : {}".format(self.interests())