Ejemplo n.º 1
1
    private CMAParameters(CMAParameters original, Cloner cloner)
      : base(original, cloner) {
      this.AxisRatio = original.AxisRatio;
      if (original.B != null) this.B = (double[,])original.B.Clone();
      if (original.BDz != null) this.BDz = (double[])original.BDz.Clone();
      if (original.C != null) this.C = (double[,])original.C.Clone();
      this.CCov = original.CCov;
      this.CCovSep = original.CCovSep;
      this.CC = original.CC;
      this.ChiN = original.ChiN;
      this.CS = original.CS;
      if (original.D != null) this.D = (double[])original.D.Clone();
      this.Damps = original.Damps;
      this.InitialIterations = original.InitialIterations;
      this.Mu = original.Mu;
      this.MuCov = original.MuCov;
      this.MuEff = original.MuEff;
      if (original.PC != null) this.PC = (double[])original.PC.Clone();
      if (original.PS != null) this.PS = (double[])original.PS.Clone();
      this.Sigma = original.Sigma;
      if (original.SigmaBounds != null) this.SigmaBounds = (double[,])original.SigmaBounds.Clone();
      if (original.Weights != null) this.Weights = (double[])original.Weights.Clone();

      if (original.QualityHistory != null) this.QualityHistory = new Queue<double>(original.QualityHistory);
      this.QualityHistorySize = original.QualityHistorySize;
    }
Ejemplo n.º 2
0
        private CMAParameters(CMAParameters original, Cloner cloner)
            : base(original, cloner)
        {
            this.AxisRatio = original.AxisRatio;
            if (original.B != null)
            {
                this.B = (double[, ])original.B.Clone();
            }
            if (original.BDz != null)
            {
                this.BDz = (double[])original.BDz.Clone();
            }
            if (original.C != null)
            {
                this.C = (double[, ])original.C.Clone();
            }
            this.CCov    = original.CCov;
            this.CCovSep = original.CCovSep;
            this.CC      = original.CC;
            this.ChiN    = original.ChiN;
            this.CS      = original.CS;
            if (original.D != null)
            {
                this.D = (double[])original.D.Clone();
            }
            this.Damps             = original.Damps;
            this.InitialIterations = original.InitialIterations;
            this.Mu    = original.Mu;
            this.MuCov = original.MuCov;
            this.MuEff = original.MuEff;
            if (original.PC != null)
            {
                this.PC = (double[])original.PC.Clone();
            }
            if (original.PS != null)
            {
                this.PS = (double[])original.PS.Clone();
            }
            this.Sigma = original.Sigma;
            if (original.SigmaBounds != null)
            {
                this.SigmaBounds = (double[, ])original.SigmaBounds.Clone();
            }
            if (original.Weights != null)
            {
                this.Weights = (double[])original.Weights.Clone();
            }

            if (original.QualityHistory != null)
            {
                this.QualityHistory = new Queue <double>(original.QualityHistory);
            }
            this.QualityHistorySize = original.QualityHistorySize;
        }
Ejemplo n.º 3
0
    public override IOperation Apply() {
      var N = DimensionParameter.ActualValue.Value;
      var lambda = PopulationSizeParameter.ActualValue.Value;
      var mu = MuParameter.ActualValue;

      var sp = new CMAParameters();
      sp.Mu = mu == null ? (int)Math.Floor(lambda / 2.0) : mu.Value;
      sp.QualityHistorySize = 10 + 30 * N / lambda;
      sp.QualityHistory = new Queue<double>(sp.QualityHistorySize + 1);

      var s = InitialSigmaParameter.ActualValue;
      if (s == null || s.Length == 0) throw new InvalidOperationException("Initial standard deviation (sigma) must be given.");
      var sigma = s.Max();
      if (sigma <= 0) throw new InvalidOperationException("Initial standard deviation (sigma) must be > 0.");

      var pc = new double[N]; // evolution paths for C
      var ps = new double[N]; // evolution paths for sigma
      var B = new double[N, N]; // B defines the coordinate system
      var D = new double[N]; // diagonal D defines the scaling
      var C = new double[N, N]; // covariance matrix C
      var BDz = new double[N];
      double minSqrtdiagC = int.MaxValue, maxSqrtdiagC = int.MinValue;
      for (int i = 0; i < N; i++) {
        B[i, i] = 1;
        if (s.Length == 1) D[i] = 1;
        else if (s.Length == N) D[i] = s[i] / sigma;
        else throw new InvalidOperationException("Initial standard deviation (sigma) must either contain only one value for all dimension or for every dimension.");
        if (D[i] <= 0) throw new InvalidOperationException("Initial standard deviation (sigma) values must all be > 0.");
        C[i, i] = D[i] * D[i];
        if (Math.Sqrt(C[i, i]) < minSqrtdiagC) minSqrtdiagC = Math.Sqrt(C[i, i]);
        if (Math.Sqrt(C[i, i]) > maxSqrtdiagC) maxSqrtdiagC = Math.Sqrt(C[i, i]);
      }

      // ensure maximal and minimal standard deviations
      var sigmaBounds = SigmaBoundsParameter.ActualValue;
      if (sigmaBounds != null && sigmaBounds.Rows > 0) {
        for (int i = 0; i < N; i++) {
          var d = sigmaBounds[Math.Min(i, sigmaBounds.Rows - 1), 0];
          if (d > sigma * minSqrtdiagC) sigma = d / minSqrtdiagC;
        }
        for (int i = 0; i < N; i++) {
          var d = sigmaBounds[Math.Min(i, sigmaBounds.Rows - 1), 1];
          if (d > sigma * maxSqrtdiagC) sigma = d / maxSqrtdiagC;
        }
      }
      // end ensure ...

      // testAndCorrectNumerics
      double fac = 1;
      if (D.Max() < 1e-6)
        fac = 1.0 / D.Max();
      else if (D.Min() > 1e4)
        fac = 1.0 / D.Min();

      if (fac != 1.0) {
        sigma /= fac;
        for (int i = 0; i < N; i++) {
          pc[i] *= fac;
          D[i] *= fac;
          for (int j = 0; j < N; j++)
            C[i, j] *= fac * fac;
        }
      }
      // end testAndCorrectNumerics

      var initialIterations = InitialIterationsParameter.ActualValue;
      if (initialIterations == null) {
        initialIterations = new IntValue(0);
      }

      double maxD = D.Max(), minD = D.Min();
      if (minD == 0) sp.AxisRatio = double.PositiveInfinity;
      else sp.AxisRatio = maxD / minD;
      sp.PC = pc;
      sp.PS = ps;
      sp.B = B;
      sp.D = D;
      sp.C = C;
      sp.BDz = BDz;
      sp.Sigma = sigma;
      if (sigmaBounds != null) {
        sp.SigmaBounds = new double[sigmaBounds.Rows, sigmaBounds.Columns];
        for (int i = 0; i < sigmaBounds.Rows; i++)
          for (int j = 0; j < sigmaBounds.Columns; j++)
            sp.SigmaBounds[i, j] = sigmaBounds[i, j];
      }
      sp.InitialIterations = initialIterations.Value;

      StrategyParametersParameter.ActualValue = sp;
      return base.Apply();
    }
Ejemplo n.º 4
0
        public override IOperation Apply()
        {
            var N      = DimensionParameter.ActualValue.Value;
            var lambda = PopulationSizeParameter.ActualValue.Value;
            var mu     = MuParameter.ActualValue;

            var sp = new CMAParameters();

            sp.Mu = mu == null ? (int)Math.Floor(lambda / 2.0) : mu.Value;
            sp.QualityHistorySize = 10 + 30 * N / lambda;
            sp.QualityHistory     = new Queue <double>(sp.QualityHistorySize + 1);

            var s = InitialSigmaParameter.ActualValue;

            if (s == null || s.Length == 0)
            {
                throw new InvalidOperationException("Initial standard deviation (sigma) must be given.");
            }
            var sigma = s.Max();

            if (sigma <= 0)
            {
                throw new InvalidOperationException("Initial standard deviation (sigma) must be > 0.");
            }

            var    pc = new double[N];   // evolution paths for C
            var    ps = new double[N];   // evolution paths for sigma
            var    B = new double[N, N]; // B defines the coordinate system
            var    D = new double[N];    // diagonal D defines the scaling
            var    C = new double[N, N]; // covariance matrix C
            var    BDz = new double[N];
            double minSqrtdiagC = int.MaxValue, maxSqrtdiagC = int.MinValue;

            for (int i = 0; i < N; i++)
            {
                B[i, i] = 1;
                if (s.Length == 1)
                {
                    D[i] = 1;
                }
                else if (s.Length == N)
                {
                    D[i] = s[i] / sigma;
                }
                else
                {
                    throw new InvalidOperationException("Initial standard deviation (sigma) must either contain only one value for all dimension or for every dimension.");
                }
                if (D[i] <= 0)
                {
                    throw new InvalidOperationException("Initial standard deviation (sigma) values must all be > 0.");
                }
                C[i, i] = D[i] * D[i];
                if (Math.Sqrt(C[i, i]) < minSqrtdiagC)
                {
                    minSqrtdiagC = Math.Sqrt(C[i, i]);
                }
                if (Math.Sqrt(C[i, i]) > maxSqrtdiagC)
                {
                    maxSqrtdiagC = Math.Sqrt(C[i, i]);
                }
            }

            // ensure maximal and minimal standard deviations
            var sigmaBounds = SigmaBoundsParameter.ActualValue;

            if (sigmaBounds != null && sigmaBounds.Rows > 0)
            {
                for (int i = 0; i < N; i++)
                {
                    var d = sigmaBounds[Math.Min(i, sigmaBounds.Rows - 1), 0];
                    if (d > sigma * minSqrtdiagC)
                    {
                        sigma = d / minSqrtdiagC;
                    }
                }
                for (int i = 0; i < N; i++)
                {
                    var d = sigmaBounds[Math.Min(i, sigmaBounds.Rows - 1), 1];
                    if (d > sigma * maxSqrtdiagC)
                    {
                        sigma = d / maxSqrtdiagC;
                    }
                }
            }
            // end ensure ...

            // testAndCorrectNumerics
            double fac = 1;

            if (D.Max() < 1e-6)
            {
                fac = 1.0 / D.Max();
            }
            else if (D.Min() > 1e4)
            {
                fac = 1.0 / D.Min();
            }

            if (fac != 1.0)
            {
                sigma /= fac;
                for (int i = 0; i < N; i++)
                {
                    pc[i] *= fac;
                    D[i]  *= fac;
                    for (int j = 0; j < N; j++)
                    {
                        C[i, j] *= fac * fac;
                    }
                }
            }
            // end testAndCorrectNumerics

            var initialIterations = InitialIterationsParameter.ActualValue;

            if (initialIterations == null)
            {
                initialIterations = new IntValue(0);
            }

            double maxD = D.Max(), minD = D.Min();

            if (minD == 0)
            {
                sp.AxisRatio = double.PositiveInfinity;
            }
            else
            {
                sp.AxisRatio = maxD / minD;
            }
            sp.PC    = pc;
            sp.PS    = ps;
            sp.B     = B;
            sp.D     = D;
            sp.C     = C;
            sp.BDz   = BDz;
            sp.Sigma = sigma;
            if (sigmaBounds != null)
            {
                sp.SigmaBounds = new double[sigmaBounds.Rows, sigmaBounds.Columns];
                for (int i = 0; i < sigmaBounds.Rows; i++)
                {
                    for (int j = 0; j < sigmaBounds.Columns; j++)
                    {
                        sp.SigmaBounds[i, j] = sigmaBounds[i, j];
                    }
                }
            }
            sp.InitialIterations = initialIterations.Value;

            StrategyParametersParameter.ActualValue = sp;
            return(base.Apply());
        }