Esempio n. 1
0
 public Vector Normalize()
 {
     Vector vector = new Vector(this.NRows);
     double num = this.Length();
     for (int i = 0; i < this.NRows; i++)
     {
         vector[i] = this.double_0[i] / num;
     }
     return vector;
 }
Esempio n. 2
0
 private void method_0(Func<Vector, double> func_1, Vector vector_6, Vector vector_7, Vector vector_8)
 {
     this.func_0 = func_1;
     this.vector_0 = vector_6;
     this.vector_1 = vector_7;
     if (!(vector_7 >= vector_6))
     {
         throw new Exception("Combination of bounding vectors is not valid.");
     }
     if (vector_8 != null)
     {
         this.vector_3 = vector_8;
     }
     else
     {
         this.vector_3 = (vector_7 - vector_6) / 2.0;
     }
     this.double_8 = func_1(this.vector_3);
     this.vector_2 = this.vector_3;
     this.vector_4 = this.vector_3;
     this.vector_5 = this.vector_3;
     this.double_7 = this.double_8;
     this.double_9 = this.double_8;
     this.double_10 = this.double_8;
     this.double_11 = 0.0;
     this.double_12 = 0.0;
     this.int_2 = 1;
     this.int_3 = 1;
     this.int_4 = 0;
     this.int_5 = 0;
     this.double_0 = 0.8;
     this.double_1 = 0.001;
     this.double_3 = -1.0 / Math.Log(this.double_0);
     this.double_4 = -1.0 / Math.Log(this.double_1);
     this.double_5 = this.double_3;
     this.double_6 = Math.Pow(this.double_4 / this.double_3, 1.0 / ((double)this.NC - 1.0));
     this.random_0 = new Random();
 }
Esempio n. 3
0
 public Vector Run(Func<Vector, double> func, Vector xl, Vector xu, Vector x0 = null)
 {
     this.method_0(func, xl, xu, x0);
     for (int i = 0; i < this.NC; i++)
     {
         for (int j = 0; j < this.NT; j++)
         {
             this.method_1();
         }
         this.double_5 *= this.double_6;
     }
     if (this.OutputEnabled)
     {
         Console.WriteLine();
         Console.WriteLine("Best function : " + this.double_10);
         this.vector_5.Print("Best coordiantes : ", "0.00");
         Console.WriteLine();
         Console.WriteLine("Accepted : " + this.int_2);
         Console.WriteLine("Rejected : " + this.int_3);
         Console.WriteLine("Accepted uphills : " + this.int_4);
         Console.WriteLine("Rejected uphills : " + this.int_5);
     }
     return this.vector_5;
 }
Esempio n. 4
0
 public object Clone()
 {
     Vector vector = new Vector(this.NRows);
     for (int i = 0; i < this.NRows; i++)
     {
         vector[i] = this[i];
     }
     return vector;
 }
Esempio n. 5
0
 public static Vector Min(Vector vector1, Vector vector2)
 {
     if (vector1.NRows != vector2.NRows)
     {
         throw new Exception("Can not perform min operation for vectors with different sizes.");
     }
     Vector vector3 = new Vector(vector1.NRows);
     for (int i = 0; i < vector1.NRows; i++)
     {
         vector3[i] = Math.Min(vector1[i], vector2[i]);
     }
     return vector3;
 }
Esempio n. 6
0
 public static Vector Rand(int nrows)
 {
     Vector vector = new Vector(nrows);
     for (int i = 0; i < nrows; i++)
     {
         vector[i] = Vector.random.NextDouble();
     }
     return vector;
 }
Esempio n. 7
0
 public static Vector operator -(Vector vector1, Vector vector2)
 {
     if (vector1.NRows != vector2.NRows)
     {
         throw new Exception("Can not subtract vectors with different sizes.");
     }
     Vector vector3 = new Vector(vector1.NRows);
     for (int i = 0; i < vector1.NRows; i++)
     {
         vector3[i] = vector1[i] - vector2[i];
     }
     return vector3;
 }
Esempio n. 8
0
 public static Vector operator -(double x, Vector vector)
 {
     Vector vector2 = new Vector(vector.NRows);
     for (int i = 0; i < vector.NRows; i++)
     {
         vector2[i] = x - vector[i];
     }
     return vector2;
 }
Esempio n. 9
0
 public static Vector operator -(Vector vector, double x)
 {
     Vector vector2 = new Vector(vector.NRows);
     for (int i = 0; i < vector.NRows; i++)
     {
         vector2[i] = vector[i] - x;
     }
     return vector2;
 }
Esempio n. 10
0
 public Chromosome Mutate(Chromosome chromosome, Bounds bounds)
 {
     Vector vector = new Vector(bounds.Lower.NRows);
     for (int i = 0; i < vector.NRows; i++)
     {
         vector[i] = GeneticAlgorithm.Random.NextDouble()*(bounds.Upper[i] - bounds.Lower[i]) + bounds.Lower[i];
     }
     return new Chromosome(vector);
 }
Esempio n. 11
0
 public Chromosome Cross(Chromosome chromosome1, Chromosome chromosome2, Bounds bounds)
 {
     int nRows = chromosome1.Vector.NRows;
     Vector vector = new Vector(nRows);
     for (int i = 0; i < nRows; i++)
     {
         double num = Math.Min(chromosome1.Vector[i], chromosome2.Vector[i]);
         double expr_55 = Math.Max(chromosome1.Vector[i], chromosome2.Vector[i]);
         double num2 = (expr_55 - num)*this.Alpha;
         double num3 = Math.Max(num - num2, bounds.Lower[i]);
         double num4 = Math.Min(expr_55 + num2, bounds.Upper[i]);
         double num5 = GeneticAlgorithm.Random.NextDouble();
         vector[i] = num5*(num4 - num3) + num3;
         if (this.IsPorfolioOptimization)
         {
             if (num5 < 0.1)
             {
                 vector[i] = bounds.Lower[i];
             }
             else if (num5 < 0.2)
             {
                 vector[i] = bounds.Upper[i];
             }
         }
     }
     return new Chromosome(vector);
 }
Esempio n. 12
0
 public Bounds(Vector lower, Vector upper)
 {
     Lower = lower;
     Upper = upper;
 }
Esempio n. 13
0
 public Vector StdDev(int index1, int index2)
 {
     Vector vector = new Vector(this.Nrows);
     for (int i = 0; i < this.Nrows; i++)
     {
         vector[i] = this.StdDev(i, index1, index2);
     }
     return vector;
 }
Esempio n. 14
0
 public Vector Variance(int index1, int index2)
 {
     Vector vector = new Vector(this.Nrows);
     for (int i = 0; i < this.Nrows; i++)
     {
         vector[i] = this.Variance(i, index1, index2);
     }
     return vector;
 }