This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (53 loc) · 1.44 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
import random
import numpy as np
import tensorflow
import matplotlib.pyplot as plt
import pandas as pd
class Student:
def __init__(self, choice):
self.choice = choice
self.policy_class = 0
student_list = []
class PolicyClassroom:
def __init__(self, class_num):
self.student = np.zeros(20)
self.class_num = class_num
def add_student(self, choice):
self.student[choice] += 1
def diversity(self):
sum = 0.0
for choice in self.student:
sum += choice
diversity = 0.0
for choice in self.student:
diversity += choice ** 2 / sum ** 2
return diversity * 10000
class LearningClassroom:
def __init__(self):
pass
class QLearning:
def __init__(self):
pass
class1 = PolicyClassroom(1)
diversity_list = []
choice_list = np.zeros(20)
for i in range(1, 40):
# choice = random.randint(1, 20) - 1
choice = random.randint(0, 19)
choice_list[choice] += 1
class1.add_student(choice)
diversity_list.append(class1.diversity())
print(class1.diversity())
plt.subplot(2, 1, 1)
# add a plt for choice diversity
plt.plot(np.linspace(0, 39, 39), diversity_list)
plt.title('Diversity')
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
plt.subplot(2, 1, 2)
plt.pie(choice_list, autopct='%1.1f%%',
shadow=True, startangle=90)
plt.axis('equal')
plt.show()
df = pd.DataFrame(choice_list)
print(df)