public static double ComputeFitness(IInd inputInd) { double[] squaredErrors = new double[_dataSet.Count]; for (int i = 0; i < _dataSet.Count; i++) { double sP = 0; var line = _dataSet[i]; for (int j = 0; j < line.Length-1; j++) { var dataValue = line[j]; var indValue = inputInd.getDoubleArray()[j]; sP += (dataValue*indValue); } squaredErrors[i] = Math.Pow((line[line.Length - 1] - sP), 2); } return squaredErrors.Sum(); }
public static IInd Mutation(IInd inpStringInd, double rate) { double[] values = inpStringInd.getDoubleArray(); for (int i = 0; i < values.Length; i++) { var r = Rand.NextDouble(); if (r <= rate) { values[i] = Rand.NextDouble() * (maxVal - minVal) + minVal; } } IInd res = new DoubleInd(values); return res; }