From 8b1d588b5ec12590ee2601c1476bc2ac153c8773 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Fri, 28 Jun 2024 11:26:44 +0200 Subject: [PATCH] add sync_rayleight_perlin --- priorConditionedAnnealing/noise.py | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/priorConditionedAnnealing/noise.py b/priorConditionedAnnealing/noise.py index 39f8693..0bdb8a6 100644 --- a/priorConditionedAnnealing/noise.py +++ b/priorConditionedAnnealing/noise.py @@ -100,7 +100,6 @@ class SDE_Noise(): 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, octave=1): self.known_shape = known_shape @@ -126,7 +125,7 @@ class Perlin_Noise(): self.index = 0 self.noise = PerlinNoise(octaves=self.octave) -class P_Perlin_Noise(): +class Async_Perlin_Noise(): def __init__(self, known_shape=None, scale=0.1, octave=1): self.known_shape = known_shape self.scale = scale @@ -220,4 +219,30 @@ class Rayleigh_Perlin_Noise(): def reset(self): self.index = 0 self.scales = np.random.rayleigh(scale=self.sigma, size=np.prod(self.known_shape[:-1])) - self.noise = PerlinNoise(octaves=1) \ No newline at end of file + self.noise = PerlinNoise(octaves=1) + +class Sync_Rayleigh_Perlin_Noise(): + def __init__(self, known_shape=None, sigma=0.1): + self.known_shape = known_shape + self.sigma = sigma + self.magic = PI # Axis offset, should be (kinda) irrational + # We want to genrate samples, that approx ~N(0,1) + self.normal_factor = PI/20 + self.clear_cache_every = 128 + self.reset() + + def __call__(self, shape=None): + if shape == None: + shape = self.known_shape + self.index += 1 + noise = [self.noise([self.index*self.scale, self.magic+(2*a)]) / self.normal_factor + for a in range(shape[-1])] + if self.index % self.clear_cache_every == 0: + self.noise.cache = {} + return th.Tensor(noise) + + def reset(self): + self.index = 0 + self.scale = np.random.rayleigh(scale=self.sigma, size=(1,))[0] + self.noise = PerlinNoise(octaves=1) +