Java Code Examples for org.apache.commons.math3.linear.MatrixUtils#createColumnRealMatrix()
The following examples show how to use
org.apache.commons.math3.linear.MatrixUtils#createColumnRealMatrix() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OLSTrendLine.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@Override public void setValues( double[] y, double[] x ) { if (x.length != y.length) { throw new IllegalArgumentException( String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length)); } double[][] xData = new double[x.length][]; for( int i = 0; i < x.length; i++ ) { // the implementation determines how to produce a vector of predictors from a single x xData[i] = xVector(x[i]); } if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were // given for( int i = 0; i < x.length; i++ ) { y[i] = Math.log(y[i]); } } ols = new OLSMultipleLinearRegression(); ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired ols.newSampleData(y, xData); // provide the data to the model coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); }
Example 2
Source File: Arja_00177_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 3
Source File: Arja_00181_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 4
Source File: Arja_00181_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 5
Source File: Arja_0028_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 6
Source File: Arja_0028_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 7
Source File: Math_6_CMAESOptimizer_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { throw new NotStrictlyPositiveException(lambda); } // initialize sigma final double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { sigmaArray[i][0] = inputSigma[i]; } final RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1 / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4 + mueff / dimension) / (dimension + 4 + 2 * mueff / dimension); cs = (mueff + 2) / (dimension + mueff + 3.); damps = (1 + 2 * Math.max(0, Math.sqrt((mueff - 1) / (dimension + 1)) - 1)) * Math.max(0.3, 1 - dimension / (1e-6 + maxIterations)) + cs; // minor increment ccov1 = 2 / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / ((dimension + 2) * (dimension + 2) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); chiN = Math.sqrt(dimension) * (1 - 1 / ((double) 4 * dimension) + 1 / ((double) 21 * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective variables diagD = insigma.scalarMultiply(1 / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3 * 10 * dimension / (double) lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 8
Source File: Cardumen_0037_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 9
Source File: Arja_00154_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 10
Source File: Arja_00177_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 11
Source File: CMAESOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { // XXX Line below to replace the current one in 4.0 (MATH-879). // throw new NotStrictlyPositiveException(lambda); lambda = 4 + (int) (3 * Math.log(dimension)); } // initialize sigma final double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { // XXX Line below to replace the current one in 4.0 (MATH-868). // sigmaArray[i][0] = inputSigma[i]; sigmaArray[i][0] = inputSigma == null ? 0.3 : inputSigma[i]; } final RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1 / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4 + mueff / dimension) / (dimension + 4 + 2 * mueff / dimension); cs = (mueff + 2) / (dimension + mueff + 3.); damps = (1 + 2 * Math.max(0, Math.sqrt((mueff - 1) / (dimension + 1)) - 1)) * Math.max(0.3, 1 - dimension / (1e-6 + maxIterations)) + cs; // minor increment ccov1 = 2 / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / ((dimension + 2) * (dimension + 2) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); chiN = Math.sqrt(dimension) * (1 - 1 / ((double) 4 * dimension) + 1 / ((double) 21 * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective variables diagD = insigma.scalarMultiply(1 / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3 * 10 * dimension / (double) lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 12
Source File: Math_18_CMAESOptimizer_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 13
Source File: CMAESOptimizer_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 14
Source File: CMAESOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { throw new NotStrictlyPositiveException(lambda); } // initialize sigma final double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { sigmaArray[i][0] = inputSigma[i]; } final RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1 / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4 + mueff / dimension) / (dimension + 4 + 2 * mueff / dimension); cs = (mueff + 2) / (dimension + mueff + 3.); damps = (1 + 2 * Math.max(0, Math.sqrt((mueff - 1) / (dimension + 1)) - 1)) * Math.max(0.3, 1 - dimension / (1e-6 + maxIterations)) + cs; // minor increment ccov1 = 2 / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2 * (mueff - 2 + 1 / mueff) / ((dimension + 2) * (dimension + 2) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3); chiN = Math.sqrt(dimension) * (1 - 1 / ((double) 4 * dimension) + 1 / ((double) 21 * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective variables diagD = insigma.scalarMultiply(1 / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3 * 10 * dimension / (double) lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 15
Source File: CMAESOptimizer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 16
Source File: Cardumen_00161_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = (getMaxEvaluations()) / (dimension); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 17
Source File: Cardumen_00213_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 18
Source File: Cardumen_0037_s.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 19
Source File: Cardumen_00211_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }
Example 20
Source File: Cardumen_0035_t.java From coming with MIT License | 4 votes |
/** * Initialization of the dynamic search parameters * * @param guess Initial guess for the arguments of the fitness function. */ private void initializeCMA(double[] guess) { if (lambda <= 0) { lambda = 4 + (int) (3. * Math.log(dimension)); } // initialize sigma double[][] sigmaArray = new double[guess.length][1]; for (int i = 0; i < guess.length; i++) { final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i]; sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range; } RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false); sigma = max(insigma); // overall standard deviation // initialize termination criteria stopTolUpX = 1e3 * max(insigma); stopTolX = 1e-11 * max(insigma); stopTolFun = 1e-12; stopTolHistFun = 1e-13; // initialize selection strategy parameters mu = lambda / 2; // number of parents/points for recombination logMu2 = Math.log(mu + 0.5); weights = log(sequence(1, mu, 1)).scalarMultiply(-1.).scalarAdd(logMu2); double sumw = 0; double sumwq = 0; for (int i = 0; i < mu; i++) { double w = weights.getEntry(i, 0); sumw += w; sumwq += w * w; } weights = weights.scalarMultiply(1. / sumw); mueff = sumw * sumw / sumwq; // variance-effectiveness of sum w_i x_i // initialize dynamic strategy parameters and constants cc = (4. + mueff / dimension) / (dimension + 4. + 2. * mueff / dimension); cs = (mueff + 2.) / (dimension + mueff + 3.); damps = (1. + 2. * Math.max(0, Math.sqrt((mueff - 1.) / (dimension + 1.)) - 1.)) * Math.max(0.3, 1. - dimension / (1e-6 + Math.min(maxIterations, getMaxEvaluations() / lambda))) + cs; // minor increment ccov1 = 2. / ((dimension + 1.3) * (dimension + 1.3) + mueff); ccovmu = Math.min(1 - ccov1, 2. * (mueff - 2. + 1. / mueff) / ((dimension + 2.) * (dimension + 2.) + mueff)); ccov1Sep = Math.min(1, ccov1 * (dimension + 1.5) / 3.); ccovmuSep = Math.min(1 - ccov1, ccovmu * (dimension + 1.5) / 3.); chiN = Math.sqrt(dimension) * (1. - 1. / (4. * dimension) + 1 / (21. * dimension * dimension)); // intialize CMA internal values - updated each generation xmean = MatrixUtils.createColumnRealMatrix(guess); // objective // variables diagD = insigma.scalarMultiply(1. / sigma); diagC = square(diagD); pc = zeros(dimension, 1); // evolution paths for C and sigma ps = zeros(dimension, 1); // B defines the coordinate system normps = ps.getFrobeniusNorm(); B = eye(dimension, dimension); D = ones(dimension, 1); // diagonal D defines the scaling BD = times(B, repmat(diagD.transpose(), dimension, 1)); C = B.multiply(diag(square(D)).multiply(B.transpose())); // covariance historySize = 10 + (int) (3. * 10. * dimension / lambda); fitnessHistory = new double[historySize]; // history of fitness values for (int i = 0; i < historySize; i++) { fitnessHistory[i] = Double.MAX_VALUE; } }