diff --git a/priorConditionedAnnealing/noise.py b/priorConditionedAnnealing/noise.py index 9247e05..e68f399 100644 --- a/priorConditionedAnnealing/noise.py +++ b/priorConditionedAnnealing/noise.py @@ -99,6 +99,7 @@ class Perlin_Noise(): self.magic = 3.141592653589 # Axis offset, should be (kinda) irrational # We want to genrate samples, that approx ~N(0,1) self.normal_factor = 14/99 + self.clear_cache_every = 1024 self.reset() def __call__(self, shape=None): @@ -107,6 +108,8 @@ class Perlin_Noise(): self.index += 1 noise = [self.noise([self.index*self.scale, self.magic*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): @@ -126,12 +129,16 @@ class Harmonic_Perlin_Noise(): octaves_arr += [1/(int_octaves+2)*(octaves-int_octaves)] octaves_arr = np.array(octaves_arr) self.octaves = octaves_arr / np.linalg.norm(octaves_arr) + self.clear_cache_every = 1024 self.reset() def __call__(self, shape=None): if shape == None: shape = self.known_shape harmonics = [noise(shape)*self.octaves[i] for i, noise in enumerate(self.noises)] + if self.index % self.clear_cache_every == 0: + for i, noise in enumerate(self.noises): + noise.cache = {} return sum(harmonics) def reset(self):