private void CreateInitialRandomGeneration3(int _seed) { //Inititally assume exponents are 0, 1, 2, 3, ... mTerms mGenes = new Matrices.Vector <double>(Terms); Random rand = new Random(DateTime.Now.Millisecond); byte[] buffer = new byte[1]; int sign = 0; for (int j = 0; j < Terms; j++) { for (int i = 0; i <= _seed * 2; i++) { rand.NextBytes(buffer); } sign = buffer[0] % 2; if (sign == 0) { sign = -1; } if (MaxFuntionValue == 0 && MinFuntionValue == 0) { mGenes[j] = Math.Round(Math.Sqrt(rand.NextDouble()) * sign, 3); } else { mGenes[j] = rand.NextDouble() * MaxFuntionValue + MinFuntionValue; } } }
public IndividualDNA(int _Terms, PointPair _MinMaxFunctionValue) { mTerms = _Terms; mFitness = 0; mGenes = new Matrices.Vector <double>(mTerms); mError = new List <PointPair>(); mGeneration = 0; mMinFuntionValue = _MinMaxFunctionValue.X; mMaxFuntionValue = _MinMaxFunctionValue.Y; }
public double GetApproximationPointValue(Matrices.Vector <double> _individual, double _x) { double value = 0; for (int i = 0; i < _individual.Dimension; i++) { value = value + _individual[i] * Math.Pow(_x, i); } return(value); }
private void CreateInitialRandomGeneration3(int _seed) { //Inititally assume exponents are 0, 1, 2, 3, ... mTerms mGenes = new Matrices.Vector<double>(Terms); Random rand = new Random(DateTime.Now.Millisecond); byte[] buffer = new byte[1]; int sign = 0; for (int j = 0; j < Terms; j++) { for (int i = 0; i <= _seed * 2; i++) { rand.NextBytes(buffer); } sign = buffer[0] % 2; if (sign == 0) sign = -1; if (MaxFuntionValue == 0 && MinFuntionValue == 0) { mGenes[j] = Math.Round(Math.Sqrt(rand.NextDouble()) * sign, 3); } else { mGenes[j] = rand.NextDouble() * MaxFuntionValue + MinFuntionValue; } } }
public IndividualDNA(int _Terms, PointPair _MinMaxFunctionValue) { mTerms = _Terms; mFitness = 0; mGenes = new Matrices.Vector<double>(mTerms); mError = new List<PointPair>(); mGeneration = 0; mMinFuntionValue = _MinMaxFunctionValue.X; mMaxFuntionValue = _MinMaxFunctionValue.Y; }