Exemple #1
0
def oneshot(ver, gene):
    import sys
    if "../lib" not in sys.path:
        sys.path.append("../lib")
    import geneop
    import config as cfg
    gene_type = ver
    geneop.load_type(gene_type)
    gene = int(gene)
    n = {
        "v1": 142,
    }[gene_type]
    gene = geneop.cvtintlst(gene, n)
    cfg.worker_config = {
        "result_format": ("sdr", "neg_gflops", "neg_mega_pc"),
        "batch_size": 2,
        "max_lr": 3e-4,
        "min_lr": 1e-4,
        "warmup_fac": 0.3,
        "first_lr_period": 100,
        "warmup_period": 100,
        "n_hop_per_sample": 64,
        "work_sr": 8000,
        "hop_size": 256,
        "fft_size": 1024,
        "n_feature": 512,
        "n_train": 156,
        "n_step": 700,
        "n_eval": 3,
    }
    pre_fn()
    r = eval_fn(gene)
    del cfg.worker_config
    clean_env()
    return r
Exemple #2
0
def infer(x, n_out_channel, train, ver=None, gene=None):
  import sys
  if not "../lib" in sys.path:
    sys.path.append("../lib")
  import geneop
  import config as cfg
  if ver is not None:
    geneop.load_type(ver)
    if isinstance(gene, int):
      gene = geneop.cvtintlst(gene, geneop.gene_len)
    else:
      raise TypeError("Invalid gene value `%r`" % (gene,))
  else:
    geneop.load_type(cfg.gene_ver)
    gene = geneop.cvtintlst(cfg.gene_value, geneop.gene_len)
  return geneop.build_from_gene(x, n_out_channel, gene)
Exemple #3
0
    def boundary():
        cb = geneop.cvtintlst(0b0, 1)
        ccg_res = geneop.cvtintlst(0b1, 1) + cb + cb
        cg_res_64 = geneop.cvtintlst(0b11, 2) + ccg_res
        cg_pass = geneop.cvtintlst(0b00, 2) + ccg_res
        pb_1x16 = geneop.cvtintlst(0b00_11, 4)
        pb_pass = geneop.cvtintlst(0b00_00, 4)
        rb_a = pb_1x16 + geneop.cvtintlst(0b11, 2) + ccg_res
        rb_pass = pb_pass + geneop.cvtintlst(0b11, 2) + ccg_res
        b_a = cg_res_64 + rb_a + rb_pass + ccg_res
        b_b = cg_res_64 + rb_pass + rb_a + ccg_res
        assert b_from_gene(None, 128, b_a) == b_from_gene(None, 128, b_a)

        v4m0 = geneop.cvtintlst(0b11_0_00_000_0000,
                                12) + b_a + b_a + b_a + b_a + b_a
        v4m0_b = geneop.cvtintlst(0b11_0_00_000_0000,
                                  12) + b_b + b_a + b_b + b_a + b_b
        v4m0_c = geneop.cvtintlst(0b11_0_01_001_0001,
                                  12) + b_b + b_a + b_b + b_a + b_b
        assert cmp_gene(v4m0, v4m0_b)
        assert not cmp_gene(v4m0, v4m0_c)
        print(geneop.cvtlstint(v4m0))
Exemple #4
0
def eval_single(gene):
    gene = geneop.cvtintlst(int(gene), cfg.n)
    return cfg.worker.eval_fn(gene)
Exemple #5
0
#  module: Python module for specified evo_type (do not change!)
evo_module = __import__("evo_%s" % (evo_type, ))
#  float: Ratio of pure random gene in initial population.
#         0.0 means no pure random gene, 1.0 means all population are built with pure random gene.
init_random_ratio = 0.0
p2 = 0.02

# Section: Gene
#  str: "v1" for the paper (do not change!)
gene_type = "v1"
geneop.load_type(gene_type)
#  List[List[bool]]: Handcrafted initial population (do not change!)
if init_random_ratio != 1.0:
    if gene_type == "v1":
        manual_gene_list = [
            geneop.cvtintlst(x, 142) for x in [
                4182591019167972528534244115322478782824676,
            ]
        ]
    else:
        assert False

# Section: Evolution(Additional)
#  int: Maximum number of bits to flip when generate gene from handcrafted popluation (do not change!)
if init_random_ratio != 1.0:
    if gene_type in ("v1", ):
        gene_jitter_count = 20
    else:
        assert False

# Section: Worker