internal Population GeneratePopulation() { var factory = new God(_config, Inputs, NumOutputs); _population = new Population(_config, this); for (int i = 0; i < _config.PopSize; i++) { _population[i] = factory.BuildGenome(); } return _population; }
internal override void Fitness(Population pop) { var sumsOfSquares = new double[pop.Size]; sumsOfSquares.Initialize(); int i = 0; for (double x = LeftLim; x < RightLim; x += Step, i++) { _inputs[0].Value = x; Parallel.For(0, pop.Size, j => { double actual = pop[j].Outputs[0].Solve(); double error = _sine.Points[i].YValues[0] - actual; sumsOfSquares[j] += error * error; }); } Parallel.For(0, pop.Size, (j, loop) => { pop[j].Fitness = sumsOfSquares[j];// +(pop[j].Outputs[0].Count > 100 ? pop[j].Outputs[0].Count : 0); }); }
internal void Run() { for (int i = 0; i < _config.Generations; i++) { _population.Evaluate(); _population = _population.Next; } }
internal abstract void Fitness(Population pop);