def action_test_1(): shape = (20, 20) d_rotx = diffeo_from_function(shape, rotx) d1 = Diffeomorphism2D(d_rotx) d2 = Diffeomorphism2D(diffeo_inverse(d_rotx)) a1 = Action(d1, label='rotx', primitive=True, invertible=False, original_cmd='rotx') a2 = Action(d2, label='rotx_inv', primitive=True, invertible=False, original_cmd='rotx_inv') assert_allclose(Action.similarity(a1, a1), +1) assert_allclose(Action.similarity(a1, a2), -1) assert_allclose(Action.similarity(a2, a1), -1) assert_allclose(Action.similarity(a2, a2), +1)
def update(self): rgb = self.input.rgb if rgb.ndim == 2: shape = rgb.shape elif rgb.ndim == 3: shape = (rgb.shape[0], rgb.shape[1]) else: raise BadInput('expected rgb', self, 'rgb') if self.D is None: # create diffeormorphism if needed self.info('Creating diffeormophism %s at %s' % (self.f, shape)) self.D = diffeo_from_function(shape, self.f) self.info('Done.') self.output.rgb = diffeo_apply(self.D, rgb)
def action_compress_test_1(): shape = (20, 20) d_rotx = diffeo_from_function(shape, rotx) d1 = Diffeomorphism2D(d_rotx) d2 = Diffeomorphism2D(diffeo_inverse(d_rotx)) a1 = Action(d1, label='rotx', primitive=True, invertible=False, original_cmd='rotx') a2 = Action(d2, label='rotx_inv', primitive=True, invertible=False, original_cmd='rotx_inv') threshold = 0.999 actions2, info = actions_compress([a1], threshold) # @UnusedVariable assert_allclose(len(actions2), 1) assert(not actions2[0].invertible) actions2, info = actions_compress([a1, a2], threshold) # @UnusedVariable assert_allclose(len(actions2), 1) assert(actions2[0].invertible)