Ejemplo n.º 1
0
def calc_smooth():
    sample = []
    with open('./data/obj_tests.csv', newline='') as csvfile, \
            open('./data/paperObjective.json') as configFile:
        config = json.load(configFile)
        reader = csv.reader(csvfile)
        next(reader)
        for row in reader:
            ml_inst = mergelife.new_ml_instance(HEIGHT, WIDTH, row[0])
            obj = mergelife.objective_function(ml_inst, config['config']['evalCycles'], config['objective'])
            base_score = float(obj['score'])
            print("** {} {}".format(row[0],base_score))

            moves = expand_rule(row[0])
            sum = 0
            for move in moves:
                ml_inst = mergelife.new_ml_instance(HEIGHT, WIDTH, move)
                obj = mergelife.objective_function(ml_inst, config['config']['evalCycles'], config['objective'])
                move_score = float(obj['score'])
                diff = abs(base_score - move_score)
                # print("{}:{}".format(diff,move_score))
                if diff>0.9999:
                    sum += 1
            a = float(sum)/float(len(moves))
            sample.append(a)
            print("Above: {}".format(a))
        print("Avg: {}".format(statistics.mean(sample)))
Ejemplo n.º 2
0
def score(config, ruleText):
    width = config['config']['cols']
    height = config['config']['rows']

    ml_inst = mergelife.new_ml_instance(height, width, ruleText)
    result = mergelife.objective_function(ml_inst,
                                          config['config']['evalCycles'],
                                          config['objective'], True)
    print("Final result: {}".format(result['score']))
Ejemplo n.º 3
0
def produceLatexTable():
    with open('./data/obj_tests.csv', newline='') as csvfile, \
            open('./data/paperObjective.json') as configFile:
                
        config = json.load(configFile)
        reader = csv.reader(csvfile)
        next(reader)
        for row in reader:
            ml_inst = mergelife.new_ml_instance(HEIGHT, WIDTH, row[0])
            obj = mergelife.objective_function(ml_inst, config['config']['evalCycles'], config['objective'])
            row += [str(obj)]
            print("\\texttt{{{}}} & {} & {} \\\\".format(row[0],row[1],obj['score']))
Ejemplo n.º 4
0
def render(config, ruleText):
    width = config['config']['cols']
    height = config['config']['rows']
    steps = config['config']['renderSteps']

    ml_inst = mergelife.new_ml_instance(height, width, ruleText)

    for i in range(steps):
        mergelife.update_step(ml_inst)

    filename = ruleText + ".png"
    mergelife.save_image(ml_inst, filename)
    print("Saved {}".format(filename))
Ejemplo n.º 5
0
def subprocessScore(inputQueue, outputQueue, config):
    while True:
        genome = inputQueue.get()
        rule_str = genome['rule']

        width = config['config']['cols']
        height = config['config']['rows']

        ml_inst = mergelife.new_ml_instance(height, width, rule_str)
        result = mergelife.objective_function(ml_inst,
                                              config['config']['evalCycles'],
                                              config['objective'])
        outputQueue.put({
            'rule': rule_str,
            'score': result['score'],
            'run': genome['run']
        })
Ejemplo n.º 6
0
def calcStdDev():
    devs = []
    with open('./data/obj_tests.csv', newline='') as csvfile, \
            open('./data/paperObjective.json') as configFile:
        config = json.load(configFile)
        reader = csv.reader(csvfile)
        next(reader)
        for row in reader:
            sample = []
            for i in range(10):
                ml_inst = mergelife.new_ml_instance(HEIGHT, WIDTH, row[0])
                obj = mergelife.objective_function(ml_inst, config['config']['evalCycles'], config['objective'])
                sample.append(float(obj['score']))
            print(sample)
            d = statistics.stdev(sample)
            devs.append(d)
            print("{} - {}".format(row[0],d))
        print("Average deviation: {}".format(statistics.mean(devs)))
Ejemplo n.º 7
0
parser.add_argument('--zoom',
                    nargs=1,
                    type=int,
                    help="the pixel size for rendering")
parser.add_argument('rule',
                    metavar='rule',
                    type=str,
                    help='the MergeLife rule to animate')

args = parser.parse_args()

if args.rows is not None:
    rows = args.rows[0]
else:
    rows = 100

if args.cols is not None:
    cols = args.cols[0]
else:
    cols = 100

time_step = 0

fig = plt.figure()
data = np.random.randint(0, 256, size=(rows, cols, 3), dtype=np.uint8)
im = plt.imshow(data, animated=True)

ml_inst = mergelife.new_ml_instance(rows, cols, args.rule)

go_animate()