예제 #1
0
    public override void CloneFrom(BaseGenome source)
    {
        GenomeFloatString s = source as GenomeFloatString;

        for (int i = 0; i < floats.Length; i++)
        {
            floats[i] = s.floats[i];
        }
    }
예제 #2
0
    public override void OnePointCrossover(BaseGenome mom, BaseGenome dad, int point)
    {
        GenomeFloatString m = mom as GenomeFloatString;
        GenomeFloatString d = dad as GenomeFloatString;

        for (int i = 0; i < floats.Length; i++)
        {
            floats[i] = (i < point ? m : d).floats[i];
        }
    }
예제 #3
0
	public override void Init(BaseGenome genome) {
		base.Init(genome);

		GenomeFloatString gfs = genome as GenomeFloatString;
		neuralNet = new NeuralNet(new int[]{5, 8, 3}, gfs.GetArray());

		sensors = new float[5+1];
		sensors[5] = 0;
		totalDistance = 0;
	}
예제 #4
0
파일: Car.cs 프로젝트: KalleSjostrom/Genome
 public void Init(GenomeFloatString genome)
 {
     neuronNet = new NeuronNet(new int[]{5, 8, 3}, genome.GetArray());
     sensors = new float[5+1];
     for (int i = 0; i < directions.Length; i++) {
         directions[i].Normalize();
     }
     sensors[5] = 0;
     totalDistance = 0;
     Duration = 0;
     isDone = false;
     initialized = true;
 }
예제 #5
0
 public void Init(GenomeFloatString genome)
 {
     neuronNet = new NeuronNet(new int[] { 5, 8, 3 }, genome.GetArray());
     sensors   = new float[5 + 1];
     for (int i = 0; i < directions.Length; i++)
     {
         directions[i].Normalize();
     }
     sensors[5]    = 0;
     totalDistance = 0;
     Duration      = 0;
     isDone        = false;
     initialized   = true;
 }
예제 #6
0
    // This operator adds a unit Gaussian distributed random value to the chosen gene. If it falls outside of the user-specified lower or upper bounds for that gene,the new gene value is clipped. This mutation operator can only be used for integer and float genes.
    public override void Mutate(Population population, GeneticAlgorithm.NextStepDelegate callback)
    {
        for (int i = 0; i < population.Size; i++)
        {
            if (Random.value > mutationProbability)
            {
                continue;
            }

            GenomeFloatString genome = population[i].Genome as GenomeFloatString;
            float[]           floats = genome.GetArray();
            int nrMutations          = Random.Range(0, (int)Mathf.Round(bitMutationFraction * genome.Length));
            for (int j = 0; j < nrMutations; j++)
            {
                floats[j] += Random.Range(-0.1f, 0.1f);
            }
        }
        callback();
    }