Esempio n. 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
        net.save(onet)

        print('done.')

        return True
Esempio n. 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: %s' % nodes)
        print('edges: %s' % 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
Esempio n. 3
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: %s' % 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 #%s' % i)

            gen = load_generator(prog, directed, gen_type)
            synth_net = gen.run(len(net.vs), len(net.es), sr)
            fit_max, fit_mean, distances = fitness.compute(synth_net)

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

            print('fitness (max): %s; fitness (mean): %s' % (fit_max, fit_mean))
            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): %s; min fitness (max): %s; max fitness (max): %s'
              % (mean_fit_max, min_fit_max, max_fit_max))
        print('mean fitness (mean): %s; min fitness (mean): %s; max fitness (mean): %s'
              % (mean_fit_mean, min_fit_mean, max_fit_mean))
        
        print('done.')
        
        return True
Esempio n. 4
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: %s' % dist)

        return True
Esempio n. 5
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? %s' % generator.is_constant())

        return True
Esempio n. 6
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