Exemple #1
0
    for case in x_train:
        y_true = target(case)
        if program is None:
            errors.append(penalty)
        else:
            try:
                y_pred = program.eval(lst=case)
                errors.append(abs(y_true - y_pred))
            except Exception as e:
                # print(e)
                errors.append(penalty)
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = CoreSoup().register_input("lst", List[int])

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
            errors.append(penalty)
        else:
            y_true = target(x1, x2)
            try:
                y_pred = program.eval(x1=float(x1), x2=float(x2))
                errors.append(float(not isinstance(y_pred, float)))
                errors.append(float((y_true - y_pred)**2))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                errors.append(penalty)
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_constants([x for x in range(10)]).register_input(
    "x1", float).register_input("x2", float))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
Exemple #3
0
                errors += [penalty] * n_errors
                continue
            # Compare the outputs element-wise and compute absolute errors.
            for ndx, el_pred in enumerate(y_pred[:len(y_true)]):
                el_true = y_true[ndx]
                errors.append(abs(el_pred - el_true))
            # If y_pred is shorter than y_true, fill in missing elements with penalties.
            for _ in range(max(0, len(y_true) - len(y_pred))):
                errors.append(penalty)
            # Add the difference in size as an error.
            errors.append(abs(len(y_true) - len(y_pred)))
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_constants([0,
                                       100]).register_input("lst", List[int]))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
Exemple #4
0
    for i, dec in x_train:
        if program is None:
            errors.append(penalty)
        else:
            y_true = target(i, dec)
            try:
                y_pred = program.eval(i=i, dec=dec)
                errors.append(abs(y_true - y_pred))
            except Exception as e:
                # print(e)
                errors.append(penalty)
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_input("i", int).register_input("dec", bool))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
                errors += [penalty] * n_errors
                continue
            # Compare the outputs element-wise and compute absolute errors.
            for ndx, el_pred in enumerate(y_pred[:len(y_true)]):
                el_true = y_true[ndx]
                errors.append(int(el_true != el_pred))
            # If y_pred is shorter than y_true, fill in missing elements with penalties.
            for _ in range(max(0, len(y_true) - len(y_pred))):
                errors.append(penalty)
            # Add the difference in size as an error.
            errors.append(abs(len(y_true) - len(y_pred)))
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_input("lst", List[Comparable]).register_input(
    "lower", Comparable).register_input("upper", Comparable))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
Exemple #6
0
        else:
            y_true = target(i)
            try:
                y_pred = program.eval(i=i)
                errors.append(float(not isinstance(y_pred, bool)))
                errors.append(float(not (bool(y_pred) == y_true)))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                errors.append(penalty)
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (
    CoreSoup()
    .register_input("i", int)
)

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
            # Compare the outputs element-wise and compute absolute errors.
            for ndx, el_pred in enumerate(y_pred[:len(y_true)]):
                el_true = y_true[ndx]
                errors.append(
                    damerau_levenshtein_distance(el_true.path_str,
                                                 el_pred.path_str))
            # If y_pred is shorter than y_true, fill in missing elements with penalties.
            for _ in range(max(0, len(y_true) - len(y_pred))):
                errors.append(penalty)
            # Add the difference in size as an error.
            errors.append(abs(len(y_true) - len(y_pred)))
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_class(SimplePath).register_input(
    "root", SimplePath).register_input("filenames", List[str]))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),
        # (Alternation(), 0.2),
        if program is None:
            errors.append(penalty)
        else:
            try:
                y_pred = program.eval(dt1=dt1, dt2=dt2)
                errors.append(abs(y_pred - y_true))
            except Exception as e:
                # print(e)
                errors.append(penalty)
                continue
    return np.array(errors)


# The "soup" containing all expression which might appear in evolved programs.
soup = (CoreSoup().register_methods(DateTime).register_methods(
    TimeDelta).register_function(sub).register_constant(365).register_input(
        "dt1", datetime).register_input("dt2", datetime))

# The spawner which will generate random genes and genomes.
spawner = Spawner(soup)

# The parent selector.
selector = Lexicase(epsilon=False)

# The evolver
evo = GeneticAlgorithm(
    error_function=error,
    spawner=spawner,
    selector=selector,
    variation=VariationSet([
        (size_neutral_umad, 1.0),