-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathensembleMethods.py
More file actions
39 lines (27 loc) · 1.3 KB
/
Copy pathensembleMethods.py
File metadata and controls
39 lines (27 loc) · 1.3 KB
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
import numpy as np
from collections import Counter
from helper import boltzmann
def boltzmannChoice(values, temp):
probabilities = boltzmann(values, temp)
return np.random.choice([0, 1, 2, 3], p=probabilities)
def simpleChoice(values, temp):
transformedValues = np.power(values, 1 / temp)
probabilities = transformedValues / transformedValues.sum()
return np.random.choice([0, 1, 2, 3], p=probabilities)
def majorityVote(algorithms, temp):
bestActions = [algo.getMostProbableAction() for algo in algorithms]
counter = Counter(bestActions)
counts = np.array([counter[action] for action in [0, 1, 2, 3]])
return boltzmannChoice(counts, temp)
def rankVote(algorithms, temp):
allRanks = np.array([algo.getActionRanking() for algo in algorithms])
probabilities = allRanks.sum(axis=0)
return boltzmannChoice(probabilities, temp)
def boltzmannMultVote(algorithms, temp):
actionsProbabilities = np.array([algo.getBoltzmannProbabilities() for algo in algorithms])
prefs = np.prod(actionsProbabilities, axis=0)
return simpleChoice(prefs, temp)
def boltzmannAddVote(algorithms, temp):
actionsProbabilities = np.array([algo.getBoltzmannProbabilities() for algo in algorithms])
prefs = np.sum(actionsProbabilities, axis=0)
return simpleChoice(prefs, temp)