Example #1
0
 def compose(a1, a2):
     label = "%s%s" % (a1.label, a2.label)
     # This is the correct order
     diffeo = Diffeomorphism2D.compose(a2.diffeo, a1.diffeo)
     diffeo_inv = Diffeomorphism2D.compose(a1.diffeo_inv, a2.diffeo_inv)
     # diffeo = Diffeomorphism2D.compose(a1.diffeo, a2.diffeo)
     # diffeo_inv = Diffeomorphism2D.compose(a2.diffeo_inv, a1.diffeo_inv)
     original_cmds = a1.get_original_cmds() + a2.get_original_cmds()
     return DiffeoAction(label, diffeo, diffeo_inv, original_cmds)
Example #2
0
 def compose(a1, a2):
     label = '%s%s' % (a1.label, a2.label)
     # This is the correct order
     diffeo = Diffeomorphism2D.compose(a2.diffeo, a1.diffeo)
     diffeo_inv = Diffeomorphism2D.compose(a1.diffeo_inv, a2.diffeo_inv)
     # diffeo = Diffeomorphism2D.compose(a1.diffeo, a2.diffeo)
     # diffeo_inv = Diffeomorphism2D.compose(a2.diffeo_inv, a1.diffeo_inv)
     original_cmds = a1.get_original_cmds() + a2.get_original_cmds()
     return DiffeoAction(label, diffeo, diffeo_inv, original_cmds)
Example #3
0
def DDSFromSymbolic(resolution, actions, topology=None):  #@UnusedVariable
    """ 
        Creates a DiffeoSystem from synthetic diffeomorphisms. 
    """
    config = get_current_config()

    logger.info('Creating symbolic diffeomorphism (resolution = %d)' %
                resolution)

    diffeoactions = []
    for _, action in enumerate(actions):

        id_diffeo, diffeo = parse_diffeo_spec(config, action['diffeo'])
        label = action.get('label', id_diffeo)

        original_cmd = np.array(action['original_cmd'])

        logger.info('Getting symbolic diffeomorphism %r' % id_diffeo)

        shape = (resolution, resolution)
        viewport = SquareDomain([[-1, +1], [-1, +1]])
        manifold = diffeo.get_topology()
        D, Dinfo = diffeo_from_function_viewport(diffeo, manifold, viewport,
                                                 shape)
        D2d = Diffeomorphism2D(D, Dinfo)

        diffeo_inv = diffeo.get_inverse()
        D_inv, Dinfo_inv = diffeo_from_function_viewport(
            diffeo_inv, manifold, viewport, shape)
        D2d_inv = Diffeomorphism2D(D_inv, Dinfo_inv)

        action = DiffeoAction(label=label,
                              diffeo=D2d,
                              diffeo_inv=D2d_inv,
                              original_cmd=original_cmd)
        diffeoactions.append(action)

    dds = DiffeoSystem('%s' % actions, actions=diffeoactions)
    return dds
 def make_hard(dd):
     assert isinstance(dd, Diffeomorphism2D)
     if use_isomorphism_heuristics:
         stats = diffeo_stats(dd.d)
         per = np.percentile(stats.norm, norm_percentile)
         limit = per * factor
         # / 3.0
         #print('norm mean/mean: %g %g' % (np.mean(stats.norm), np.median(stats.norm)))
         #for i in range(0, 100, 5):
         #    print(' %3d%% = %g' % (i, np.percentile(stats.norm, i)))
         #limit = np.percentile(stats.norm, info_percentile)
         #if limit <= 1:
         #    print('limit was %g' % limit)
         #    limit = 4
         variance = (stats.norm > limit).astype('float')
         logger.info('---hard choices---')
         logger.info('  per: %g pixels * %g =' % (per, factor))
         logger.info('limit: %g pixels' % limit)
         logger.info('  vis: %.1f%% ' % (100 * np.mean(variance)))
     else:
         variance = (dd.variance > info_threshold).astype('float')
     return Diffeomorphism2D(dd.d, variance)
Example #5
0
 def identity(label, shape, original_cmd):
     """ Constructs the identity action of the given shape. """
     diffeo = Diffeomorphism2D.identity(shape)
     diffeo_inv = diffeo
     return DiffeoAction(label, diffeo, diffeo_inv, original_cmd)
Example #6
0
 def identity(label, shape, original_cmd):
     """ Constructs the identity action of the given shape. """
     diffeo = Diffeomorphism2D.identity(shape)
     diffeo_inv = diffeo
     return DiffeoAction(label, diffeo, diffeo_inv, original_cmd)