コード例 #1
0
ファイル: search.py プロジェクト: malykhin-yuri/peano_history
    def gen_pcurves():
        for gates_idx, gates in enumerate(gates_generator):
            if output_gates:
                yield gates
                continue

            logging.info('processing gates: %d', gates_idx + 1)
            paths_gen = PathsGenerator(dim=dim,
                                       div=div,
                                       portals=gates,
                                       max_cdist=max_cdist)
            if output_stats:
                counts = []
                for gate in gates:
                    gcnt = len(
                        list(
                            paths_gen.generate_paths_generic(portal=gate,
                                                             std=True)))
                    counts.append(gcnt)
                yield counts
                continue

            paths_list = list(paths_gen.generate_paths(std=True))
            logging.warning('gates: %s', [str(g) for g in gates])
            logging.warning('paths: %d', len(paths_list))

            for paths_idx, paths in enumerate(paths_list):
                logging.info('processing gate_paths: %d of %d', paths_idx + 1,
                             len(paths_list))
                paths = tuple(
                    CurvePath(path.proto, path.portals) for path in paths)
                yield PathFuzzyCurve.init_from_paths(paths)
コード例 #2
0
def check_genus5_ye_proto():
    YE_curve = get_ye_curve()
    YE_proto = YE_curve.proto
    YE_protos = set(bm * YE_proto for bm in BaseMap.gen_base_maps(dim=2))
    paths_gen = PathsGenerator(dim=2, div=5, links=(SIDE_LINK, ), max_cdist=1)
    paths_list = list(paths_gen.generate_paths(std=True))
    print('got paths:', len(paths_list))
    paths_list = [paths for paths in paths_list if paths[0].proto in YE_protos]
    print('got YE paths:', len(paths_list))
    assert len(paths_list) == 1

    assert paths_list[0][0].proto == YE_proto

    test_pcurves = []
    ye_pcurve = get_ye_curve().forget()
    for cnum, ye_spec in enumerate(YE_curve.specs):
        allowed = ye_pcurve.gen_allowed_specs(pnum=0, cnum=cnum)
        test_pcurves += [
            ye_pcurve.specify(pnum=0, cnum=cnum, spec=sp) for sp in allowed
            if sp != ye_spec
        ]

    estimator = Estimator(ratio_l2, cache_max_size=2**16)

    result = estimator.estimate_dilation_sequence(
        test_pcurves,
        rel_tol_inv=1000,
        sat_strategy={
            'type': 'geometric',
            'multiplier': 1.3
        },
    )
    print(result)
    print('lower bound:', float(result['lo']))
    print('upper bound:', float(result['up']))
コード例 #3
0
    def test_ye_ratio(self):
        # TODO: use ye curve from examples ?
        good_proto = Proto(dim=2, div=5, cubes=[
            (0, 0), (0, 1), (1, 1), (1, 0), (2, 0),
            (2, 1), (2, 2), (1, 2), (0, 2), (0, 3),
            (0, 4), (1, 4), (1, 3), (2, 3), (2, 4),
            (3, 4), (4, 4), (4, 3), (3, 3), (3, 2),
            (4, 2), (4, 1), (3, 1), (3, 0), (4, 0),
        ])
        # in new version we have (0,0)->(0,1) gate
        good_proto = BaseMap.parse('ji') * good_proto

        paths_gen = PathsGenerator(dim=2, div=5, hdist=1, max_cdist=1)
        for paths in paths_gen.generate_paths():
            if paths[0].proto == good_proto:
                path0 = paths[0]
                break

        path0 = CurvePath(path0.proto, path0.portals)  # legacy
        pcurve = PathFuzzyCurve.init_from_paths([path0])
        estimator = Estimator(utils.ratio_l2_squared)
        curve = estimator.estimate_ratio(pcurve, rel_tol_inv=10000, verbose=False)['curve']
        ratio = estimator.estimate_ratio(curve, rel_tol_inv=10000, use_vertex_brkline=True, verbose=False, max_depth=5)

        assert ratio['lo'] == (Rational(408, 73) ** 2)
コード例 #4
0
ファイル: search.py プロジェクト: malykhin-yuri/peano
    def gen_pcurves(gates_iterable):
        for gates_idx, gates in enumerate(gates_iterable):
            if output_gates:
                yield gates
                continue

            logging.info('processing gates: %d', gates_idx + 1)
            paths_gen = PathsGenerator(dim=dim,
                                       div=div,
                                       links=gates,
                                       max_cdist=max_cdist)
            if output_stats:
                counts = []
                for gate in gates:
                    gcnt = len(
                        list(
                            paths_gen.generate_paths_generic(link=gate,
                                                             std=True)))
                    counts.append(gcnt)
                yield counts
                continue

            kw = {}
            if finish_max_count is not None:
                kw['finish_max_count'] = finish_max_count
            paths_list = list(paths_gen.generate_paths(std=True, **kw))
            logging.warning('gates: %s', [str(g) for g in gates])
            logging.warning('paths: %d', len(paths_list))

            for paths_idx, paths in enumerate(paths_list):
                logging.info('processing gate_paths: %d of %d', paths_idx + 1,
                             len(paths_list))
                yield PathFuzzyCurve.init_from_paths(paths)
コード例 #5
0
ファイル: test_curves.py プロジェクト: malykhin-yuri/peano
 def test_diag(self):
     gates = Link.parse_gates('(0,0)->(1,1/2)')
     pgen = PathsGenerator(dim=2, div=5, links=[gates], max_cdist=1)
     paths = next(pgen.generate_paths())
     pcurve = PathFuzzyCurve.init_from_paths(paths)
     curve = pcurve.get_curve_example()
     print(curve)
コード例 #6
0
ファイル: test_ratio.py プロジェクト: jura05/peano
    def test_55_ratio(self):
        good_proto = Proto(dim=2,
                           div=5,
                           cubes=[
                               (0, 0),
                               (0, 1),
                               (1, 1),
                               (1, 0),
                               (2, 0),
                               (2, 1),
                               (2, 2),
                               (1, 2),
                               (0, 2),
                               (0, 3),
                               (0, 4),
                               (1, 4),
                               (1, 3),
                               (2, 3),
                               (2, 4),
                               (3, 4),
                               (4, 4),
                               (4, 3),
                               (3, 3),
                               (3, 2),
                               (4, 2),
                               (4, 1),
                               (3, 1),
                               (3, 0),
                               (4, 0),
                           ])
        # in new version we have (0,0)->(0,1) gate
        good_proto = BaseMap.from_basis('ji') * good_proto

        paths_gen = PathsGenerator(dim=2,
                                   div=5,
                                   hdist=1,
                                   max_cdist=1,
                                   verbose=1)
        for paths in paths_gen.generate_paths():
            if paths[0].proto == good_proto:
                path0 = paths[0]
                break

        pcurve = PathFuzzyCurve.init_from_paths([path0])
        estimator = Estimator(utils.ratio_l2_squared)
        curve = estimator.estimate_ratio(pcurve,
                                         rel_tol_inv=10000,
                                         verbose=False)['curve']
        ratio = estimator.estimate_ratio(curve,
                                         rel_tol_inv=10000,
                                         use_vertex_brkline=True,
                                         verbose=False)

        assert ratio['lo'] == (FastFraction(408, 73)**2)
コード例 #7
0
def check_genus5_non_ye():
    YE_proto = get_ye_curve().proto
    YE_protos = set(bm * YE_proto for bm in BaseMap.gen_base_maps(dim=2))
    paths_gen = PathsGenerator(dim=2, div=5, links=(SIDE_LINK, ), max_cdist=1)
    paths_list = list(paths_gen.generate_paths(std=True))
    print('got paths:', len(paths_list))
    paths_list = [
        paths for paths in paths_list if paths[0].proto not in YE_protos
    ]
    print('got non-YE paths:', len(paths_list))

    estimator = Estimator(ratio_l2, cache_max_size=2**16)

    result = estimator.estimate_dilation_sequence(
        [PathFuzzyCurve.init_from_paths(paths) for paths in paths_list],
        rel_tol_inv=200,
        sat_strategy={
            'type': 'geometric',
            'multiplier': 1.3
        },
    )
    print(result)
    print('lower bound:', float(result['lo']))
    print('upper bound:', float(result['up']))
コード例 #8
0
ファイル: meta-perebor.py プロジェクト: jura05/peano
def meta_perebor(dim, div, pattern_count, ratio_func, rel_tol_inv, rel_tol_inv_mult):
    estimator = Estimator(ratio_func, cache_max_size=2**16)
    result = {}
    for gates in gen_possible_gates(dim=dim, div=div, pattern_count=pattern_count):
        paths_gen = PathsGenerator(dim=dim, div=div, gates=gates)
        paths_list = list(paths_gen.generate_paths(uniq=True))
        logging.warning('gates: %s', [str(g) for g in gates])
        logging.warning('paths: %d', len(paths_list))
        pcurves = (PathFuzzyCurve.init_from_paths(paths) for paths in paths_list)
        res = estimator.estimate_ratio_sequence(
            pcurves,
            rel_tol_inv=rel_tol_inv,
            rel_tol_inv_mult=rel_tol_inv_mult,
            sat_strategy={'type': 'geometric', 'multiplier': 1.3},
        )
        result[tuple(gates)] = {'paths': paths_list, 'estimate': res}

    for gates in sorted(result.keys()):
        gates_result = result[gates]
        print('Result for gates:', [str(g) for g in gates])
        print('paths:', len(gates_result['paths']))
        print('lower bound:', float(gates_result['estimate']['lo']))
        print('upper bound:', float(gates_result['estimate']['up']))
        print('')
コード例 #9
0
ファイル: test_paths.py プロジェクト: Anton495/peano-1
 def test_p3(self):
     gen = PathsGenerator(dim=2, div=5, hdist=2)
     assert len(list(gen.generate_paths(**self.kws))) == 2592
     assert len(list(gen.generate_paths(std=True, **self.kws))) == 659
コード例 #10
0
ファイル: test_paths.py プロジェクト: Anton495/peano-1
 def test_p2(self):
     gen = PathsGenerator(dim=2, div=5, hdist=1)
     assert len(list(gen.generate_paths(**self.kws))) == 49700
     assert len(list(gen.generate_paths(std=True, **self.kws))) == 24850
コード例 #11
0
ファイル: test_paths.py プロジェクト: Anton495/peano-1
 def test_p1(self):
     gen = PathsGenerator(dim=2, div=4, hdist=1)
     assert len(list(gen.generate_paths(**self.kws))) == 298
     assert len(list(gen.generate_paths(std=True, **self.kws))) == 162
コード例 #12
0
def perebor(conf, start_idx=None, end_idx=None):
    logging.warning('CONF: %s', conf)
    funcs = {
        'l1': utils.ratio_l1,
        'l2': utils.ratio_l2,
        'l2_squared': utils.ratio_l2_squared,
        'linf': utils.ratio_linf,
    }
    ratio_func = funcs[conf['ratio_func_name']]
    dim, div = conf['dim'], conf['div']
    gates = None
    if 'gate_strs' in conf:
        gates = [get_gate(g) for g in conf['gate_strs']]
    elif 'gates' in conf:
        gates = conf['gates']

    paths_gen = PathsGenerator(
        dim=dim,
        div=div,
        hdist=conf.get('hdist'),
        gates=gates,
        max_cdist=conf.get('max_cdist'),
    )
    paths_list = list(paths_gen.generate_paths(uniq=True))
    logging.warning('paths: %d', len(paths_list))

    if end_idx is not None:
        # should be checked first!
        paths = list(paths)
        paths = paths[:end_idx]
    if start_idx is not None:
        paths = list(paths)
        paths = paths[start_idx:]

    estimator = Estimator(ratio_func, cache_max_size=2**16)

    #logging.warning('sort by paths ratio ...')
    #path_ratio = {path: estimator.estimate_path(path) for path in paths}
    #paths.sort(key=lambda path: path_ratio[path])

    pcurves = (PathFuzzyCurve.init_from_paths(paths) for paths in paths_list)
    res = estimator.estimate_ratio_sequence(
        pcurves,
        rel_tol_inv=conf['rel_tol_inv'],
        rel_tol_inv_mult=conf.get('rel_tol_inv_mult', 2),
        sat_strategy={
            'type': 'geometric',
            'multiplier': 1.3
        },
        upper_bound=conf.get('upper_bound'),
    )

    if res is None:
        res = {'lo': 0, 'up': float('inf')}

    res['paths_count'] = len(paths_list)
    res['lo_float'] = float(res['lo'])
    res['up_float'] = float(res['up'])

    print('CONFIG:', conf)
    print('BOUNDS: {:.6f} <= r <= {:.6f}'.format(res['lo_float'],
                                                 res['up_float']))
    print('RESULT:', res, flush=True)