26 lines
648 B
Python
26 lines
648 B
Python
import numpy as np
|
|
import torch
|
|
|
|
|
|
def dev0(a, b):
|
|
a = a.detach().numpy()
|
|
b = b.detach().numpy()
|
|
with np.errstate(divide='ignore', invalid='ignore'):
|
|
c = np.true_divide(a, b)
|
|
c[~ np.isfinite(c)] = 0
|
|
c = torch.from_numpy(c)
|
|
return c
|
|
|
|
|
|
def soft_update(target, source, tau):
|
|
for target_param, param in zip(target.parameters(), source.parameters()):
|
|
target_param.data.copy_(target_param.data * (1.0 - tau) + param.data * tau)
|
|
|
|
|
|
def hard_update(target, source):
|
|
for target_param, param in zip(target.parameters(), source.parameters()):
|
|
target_param.data.copy_(param.data)
|
|
|
|
|
|
class DeepQNetwork:
|