コード例 #1
0
ファイル: NeatAlgorithm.cpp プロジェクト: nerd-toolkit/nerd
/**
 * Constructs a new NeatAlgorithm.
 */
NeatAlgorithm::NeatAlgorithm(World *world)
{

	if(world == 0) {
		return;
	}

	NeatEvolutionAlgorithm *neatAlg = new NeatEvolutionAlgorithm();

	world->setEvolutionAlgorithm(neatAlg);


	//Add Selection Methods and genotypePhenotypeMapper
	QList<Population*> populations = world->getPopulations();
	for(QListIterator<Population*> i(populations); i.hasNext();) {
		Population *population = i.next();

		//Add Selection Methods.
		NeatSelectionMethod *selection = new NeatSelectionMethod();
		population->addSelectionMethod(selection);
		selection->getPopulationProportion()->set(1.0);

		selection->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));

		//Add GenotypePhenotypeMapper.
		NeatGenotypePhenotypeMapper *mapper = new NeatGenotypePhenotypeMapper();
		population->setGenotypePhenotypeMapper(mapper);
	}
}
コード例 #2
0
bool EvolutionOperatorTestApplication::buildEvolutionSystem() {

	Evolution::install();

	//install evolution system with local simulator evolution.
	new NeuroEvolutionSelector(new LocalNetworkInSimulationEvaluationMethod());
	
	if(!Evolution::getEvolutionManager()->getEvolutionWorlds().empty()) {
		World *world = Evolution::getEvolutionManager()->getEvolutionWorlds().at(0);
		const QList<Population*> &populations = world->getPopulations();

		for(QListIterator<Population*> i(populations); i.hasNext();) {
			Population *population = i.next();	

			//Add Selection Methods.
			FirstParentsTestSelectionMethod *firstParentSelection = new FirstParentsTestSelectionMethod();
			population->addSelectionMethod(firstParentSelection);
			firstParentSelection->getPopulationProportion()->set(0.0);
	
			firstParentSelection->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		}
	}

	return true;
}
コード例 #3
0
ファイル: JanEvolution.cpp プロジェクト: nerd-toolkit/nerd
bool JanEvolution::buildEvolutionSystem() {

	World *world = new World("Main");
	Population *population = new Population("HumanoidControllers");
	world->addPopulation(population);

	IdentityGenotypePhenotypeMapper *mapper = new IdentityGenotypePhenotypeMapper();
	population->setGenotypePhenotypeMapper(mapper);

	new ENS3EvolutionAlgorithm(world);

	world->setEvaluationMethod(new LocalNetworkInSimulationEvaluationMethod());

	Evolution::getEvolutionManager()->addEvolutionWorld(world);


	//Add statistics calculator.
	Statistics::getStatisticsManager()->addGenerationStatistics(
		new BasicNeuralNetworkStatistics(*population));



	FitnessFunction *fitness = 0;

	CommandLineArgument *fitnessFunctionArg = new CommandLineArgument(
		"fitness", "fit", "<prototypeName> <fitnessFunctionName>", 
		"Creates a copy of <prototypeName> and uses it for the population"
		" with the given <fitnessFunctionName>.", 2, 0, true);

	QList<QString> fitArguments = fitnessFunctionArg->getEntryParameters(0);
	if(fitArguments.size() > 1) {
		fitness = Fitness::getFitnessManager()
			->createFitnessFunctionFromPrototype(fitArguments.at(0), fitArguments.at(1));

		if(fitness == 0) {
			cerr << "Failed to create FitnessFunction prototype ["
				 << fitArguments.at(0).toStdString().c_str() << endl;
		}
	}

	if(fitness == 0) {
		fitness = Fitness::getFitnessManager()
			->createFitnessFunctionFromPrototype("Script", "Script");
	}

	population->addFitnessFunction(fitness);

	TournamentSelectionMethod *tournament = new TournamentSelectionMethod(5);
	PoissonDistributionRanking *poissonDistribution = new PoissonDistributionRanking();
	population->addSelectionMethod(tournament);
	population->addSelectionMethod(poissonDistribution);
	tournament->setResponsibleFitnessFunction(fitness);
	poissonDistribution->setResponsibleFitnessFunction(fitness);
	poissonDistribution->getPopulationProportion()->set(0.0);

	//add individual statistics
	StandardIndividualStatistics indStatistics(population); 
	NeuralNetworkIndividualStatistics neuroStatistics(population);

	return true;
}
コード例 #4
0
/**
 * Note. This constructore assumes that world is fully configured.
 * The correct number of populations has already to be set.. 
 * Also a FitnessFunction has to be set for each population before this constructor
 * is called. The first FitnessFunction in the list of FitnessFunctions
 * of each population is used as responsible FitnessFunction for the SelectionMethods.
 *
 * ENS3 consists of:
 * - the ManipulationChainAlgorithm with a number of mutation operators.
 * - the IdentityPhenotypeGenotypeMapper.
 * - a number of compatible SelectionMethods with the PoissionDistribution as default.
 */
ENS3EvolutionAlgorithm::ENS3EvolutionAlgorithm(World *world)
{
	NeuralNetworkManipulationChainAlgorithm *evo = 
			new NeuralNetworkManipulationChainAlgorithm("ENS3");

	if(world != 0) {
		world->setEvolutionAlgorithm(evo);
	}
	
	CreateNetworkOperator *createNetOp = 
				new CreateNetworkOperator("CreateInitNetwork");
	CloneNetworkOperator *cloneNetOp = 
				new CloneNetworkOperator("CloneParent");
	RemoveNeuronOperator *removeNeuronOp = 	
				new RemoveNeuronOperator("RemoveNeurons");
	RemoveSynapseOperator *removeSynapseOp =
				new RemoveSynapseOperator("RemoveSynapse");
	RemoveBiasOperator *removeBiasOp =
				new RemoveBiasOperator("RemoveBias");
	InsertNeuronOperator *insertNeuronOp = 
				new InsertNeuronOperator("InsertNeuron");
	InsertSynapseOperator *insertSynapseOp = 
				new InsertSynapseOperator("InsertSynapse");
	InsertBiasOperator *insertBiasOp = 
				new InsertBiasOperator("InsertBias");
	InitializeSynapsesOperator *initSynapsesOp = 
				new InitializeSynapsesOperator("InitSynapses");
	InitializeBiasOperator *initBiasOp =
				new InitializeBiasOperator("InitBias");
	ChangeBiasOperator *changeBias =
				new ChangeBiasOperator("ChangeBias");
	ChangeSynapseStrengthOperator *changeSynapseStrengthOp =
				new ChangeSynapseStrengthOperator("ChangeSynapseStrength");	
// 	ConnectNeuronClassesFilter *connectNeuronClassFilter =
// 				new ConnectNeuronClassesFilter("ConnectNeuronClasses");
	EnableSynapseOperator *enableSynapseOperator =
				new EnableSynapseOperator("EnableSynapse", true);
	EnableSynapseOperator *disableSynapseOperator =
				new EnableSynapseOperator("DisableSynapse", false);
	

	evo->addOperator(createNetOp);
	evo->addOperator(cloneNetOp);
	evo->addOperator(removeNeuronOp);
	evo->addOperator(removeSynapseOp);
	evo->addOperator(removeBiasOp);
	evo->addOperator(insertNeuronOp);
	evo->addOperator(insertSynapseOp);
	evo->addOperator(insertBiasOp);
	evo->addOperator(initSynapsesOp);
	evo->addOperator(enableSynapseOperator);
	evo->addOperator(disableSynapseOperator);
	evo->addOperator(initBiasOp);
	evo->addOperator(changeBias);
	evo->addOperator(changeSynapseStrengthOp);
// 	evo->addOperator(connectNeuronClassFilter);

	createNetOp->getOperatorIndexValue()->set(0);
	cloneNetOp->getOperatorIndexValue()->set(5);
	removeNeuronOp->getOperatorIndexValue()->set(10);
	removeSynapseOp->getOperatorIndexValue()->set(15);
	removeBiasOp->getOperatorIndexValue()->set(17);
	insertNeuronOp->getOperatorIndexValue()->set(20);
	insertSynapseOp->getOperatorIndexValue()->set(30);
	insertBiasOp->getOperatorIndexValue()->set(40);
	initSynapsesOp->getOperatorIndexValue()->set(50);
	initBiasOp->getOperatorIndexValue()->set(52);
	disableSynapseOperator->getOperatorIndexValue()->set(54);
	enableSynapseOperator->getOperatorIndexValue()->set(55);
	changeBias->getOperatorIndexValue()->set(60);
	changeSynapseStrengthOp->getOperatorIndexValue()->set(70);
// 	connectNeuronClassFilter->getOperatorIndexValue()->set(1100);


	//TODO remove (is not ENS3)
// 	ResolveConstraintsOperator *constraintResolver =
// 				new ResolveConstraintsOperator("ConstraintResolver");
// 	constraintResolver->getOperatorIndexValue()->set(1000);
// 	evo->addOperator(constraintResolver);


	//Add Selection Methods and genotypePhenotypeMapper
	QList<Population*> populations = world->getPopulations();
	for(QListIterator<Population*> i(populations); i.hasNext();) {
		Population *population = i.next();

		//Add Selection Methods.
		TournamentSelectionMethod *tournament = new TournamentSelectionMethod(5);
		PoissonDistributionRanking *poissonDistribution = new PoissonDistributionRanking();
		population->addSelectionMethod(tournament);
		population->addSelectionMethod(poissonDistribution);
		tournament->getPopulationProportion()->set(0.0);
		poissonDistribution->getPopulationProportion()->set(1.0);

		tournament->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		poissonDistribution->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));

		//Add GenotypePhenotypeMapper.
		IdentityGenotypePhenotypeMapper *mapper = new IdentityGenotypePhenotypeMapper();
		population->setGenotypePhenotypeMapper(mapper);
	}

	
	
	
}
コード例 #5
0
/**
 * Constructs a new ModularNeuroEvolution1.
 */
ModularNeuroEvolution1::ModularNeuroEvolution1(World *world)
{
	NeuralNetworkManipulationChainAlgorithm *evo = 
			new NeuralNetworkManipulationChainAlgorithm("ICONE");
	evo->setRequiredNumberOfParentsPerIndividual(2);

	if(world != 0) {
		world->setEvolutionAlgorithm(evo);
	}
	
	CreateNetworkOperator *createNetOp = 
				new CreateNetworkOperator("CreateInitNetwork");
	ModuleCrossOverOperator *modularCrossover =
				new ModuleCrossOverOperator("ModularCrossover");
	CloneNetworkOperator *cloneNetOp = 
				new CloneNetworkOperator("CloneParent");
	RemoveNeuronOperator *removeNeuronOp = 	
				new RemoveNeuronOperator("RemoveNeurons");
	RemoveSynapseOperator *removeSynapseOp =
				new RemoveSynapseOperator("RemoveSynapse");
	RemoveBiasOperator *removeBiasOp =
				new RemoveBiasOperator("RemoveBias");
	InsertNeuroModuleOperator *insertNeuroModule = 
				new InsertNeuroModuleOperator("InsertNeuroModule");
	InsertNeuronOperator *insertNeuronOp = 
				new InsertNeuronOperator("InsertNeuron");
	InsertSynapseModularOperator *insertSynapseOp = 	
				new InsertSynapseModularOperator("InsertSynapse");
	InsertBiasOperator *insertBiasOp = 
				new InsertBiasOperator("InsertBias");
	InitializeSynapsesOperator *initSynapsesOp = 
				new InitializeSynapsesOperator("InitSynapses");
	InitializeBiasOperator *initBiasOp =
				new InitializeBiasOperator("InitBias");
	ChangeBiasOperator *changeBias =
				new ChangeBiasOperator("ChangeBias");
	ChangeSynapseStrengthOperator *changeSynapseStrengthOp =
				new ChangeSynapseStrengthOperator("ChangeSynapseStrength");	
	AdaptSRNParametersOperator *adaptSRNParametersOperator =
				new AdaptSRNParametersOperator("AdaptSRNParameters");
	EnableSynapseOperator *enableSynapseOperator =
				new EnableSynapseOperator("EnableSynapse", true);
	EnableSynapseOperator *disableSynapseOperator =
				new EnableSynapseOperator("DisableSynapse", false);
	ResolveConstraintsOperator *constraintResolver =
				new ResolveConstraintsOperator("ConstraintResolver");
	ConnectNeuronClassesFilter *connectNeuronClassFilter =
				new ConnectNeuronClassesFilter("ConnectNeuronClasses");


	evo->addOperator(createNetOp);
	evo->addOperator(modularCrossover);
	evo->addOperator(cloneNetOp);
	evo->addOperator(removeNeuronOp);
	evo->addOperator(removeSynapseOp);
	evo->addOperator(removeBiasOp);
	evo->addOperator(insertNeuroModule);
	evo->addOperator(insertNeuronOp);
	evo->addOperator(insertSynapseOp);
	evo->addOperator(insertBiasOp);
	evo->addOperator(initSynapsesOp);
	evo->addOperator(enableSynapseOperator);
	evo->addOperator(disableSynapseOperator);
	evo->addOperator(initBiasOp);
	evo->addOperator(changeBias);
	evo->addOperator(adaptSRNParametersOperator);
	evo->addOperator(changeSynapseStrengthOp);
	evo->addOperator(connectNeuronClassFilter);

	createNetOp->getOperatorIndexValue()->set(0);
	modularCrossover->getOperatorIndexValue()->set(10);
	cloneNetOp->getOperatorIndexValue()->set(20);
	removeNeuronOp->getOperatorIndexValue()->set(30);
	removeSynapseOp->getOperatorIndexValue()->set(40);
	removeBiasOp->getOperatorIndexValue()->set(50);
	insertNeuroModule->getOperatorIndexValue()->set(60);
	insertNeuronOp->getOperatorIndexValue()->set(70);
	insertSynapseOp->getOperatorIndexValue()->set(80);
	insertBiasOp->getOperatorIndexValue()->set(90);
	initSynapsesOp->getOperatorIndexValue()->set(100);
	initBiasOp->getOperatorIndexValue()->set(120);
	disableSynapseOperator->getOperatorIndexValue()->set(140);
	enableSynapseOperator->getOperatorIndexValue()->set(160);
	changeBias->getOperatorIndexValue()->set(180);
	changeSynapseStrengthOp->getOperatorIndexValue()->set(200);
	adaptSRNParametersOperator->getOperatorIndexValue()->set(220);
	constraintResolver->getOperatorIndexValue()->set(1000);
	connectNeuronClassFilter->getOperatorIndexValue()->set(1100);
	evo->addOperator(constraintResolver);
	
	modularCrossover->getEnableOperatorValue()->set(false);
	enableSynapseOperator->getEnableOperatorValue()->set(false);
	disableSynapseOperator->getEnableOperatorValue()->set(false);
	
	modularCrossover->getHiddenValue()->set(true);
	enableSynapseOperator->getHiddenValue()->set(true);
	disableSynapseOperator->getHiddenValue()->set(true);


	//Add Selection Methods and genotypePhenotypeMapper
	QList<Population*> populations = world->getPopulations();
	for(QListIterator<Population*> i(populations); i.hasNext();) {
		Population *population = i.next();

		//Add Selection Methods.
		TournamentSelectionMethod *tournament = new TournamentSelectionMethod(5);
		StochasticUniversalSamplingSelection *universalSampling = new StochasticUniversalSamplingSelection();
		MultiObjectiveTournamentSelection *multiObjectivTournament = new MultiObjectiveTournamentSelection(5);
		PoissonDistributionRanking *poissonDistribution = new PoissonDistributionRanking();
		population->addSelectionMethod(tournament);
		population->addSelectionMethod(universalSampling);
		population->addSelectionMethod(multiObjectivTournament);
		population->addSelectionMethod(poissonDistribution);
		tournament->getPopulationProportion()->set(1.0);
		universalSampling->getPopulationProportion()->set(0.0);
		multiObjectivTournament->getPopulationProportion()->set(0.0);
		poissonDistribution->getPopulationProportion()->set(0.0);

		tournament->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		universalSampling->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		multiObjectivTournament->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		poissonDistribution->setResponsibleFitnessFunction(population->getFitnessFunctions().at(0));
		

		//Add GenotypePhenotypeMapper.
		IdentityGenotypePhenotypeMapper *mapper = new IdentityGenotypePhenotypeMapper();
		population->setGenotypePhenotypeMapper(mapper);
	}
}