質問編集履歴
2
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,6 +9,20 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
```ここに言語を入力
|
12
|
+
class Actor:
|
13
|
+
def get_action(self, state, episode, targetQN): # [C]t+1での行動を返す
|
14
|
+
# 徐々に最適行動のみをとる、ε-greedy法
|
15
|
+
epsilon = 0.001 + 0.9 / (1.0 + episode)
|
16
|
+
|
17
|
+
if epsilon <= np.random.uniform(0, 1):
|
18
|
+
retTargetQs = targetQN.forward(state)[0]
|
19
|
+
action = np.argmax(retTargetQs) # 最大の報酬を返す行動を選択する
|
20
|
+
|
21
|
+
else:
|
22
|
+
action = np.random.choice([0, 1]) # ランダムに行動する
|
23
|
+
|
24
|
+
return action
|
25
|
+
|
12
26
|
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
13
27
|
mainQN = Network().to(device)
|
14
28
|
optimizer = optim.Adam(mainQN.parameters(), lr=learning_rate)
|