/// <summary> /// Copy constructor. /// </summary> /// <param name="copyFrom"></param> public ConnectionMutationParameterGroup(ConnectionMutationParameterGroup copyFrom) { ActivationProportion = copyFrom.ActivationProportion; PerturbationType = copyFrom.PerturbationType; SelectionType = copyFrom.SelectionType; Proportion = copyFrom.Proportion; Quantity = copyFrom.Quantity; PerturbationFactor = copyFrom.PerturbationFactor; Sigma = copyFrom.Sigma; }
private void MutateConnectionWeight(ConnectionGene connectionGene, NeatParameters np, ConnectionMutationParameterGroup paramGroup) { switch(paramGroup.PerturbationType) { case ConnectionPerturbationType.JiggleEven: { connectionGene.Weight += (Utilities.NextDouble()*2-1.0) * paramGroup.PerturbationFactor; // Cap the connection weight. Large connections weights reduce the effectiveness of the search. connectionGene.Weight = Math.Max(connectionGene.Weight, -np.connectionWeightRange/2.0); connectionGene.Weight = Math.Min(connectionGene.Weight, np.connectionWeightRange/2.0); break; } case ConnectionPerturbationType.JiggleND: { connectionGene.Weight += RandLib.gennor(0, paramGroup.Sigma); // Cap the connection weight. Large connections weights reduce the effectiveness of the search. connectionGene.Weight = Math.Max(connectionGene.Weight, -np.connectionWeightRange/2.0); connectionGene.Weight = Math.Min(connectionGene.Weight, np.connectionWeightRange/2.0); break; } case ConnectionPerturbationType.Reset: { // TODO: Precalculate connectionWeightRange / 2. connectionGene.Weight = (Utilities.NextDouble()*np.connectionWeightRange) - np.connectionWeightRange/2.0; break; } default: { throw new Exception("Unexpected ConnectionPerturbationType"); } } }