diff --git a/test.py b/test.py index 152b133..9c562a1 100644 --- a/test.py +++ b/test.py @@ -133,7 +133,7 @@ class Perlin_Noise(): class Perlin_PCA_Noise(): - def __init__(self, dim_a=2, kernel_func='SE_1.41_1', window=64, ssf=-1, f_sigma=1): + def __init__(self, dim_a=2, kernel_func='SE_1.41_1.0', window=128, ssf=-1, f_sigma=1): self.dim_a = dim_a self.kernel_func = kernel_func self.window = window @@ -162,7 +162,7 @@ class Perlin_PCA_Noise(): class PCA_Noise(): - def __init__(self, dim_a=2, kernel_func='SE_1.41_1', window=64, ssf=-1, f_sigma=1): + def __init__(self, dim_a=2, kernel_func='SE_1.41_1.0', window=128, ssf=-1, f_sigma=1): self.dim_a = dim_a self.kernel_func = kernel_func self.window = window @@ -187,6 +187,35 @@ class PCA_Noise(): self.traj = [[0]*self.dim_a] +class Human_PCA_Noise(): + def __init__(self, dim_a=2, kernel_func='SE_1.414_1.0', window=128, ssf=-1, f_sigma=1): + self.dim_a = dim_a + self.kernel_func = kernel_func + self.window = window + self.ssf = ssf + self.f_sigma = f_sigma + self.index = 0 + self.reset() + + def __call__(self, obs, env): + if self.ssf != -1 and self.index % self.ssf == 0: + self.traj = [[0]*len(self.traj[0])] + traj = th.Tensor(self.traj).unsqueeze(0) + eps = human_input(obs, env) + epsilon = th.Tensor(eps).unsqueeze(0) + sample = self.dist.sample(traj, self.f_sigma, epsilon).squeeze(0) + self.traj.append(sample) + self.index += 1 + return sample + + def reset(self): + self.dist = pca.PCA_Distribution( + action_dim=self.dim_a, par_strength='CONT_DIAG', kernel_func=self.kernel_func, window=self.window) + self.dist.proba_distribution(th.Tensor([[0]*2]), th.Tensor([[1]*2])) + + self.traj = [[0]*self.dim_a] + + class Colored_PCA_Noise(): def __init__(self, beta=1, dim_a=2, samples=2**18, kernel_func='SE_1.41_1', window=64, ssf=-1): self.beta = beta @@ -199,11 +228,11 @@ class Colored_PCA_Noise(): self.reset() def __call__(self, obs, env): - epsilon = self.samples[:, self.index] + epsilon = th.Tensor(self.samples[:, self.index]).unsqueeze(0) if self.ssf != -1 and self.index % self.ssf == 0: self.traj = [[0]*len(self.traj[0])] traj = th.Tensor(self.traj).unsqueeze(0) - sample = self.dist.sample(traj).squeeze(0) + sample = self.dist.sample(traj, epsilon=epsilon).squeeze(0) self.traj.append(sample) self.index += 1 return sample @@ -223,7 +252,7 @@ def rand_seed(): def choosePlayType(): options = {'human': human_input, 'PCA': PCA_Noise(), - 'REX': Colored_Noise(beta=0), 'PINK': Colored_Noise(beta=1), 'BROWN': Colored_Noise(beta=2), 'BETA.5': Colored_Noise(beta=.5), 'PINK_PCA': Colored_PCA_Noise(beta=1), 'Precise_PCA': PCA_Noise(f_sigma=0.33), 'Perlin': Perlin_Noise(scale=0.05, octaves=1), 'FastPerlin': Perlin_Noise(scale=0.2, octaves=1), 'SlowPerlin': Perlin_Noise(scale=0.0125, octaves=1), 'Perlin_3': Perlin_Noise(scale=0.05, octaves=3), 'Perlin_8': Perlin_Noise(scale=0.05, octaves=8), 'Perlin_PCA': Perlin_PCA_Noise()} + 'REX': Colored_Noise(beta=0), 'PINK': Colored_Noise(beta=1), 'BROWN': Colored_Noise(beta=2), 'BETA.5': Colored_Noise(beta=.5), 'PINK_PCA': Colored_PCA_Noise(beta=1), 'Precise_PCA': PCA_Noise(f_sigma=0.33), 'Perlin': Perlin_Noise(scale=0.05, octaves=1), 'FastPerlin': Perlin_Noise(scale=0.2, octaves=1), 'SlowPerlin': Perlin_Noise(scale=0.0125, octaves=1), 'Perlin_3': Perlin_Noise(scale=0.05, octaves=3), 'Perlin_8': Perlin_Noise(scale=0.05, octaves=8), 'Perlin_PCA': Perlin_PCA_Noise(), 'Human_PCA': Human_PCA_Noise()} for i, name in enumerate(options): print('['+str(i)+'] '+name) while True: