-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
60 lines (41 loc) · 1.52 KB
/
agent.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
49
50
51
52
53
54
55
56
57
58
59
60
import math, random
import numpy as np
import rythm
import functions
class Agent:
def __init__(self, initial_density):
self.density = initial_density
self.success_communication = 0
self.success_repetition = 0
def learn(self, rythm_list):
""" Learn the rythm list"""
for rythm in rythm_list:
# Get the rythm density, add it to the agent's density
# distribution and then normalize it
for ratio, d in rythm.density():
if ratio not in self.density.keys():
self.density[ratio] = d
else:
self.density[ratio] += d
# NORMALIZE!
def create_rythm(self, dev):
""" Create a rythm. It will use all the rythms it learns combined """
new_rythm = rythm.Rythm()
new_rythm.rythm_from_distr(duration, self.density)
return new_rythm
def repeat_rythm(self, rythm, dev):
""" Try to repeat a rythm with a certain deviation """
return rythm
def create_rational(self, dev, listerner):
""" Create a rythm rationally trying to make the listener like it """
# TO BE IMPLEMENTED
rythm = []
return rythm
def punctuate_rythm(self, rythm):
""" Say how much it has liked it according to what it knows """
# TO BE IMPLEMENTED
return 0.5
def fitness(self):
""" Calculate the fitness of an agent and return it """
# TO BE DECIDED
return 1