Example #1
0
        selection_operator = ThresholdSelection(0, tournament_selection, 10)
    else:
        raise ValueError(
            'Invalid selection operator "%s". Choose "threshold", "tournament" or "dual".'
            % (args.selection[0]))

    optimiser.setSelectionOperator(selection_operator)

    # Create the genetic operators
    new_blood = NewBloodOperator(args.initial_new_blood_probability[0])
    gaussian_mutation = GaussianMutationOperator(
        1.0 - args.initial_new_blood_probability[0],
        args.initial_mutation_variance[0])

    # Add the genetic operators to the EA
    optimiser.addGeneticOperator(new_blood)
    optimiser.addGeneticOperator(gaussian_mutation)

    # Show the visualisation
    if args.visualisation:
        fig, ax = plt.subplots(7, 2)
        global_fitness_function.plot(fig, ax, 0, number_of_generation)

    # Create a progress bar
    bar = MyBar('Generation', max=number_of_generation)
    best_global_fitness = global_fitness_function.global_fitness_set[-1]

    # Log message
    if not isinstance(args.logging, NoneType):
        logging.debug("Initial Global fitness: %f" % best_global_fitness)
        logging.debug("Initial RMSE: %f" %
Example #2
0
# Optimisation and visualisation
optimiser = EvolutionaryAlgorithm(test_problem, g_number_of_individuals)

# Set the selection operator
#optimiser.setSelectionOperator(TournamentSelection(2));
#optimiser.setSelectionOperator(RouletteWheel());
optimiser.setSelectionOperator(RankSelection())

# Create the genetic operators
elitism = ElitismOperator(0.1)
new_blood = NewBloodOperator(0.1)
gaussian_mutation = GaussianMutationOperator(0.1, 0.2)
blend_cross_over = BlendCrossoverOperator(0.6, gaussian_mutation)

# Add the genetic operators to the EA
optimiser.addGeneticOperator(new_blood)
optimiser.addGeneticOperator(gaussian_mutation)
optimiser.addGeneticOperator(blend_cross_over)
optimiser.addGeneticOperator(elitism)

test_problem.number_of_evaluation = 0
optimiser.plotAnimation(g_iterations, visualisationCallback)
EA_number_of_evaluation = test_problem.number_of_evaluation
EA_solution = optimiser.best_solution

# Optimisation and visualisation
test_problem.number_of_evaluation = 0
optimiser = PSO(test_problem, g_number_of_individuals)
optimiser.plotAnimation(g_iterations)
PSO_number_of_evaluation = test_problem.number_of_evaluation
PSO_solution = optimiser.best_solution
    elif args.selection[0] == "ranking":
        optimiser.setSelectionOperator(RankSelection())
    elif args.selection[0] == "roulette":
        optimiser.setSelectionOperator(RouletteWheelSelection())
    else:
        raise ValueError(
            'Invalid selection operator "%s". Choose "threshold", "tournament" or "dual".'
            % (args.selection[0]))

    # Create the genetic operators
    gaussian_mutation = GaussianMutationOperator(
        0.3, args.initial_mutation_variance[0])
    blend_cross_over = BlendCrossoverOperator(0.6, gaussian_mutation)

    # Add the genetic operators to the EA
    optimiser.addGeneticOperator(blend_cross_over)
    optimiser.addGeneticOperator(gaussian_mutation)
    optimiser.addGeneticOperator(ElitismOperator(0.1))

    # Show the visualisation
    if args.visualisation:
        fig, ax = plt.subplots(7, 2)
        global_fitness_function.plot(fig, ax, 0, number_of_generation)

    # Create a progress bar
    bar = MyBar('Generation', max=number_of_generation)
    best_global_fitness = global_fitness_function.global_fitness_set[-1]

    # Log message
    if not isinstance(args.logging, NoneType):
        logging.debug("Initial Global fitness: %f" % best_global_fitness)