public AgentGenome Mutate(AgentGenome parentGenome, bool bodySettings, bool brainSettings) { //AgentGenome parentGenome = leaderboardGenomesList[selectedIndex].candidateGenome; //***EAC Creature NAME mutation here??? string parentName = parentGenome.name; int randIndex = Random.Range(0, parentName.Length - 1); string frontHalf = parentName.Substring(0, randIndex); string middleChar = parentName.Substring(randIndex, 1); string backHalf = parentName.Substring(randIndex + 1); if (RandomStatics.CoinToss(.05f)) { middleChar = RandomStatics.GetRandomLetter(); } frontHalf += middleChar; string newName = RandomStatics.CoinToss(.025f) ? backHalf + frontHalf : frontHalf + backHalf; //-------------------------------------------------------------------------------------------------------------------- tempMutationSettings = bodySettings ? mutationSettings : cachedNoneMutationSettings; BodyGenome newBodyGenome = new BodyGenome(parentGenome.bodyGenome, tempMutationSettings); tempMutationSettings = brainSettings ? mutationSettings : cachedNoneMutationSettings; BrainGenome newBrainGenome = new BrainGenome(parentGenome.brainGenome, newBodyGenome, tempMutationSettings); return new AgentGenome(newBodyGenome, newBrainGenome, parentGenome.generationCount + 1, newName); }
public void Copy(MutationSettingsInstance template) { brainInitialConnectionChance = template.brainInitialConnectionChance; brainWeightMutationChance = template.brainWeightMutationChance; brainWeightMutationStepSize = template.brainWeightMutationStepSize; brainRemoveLinkChance = template.brainRemoveLinkChance; brainWeightDecayAmount = template.brainWeightDecayAmount; brainCreateNewLinkChance = template.brainCreateNewLinkChance; brainCreateNewHiddenNodeChance = template.brainCreateNewHiddenNodeChance; bodyColorsMutationChance = template.bodyColorsMutationChance; bodyColorsMutationStepSize = template.brainWeightMutationStepSize; bodyCoreSizeMutationChance = template.bodyCoreSizeMutationChance; bodyCoreMutationStepSize = template.bodyCoreMutationStepSize; bodyProportionsMutationChance = template.bodyProportionsMutationChance; bodyProportionsMutationStepSize = template.bodyProportionsMutationStepSize; bodyEyeProportionsMutationChance = template.bodyEyeProportionsMutationChance; bodyEyeProportionsMutationStepSize = template.bodyEyeProportionsMutationStepSize; bodyModuleCreateNewChance = template.bodyModuleCreateNewChance; bodyModuleInternalMutationChance = template.bodyModuleInternalMutationChance; bodyModuleInternalMutationStepSize = template.bodyModuleInternalMutationStepSize; bodyModuleRemoveExistingChance = template.bodyModuleRemoveExistingChance; bodyTalentSpecMutationChance = template.bodyTalentSpecMutationChance; bodyTalentSpecMutationStepSize = template.bodyTalentSpecMutationStepSize; bodyDietSpecMutationChance = template.bodyDietSpecMutationChance; bodyDietSpecMutationStepSize = template.bodyDietSpecMutationStepSize; defaultFoodMutationChance = template.defaultFoodMutationChance; defaultFoodMutationStepSize = template.defaultFoodMutationStepSize; }
List <LinkGenome> MutateLinks(List <LinkGenome> original, MutationSettingsInstance settings) { var result = new List <LinkGenome>(); foreach (var element in original) { LinkGenome newLinkGenome = new LinkGenome(element.from, element.to, element.weight, true); // Remove fully??? ***** if (RandomStatics.CoinToss(settings.brainRemoveLinkChance)) { newLinkGenome.weight = 0f; } if (RandomStatics.CoinToss(settings.brainWeightMutationChance)) { float randomWeight = Gaussian.GetRandomGaussian(); newLinkGenome.weight += Mathf.Lerp(0f, randomWeight, settings.brainWeightMutationStepSize); } newLinkGenome.weight *= settings.brainWeightDecayAmount; result.Add(newLinkGenome); } return(result); }
// WPP: empty constructor is redundant, compiler creates this by default //public MasterGenomePool() { } public void FirstTimeInitialize(MutationSettingsInstance mutationSettings) { debugRecentlyDeletedCandidateIDsList = new List <int>(); nextCandidateIndex = 0; this.mutationSettings = mutationSettings; currentlyActiveSpeciesIDList = new List <int>(); completeSpeciesPoolsList = new List <SpeciesGenomePool>(); //SpeciesGenomePool rootSpecies = new SpeciesGenomePool(0, -1, 0, 0, mutationSettingsRef); //rootSpecies.FirstTimeInitializeROOT(numAgentGenomes, 0); //currentlyActiveSpeciesIDList.Add(0); //completeSpeciesPoolsList.Add(rootSpecies); for (int i = 0; i < numInitSpecies; i++) { //float lerpV = Mathf.Clamp01((i + 0.1f) / (numInitSpecies + 1) + 0.06f) * 0.8f + 0.1f; //float lerpV = 0.5f; SpeciesGenomePool newSpecies = new SpeciesGenomePool(i, -1, 0, 0, mutationSettings); AgentGenome seedGenome = new AgentGenome(mutationSettings.brainInitialConnectionChance, simulation.numInitialHiddenNeurons); newSpecies.FirstTimeInitialize(new CandidateAgentData(seedGenome, i), 0); currentlyActiveSpeciesIDList.Add(i); completeSpeciesPoolsList.Add(newSpecies); } selectionManager.SetSelected(completeSpeciesPoolsList[0].candidateGenomesList[0]); }
// Mutable by Player // Add body-sensor/effector mutations here and cleanup Brain Genome void SetToMutatedCopyOfParentGenome(BodyGenome parent, MutationSettingsInstance settings) { appearanceGenome.SetToMutatedCopyOfParentGenome(parent.appearanceGenome, settings); coreGenome.SetToMutatedCopyOfParentGenome(parent.coreGenome, settings); unlockedTech = unlockedTech.GetMutatedCopy(); newlyUnlockedNeuronInfo = GetNewlyUnlockedNeurons(parent); }
public BodyGenome(BodyGenome parentGenome, MutationSettingsInstance mutationSettings) { unlockedTech = new UnlockedTech(parentGenome.unlockedTech); data = new BodyGenomeData(unlockedTech); FirstTimeInitializeCritterModuleGenomes(); SetToMutatedCopyOfParentGenome(parentGenome, mutationSettings); }
public SpeciesGenomePool(int ID, int parentID, int year, int timeStep, MutationSettingsInstance settings) { yearCreated = year; speciesID = ID; parentSpeciesID = parentID; mutationSettings = settings; timeStepCreated = timeStep; timeStepExtinct = 2000000000; speciesName = ID.ToString(); }
void AddNewLink(MutationSettingsInstance settings) { foreach (var neuron in hiddenNeurons) { inputNeurons.Add(neuron); outputNeurons.Add(neuron); } if (inputNeurons.Count <= 0 || outputNeurons.Count <= 0) { Debug.LogError("Cannot create new list because input or output list count is zero. " + $"Input count = {inputNeurons.Count}, output count = {outputNeurons.Count}"); return; } // Try x times to find new connection -- random scattershot approach at first: // other methods: // -- make sure all bodyNeurons are fully-connected when modifying body int maxChecks = 8; for (int k = 0; k < maxChecks; k++) { int randInputID = Random.Range(0, inputNeurons.Count); var from = inputNeurons[randInputID]; int randOutputID = Random.Range(0, outputNeurons.Count); var to = outputNeurons[randOutputID]; if (LinkExists(from, to)) { continue; } float randomWeight = Gaussian.GetRandomGaussian() * settings.brainWeightMutationStepSize; LinkGenome linkGenome = new LinkGenome(from, to, randomWeight, true); links.Add(linkGenome); //Debug.Log("New Link! from: [" + fromNID.moduleID.ToString() + ", " + fromNID.neuronID.ToString() + "], to: [" + toNID.moduleID.ToString() + ", " + toNID.neuronID.ToString() + "]"); break; } }
public void InitializeGridSearch(MutationSettingsInstance settings, bool biggerIsBetter) { this.biggerIsBetter = biggerIsBetter; this.settings = settings; isComplete = false; numGens = 420; // number of generations for each Run numRunsPerSetting = 8; resolutionA = 1; // how to split each dimension resolutionB = 1; // how to split each dimension resolutionC = 2; // how to split each dimension resolutionD = 1; // how to split each dimension // Start out hardcoded to 4 dimensions, expand functionality later: coordA = 0; // mutationChance coordB = 0; // stepSize coordC = 0; // initialConnectionChance coordD = 0; // weight decay curIter = 0; minA = 0.015f; maxA = 0.015f; minB = 0.5f; maxB = 0.5f; minC = 0.0f; maxC = 0.5f; minD = 1f; maxD = 1f; storedResults = new GridSearchResults(); coordA = 0; coordB = 0; coordC = 0; coordD = 0; curIter = 0; CreateDataContainer(); }
public void SetToMutatedCopyOfParentGenome(EggSackGenome parentFoodGenome, MutationSettingsInstance settings) { // *** Result needs to be fully independent copy and share no references!!! fullSize = UtilityMutationFunctions.GetMutatedVector2Additive(parentFoodGenome.fullSize, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0.25f, 4.5f); if (fullSize.y < fullSize.x) { fullSize.y = fullSize.x; } // Set equal to parent at first, then check for possible mutation of that value: fruitHue = UtilityMutationFunctions.GetMutatedVector3Additive(parentFoodGenome.fruitHue, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0f, 1f); leafHue = UtilityMutationFunctions.GetMutatedVector3Additive(parentFoodGenome.leafHue, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0f, 1f); stemHue = UtilityMutationFunctions.GetMutatedVector3Additive(parentFoodGenome.stemHue, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0f, 1f); stemBrushType = UtilityMutationFunctions.GetMutatedIntAdditive(parentFoodGenome.stemBrushType, settings.defaultFoodMutationChance, 3, 0, 7); leafBrushType = UtilityMutationFunctions.GetMutatedIntAdditive(parentFoodGenome.leafBrushType, settings.defaultFoodMutationChance, 3, 0, 7); fruitBrushType = UtilityMutationFunctions.GetMutatedIntAdditive(parentFoodGenome.fruitBrushType, settings.defaultFoodMutationChance, 3, 0, 7); stemWidth = UtilityMutationFunctions.GetMutatedFloatAdditive(parentFoodGenome.stemWidth, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0.1f, 0.8f); leafScale = UtilityMutationFunctions.GetMutatedVector2Additive(parentFoodGenome.leafScale, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0.15f, 0.25f); fruitScale = UtilityMutationFunctions.GetMutatedVector2Additive(parentFoodGenome.fruitScale, settings.defaultFoodMutationChance, settings.defaultFoodMutationStepSize, 0.06f, 0.15f); }
public MutationSettingsInstance(MutationSettingsInstance template) { Copy(template); }
public BrainGenome(BrainGenome parentGenome, BodyGenome bodyGenome, MutationSettingsInstance mutationSettings) { SetToMutatedCopyOfParentGenome(parentGenome, bodyGenome, mutationSettings); }
public void SetToMutatedCopyOfParentGenome(BrainGenome parentGenome, BodyGenome bodyGenome, MutationSettingsInstance settings) { /* * //this.bodyNeuronList = parentGenome.bodyNeuronList; // UNSUSTAINABLE!!! might work now since all neuronLists are identical ****** * * // Copy from parent brain or rebuild neurons from scratch based on the new mutated bodyGenome???? --- ****** * for(int i = 0; i < parentGenome.bodyNeuronList.Count; i++) { * NeuronGenome newBodyNeuronGenome = new NeuronGenome(parentGenome.bodyNeuronList[i]); * this.bodyNeuronList.Add(newBodyNeuronGenome); * } * // Alternate: SetBodyNeuronsFromTemplate(BodyGenome templateBody); */ // Rebuild BodyNeuronGenomeList from scratch based on bodyGenome InitializeBodyNeuronList(); InitializeIONeurons(bodyGenome); hiddenNeurons = MutateHiddenNeurons(parentGenome.hiddenNeurons); links = MutateLinks(parentGenome.links, settings); if (RandomStatics.CoinToss(settings.brainCreateNewLinkChance)) { AddNewLink(settings); } if (RandomStatics.CoinToss(settings.brainCreateNewHiddenNodeChance)) { AddNewHiddenNeuron(); } var newNeurons = GetNewlyUnlockedNeurons(bodyGenome); //Debug.Log($"Initializing axons with {newNeurons.Count} new neurons from " + // $"{bodyGenome.newlyUnlockedNeuronInfo.Count} new tech."); foreach (var neuron in newNeurons) { SortIONeuron(neuron); LinkNeuronToLayer(neuron); } //RemoveVestigialLinks(); }
MutationSettingsInstance GetSetNoneMutationSettings() { return _cachedNoneMutationSettings = lookup.GetMutationSettingsCopy(MutationSettingsId.None); }
public void SetToMutatedCopyOfParentGenome(CritterModuleAppearanceGenome parentGenome, MutationSettingsInstance settings) { //float mutationChanceMultiplier = 1f; // ******* settings.mutationStrengthSlot; huePrimary = UtilityMutationFunctions.GetMutatedVector3Additive(parentGenome.huePrimary, settings.bodyColorsMutationChance, settings.bodyColorsMutationStepSize, 0f, 1f); hueSecondary = UtilityMutationFunctions.GetMutatedVector3Additive(parentGenome.hueSecondary, settings.bodyColorsMutationChance, settings.bodyColorsMutationStepSize, 0f, 1f); // ***** v v v Revisit when implementing #BrushTypes!! **** REVISIT!! bodyStrokeBrushTypeX = UtilityMutationFunctions.GetMutatedIntAdditive(parentGenome.bodyStrokeBrushTypeX, settings.bodyCoreSizeMutationChance, 2, 0, 7); // ***** bodyStrokeBrushTypeY = UtilityMutationFunctions.GetMutatedIntAdditive(parentGenome.bodyStrokeBrushTypeY, settings.bodyCoreSizeMutationChance, 2, 0, 3); eyeGenome = new EyeGenome(); eyeGenome.localPos = UtilityMutationFunctions.GetMutatedVector2Additive(parentGenome.eyeGenome.localPos, settings.bodyEyeProportionsMutationChance, settings.bodyEyeProportionsMutationStepSize, new Vector2(0.45f, 0.4f), new Vector2(1f, 1f)); // EYES SCALE IS: (x= size, y= aspectRatio) eyeGenome.localScale = UtilityMutationFunctions.GetMutatedVector2Additive(parentGenome.eyeGenome.localScale, settings.bodyEyeProportionsMutationChance, settings.bodyEyeProportionsMutationStepSize, new Vector2(1f, 1f), new Vector2(1f, 1f)); eyeGenome.irisHue = UtilityMutationFunctions.GetMutatedVector3Additive(parentGenome.eyeGenome.irisHue, settings.bodyEyeProportionsMutationChance, settings.bodyEyeProportionsMutationStepSize, 0f, 1f); eyeGenome.pupilHue = UtilityMutationFunctions.GetMutatedVector3Additive(parentGenome.eyeGenome.pupilHue, settings.bodyEyeProportionsMutationChance, settings.bodyEyeProportionsMutationStepSize, 0f, 1f); eyeGenome.eyeBrushType = UtilityMutationFunctions.GetMutatedIntAdditive(parentGenome.eyeGenome.eyeBrushType, settings.bodyEyeProportionsMutationChance, 7, 0, 7); //eyeGenome.pupilRadius = UtilityMutationFunctions.GetMutatedFloatAdditive(parentBodyGenome.eyeGenome.pupilRadius, settings.bodyEyeProportionsMutationChance, settings.bodyEyeProportionsMutationStepSize, 0.25f, 0.95f); }