From 5f2d27efcea1bf8382144a1acc9a0f49de53c83f Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Thu, 4 May 2023 12:17:43 +0200 Subject: [PATCH] Implemented Perlin as underlying epsilon dist --- priorConditionedAnnealing/noise.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/priorConditionedAnnealing/noise.py b/priorConditionedAnnealing/noise.py index 1e0c22e..118360c 100644 --- a/priorConditionedAnnealing/noise.py +++ b/priorConditionedAnnealing/noise.py @@ -1,6 +1,7 @@ import numpy as np import torch as th import colorednoise as cn +from perlin_noise import PerlinNoise from torch.distributions import Normal @@ -78,3 +79,23 @@ class SDE_Noise(): # (batch_size, 1, n_actions) noise = th.bmm(th.bmm(latent_sde, self.exploration_matrices), chol) return noise.squeeze(dim=1) + + +class Perlin_Noise(): + def __init__(self, known_shape=None, scale=0.1, octaves=1): + self.known_shape = known_shape + self.scale = scale + self.octaves = octaves + self.magic = 3.14159 # Axis offset + # We want to genrate samples, that approx ~N(0,1) + self.normal_factor = 0.0471 + self.reset() + + def __call__(self, shape): + self.index += 1 + return [self.noise([self.index*self.scale, self.magic*a]) / self.normal_factor + for a in range(self.shape[-1])] + + def reset(self): + self.index = 0 + self.noise = PerlinNoise(octaves=self.octaves)