Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
 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;
 }