示例#1
0
    def run(self, args):
        self.error_msg = None

        prog = args['prg']
        onet = args['onet']

        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        directed = not args['undir']
        nodes = arg_with_default(args, 'nodes', DEFAULT_NODES)
        edges = arg_with_default(args, 'edges', DEFAULT_EDGES)
        gentype = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        print('nodes: {}'.format(nodes))
        print('edges: {}'.format(edges))

        # load and run generator
        gen = load_generator(prog, directed, gentype)
        net = gen.run(nodes, edges, sr)

        # write net
        if onet[-4:] == '.txt' or onet[-4:] =='.gml':
            net.save(onet)
        else: 
            net.save(onet + '.gml')

        print('done.')

        return True
示例#2
0
    def run(self, args):
        self.error_msg = None

        prog = args['prg']
        out_prog = args['oprg']

        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        directed = not args['undir']
        nodes = arg_with_default(args, 'nodes', DEFAULT_NODES)
        edges = arg_with_default(args, 'edges', DEFAULT_EDGES)
        gentype = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        print('nodes: {}'.format(nodes))
        print('edges: {}'.format(edges))

        # load and run generator
        gen = load_generator(prog, directed, gentype)
        gen.run(nodes, edges, sr)

        # prune and save
        gen.prog.dyn_pruning()
        gen.prog.write(out_prog)

        print('done.')

        return True
示例#3
0
    def run(self, args):
        self.error_msg = None

        prog = args['prg']

        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        directed = not args['undir']
        nodes = arg_with_default(args, 'nodes', DEFAULT_NODES)
        edges = arg_with_default(args, 'edges', DEFAULT_EDGES)
        gentype = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        generator = load_generator(prog, directed, gentype)
        generator.run(nodes, edges, sr)
        print('is constant? {}'.format(generator.is_constant()))

        return True
示例#4
0
    def run(self, args):
        self.error_msg = None

        netfile1 = args['inet']
        netfile2 = args['inet2']

        bins = arg_with_default(args, 'bins', DEFAULT_BINS)
        max_dist = arg_with_default(args, 'maxdist', DEFAULT_MAX_DIST)
        directed = not args['undir']

        # load nets
        net1 = load_net(netfile1, directed)
        net2 = load_net(netfile2, directed)

        print('Network 1: {}'.format(netfile1))
        print('Network 2: {}'.format(netfile2))

        fitness = DistancesToNet(net1,
                                 get_stat_dist_types(args),
                                 bins,
                                 max_dist,
                                 norm=Norm.ER_MEAN_RATIO,
                                 norm_samples=DEFAULT_NORM_SAMPLES)

        distances = fitness.compute(net2)
        print("\nDistance of network 2 (candidate) from network 1 (target):")
        print([stat_type.name for stat_type in fitness.stat_types])
        print(distances)

        fitness = DistancesToNet(net2,
                                 get_stat_dist_types(args),
                                 bins,
                                 max_dist,
                                 norm=Norm.ER_MEAN_RATIO,
                                 norm_samples=DEFAULT_NORM_SAMPLES)

        distances = fitness.compute(net1)
        print("\nDistance of network 1 (candidate) from network 2 (target):")
        print([stat_type.name for stat_type in fitness.stat_types])
        print(distances)
        print('\n')

        return True
示例#5
0
    def run(self, args):
        self.error_msg = None

        out_prog = args['oprg']

        directed = not args['undir']
        gentype = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        gen = create_generator(directed, gentype, init_random=True)
        gen.prog.write(out_prog)

        print('done.')

        return True
示例#6
0
    def run(self, args):
        self.error_msg = None

        prog1 = args['prg']
        prog2 = args['prg2']

        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        directed = not args['undir']
        nodes = arg_with_default(args, 'nodes', DEFAULT_NODES)
        edges = arg_with_default(args, 'edges', DEFAULT_EDGES)
        gentype = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        gen1 = load_generator(prog1, directed, gentype)
        gen2 = load_generator(prog2, directed, gentype)

        gen1.run(nodes, edges, sr, shadow=gen2)
        dist1 = gen1.eval_distance
        gen2.run(nodes, edges, sr, shadow=gen1)
        dist2 = gen2.eval_distance
        dist = (dist1 + dist2) / 2

        print('eval distance: {}'.format(dist))

        return True
示例#7
0
    def run(self, args):
        self.error_msg = None

        netfile = args['inet']
        outdir = args['odir']
        generations = arg_with_default(args, 'gens', DEFAULT_GENERATIONS)
        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        bins = arg_with_default(args, 'bins', DEFAULT_BINS)
        max_dist = arg_with_default(args, 'maxdist', DEFAULT_MAX_DIST)
        directed = not args['undir']
        tolerance = arg_with_default(args, 'tolerance', DEFAULT_TOLERANCE)
        gen_type = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        # load net
        net = load_net(netfile, directed)

        # create base generator
        base_generator = create_generator(directed, gen_type)
        if base_generator is None:
            self.error_msg = 'unknown generator type: {}'.format(gen_type)
            return False

        # create fitness calculator
        # TODO: norm samples configurable
        dists2net = DistancesToNet(net,
                                   get_stat_dist_types(args),
                                   bins,
                                   max_dist,
                                   norm=Norm.ER_MEAN_RATIO,
                                   norm_samples=DEFAULT_NORM_SAMPLES)

        # create evolutionary search
        evo = Evo(net, dists2net, generations, tolerance, base_generator,
                  outdir, sr)

        # some reports to screen
        print('target net: {}'.format(netfile))
        print(evo.info_string())

        # write experiment params to file
        with open('{}/params.txt'.format(outdir), 'w') as text_file:
            text_file.write(evo.info_string())

        # run search
        evo.run()

        return True
示例#8
0
    def run(self, args):
        self.error_msg = None

        netfile = args['inet']
        prog = args['prg']
        sr = arg_with_default(args, 'sr', DEFAULT_SAMPLE_RATE)
        bins = arg_with_default(args, 'bins', DEFAULT_BINS)
        max_dist = arg_with_default(args, 'maxdist', DEFAULT_MAX_DIST)
        directed = not args['undir']
        runs = arg_with_default(args, 'runs', DEFAULT_RUNS)
        gen_type = arg_with_default(args, 'gentype', DEFAULT_GEN_TYPE)

        # load net
        net = load_net(netfile, directed)

        # create base generator
        base_generator = create_generator(directed, gen_type)
        if base_generator is None:
            self.error_msg = 'unknown generator type: {}'.format(gen_type)
            return False

        # create fitness calculator
        # TODO: norm samples configurable
        fitness = DistancesToNet(net,
                                 get_stat_dist_types(args),
                                 bins,
                                 max_dist,
                                 norm=Norm.ER_MEAN_RATIO,
                                 norm_samples=DEFAULT_NORM_SAMPLES)

        fit_maxes = []
        fit_means = []
        for i in range(runs):
            print('run #{}'.format(i))

            gen = load_generator(prog, directed, gen_type)
            synth_net = gen.run(net.vcount(), net.ecount(), sr)
            distances = fitness.compute(synth_net)
            fit_max = max(distances)
            fit_mean = mean(distances)

            fit_maxes.append(fit_max)
            fit_means.append(fit_mean)

            print('fitness (max): {}; fitness (mean): {}'.format(
                fit_max, fit_mean))
            print([stat_type.name for stat_type in fitness.stat_types])
            print(distances)

        mean_fit_max = sum(fit_maxes) / runs
        max_fit_max = max(fit_maxes)
        min_fit_max = min(fit_maxes)

        mean_fit_mean = sum(fit_means) / runs
        max_fit_mean = max(fit_means)
        min_fit_mean = min(fit_means)

        print('\n\n')

        print('mean fitness (max): {}; '
              'min fitness (max): {}; '
              'max fitness (max): {}'.format(mean_fit_max, min_fit_max,
                                             max_fit_max))
        print('mean fitness (mean): {}; '
              'min fitness (mean): {}; '
              'max fitness (mean): {}'.format(mean_fit_mean, min_fit_mean,
                                              max_fit_mean))

        print('done.')

        return True