def _make_pattern(self, base_sample): base_sample_weight = self._samples.pop(base_sample) base_weight = self.conf.INCUBATOR_NEW_PATTERN_IMPULSE_WEIGHT # find similar samples similar_samples = {} for sample, sample_weight in dict(self._samples).items(): activity = similarity(base_sample, sample) if activity >= self.conf.INCUBATOR_NEW_PATTERN_SIMILAR_SAMPLES_ACTIVITY: similar_samples[sample] = sample_weight del self._samples[sample] # create pattern from base sample pattern = Matrix.create(self.conf.UNIT_INPUT_HEIGHT, self.conf.UNIT_INPUT_WIDTH) for y, impulse in enumerate(base_sample): if impulse is not None: pattern.set(y, impulse, base_weight) # add similar samples to pattern for sample, sample_weight in similar_samples.items(): adding_weight = sample_weight / base_sample_weight * base_weight for y, impulse in enumerate(sample): if impulse is not None: new_weight = braking_add(pattern.get(y, impulse), adding_weight) pattern.set(y, impulse, new_weight) return pattern
def test_braking_add(): assert braking_add(0, 0) == 0 assert braking_add(1, 1) == 1 assert braking_add(1, 0) == 1 assert braking_add(0, 1) == 1 assert braking_add(0.5, 0.5) == 0.75 assert braking_add(0.1, 0.1) == 0.19 assert braking_add(0.9, 0.1) == 0.91