final Set<Integer> nanPositions = new HashSet<Integer>(); for (int i = 0; i < matrix.getColumnDimension(); i++) { nanPositions.addAll(getNaNPositions(matrix.getColumn(i))); matrix.getColumnDimension()); for (int i = 0; i < transformed.getColumnDimension(); i++) { transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions)); transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
fitfun.isFeasible(arxk.getColumn(0))) { break; fitness[k] = fitfun.value(arx.getColumn(k)); // compute fitness } catch (TooManyEvaluationsException e) { break generationLoop; bestValue = bestFitness; lastResult = optimum; optimum = new PointValuePair(fitfun.repair(bestArx.getColumn(0)), isMinimize ? bestFitness : -bestFitness); if (getConvergenceChecker() != null && lastResult != null && break generationLoop; final double[] sqrtDiagC = sqrt(diagC).getColumn(0); final double[] pcCol = pc.getColumn(0); for (int i = 0; i < dimension; i++) { if (sigma * FastMath.max(FastMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { = new PointValuePair(bestArx.getColumn(0), isMinimize ? bestFitness : -bestFitness); if (lastResult != null &&
public double[] getMean(int group){ MvNormalComponentDistribution mvnDist = (MvNormalComponentDistribution)compDistribution[group]; return mvnDist.getMean().getColumn(0); }
/** * Computes the Kendall's Tau rank correlation matrix for the columns of * the input matrix. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix */ public RealMatrix computeCorrelationMatrix(final RealMatrix matrix) { int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }
@Override public Object doWork(Object value) throws IOException{ if(null == value){ return null; } else if (value instanceof Matrix) { //First transpose the matrix Matrix matrix = (Matrix) value; double[][] data = matrix.getData(); RealMatrix realMatrix = new Array2DRowRealMatrix(data, false); List<Number> sums = new ArrayList(data[0].length); for(int i=0; i<data[0].length; i++) { double sum = 0; double[] col = realMatrix.getColumn(i); for(int j=0; j<col.length; j++){ sum+=col[j]; } sums.add(sum); } return sums; } else { throw new IOException("Grand sum function only operates on a matrix"); } } }
fitfun.isFeasible(arxk.getColumn(0))) { break; valuePenaltyPairs[k] = fitfun.value(arx.getColumn(k)); // compute fitness } catch (TooManyEvaluationsException e) { break generationLoop; bestValue = bestFitness; lastResult = optimum; optimum = new PointValuePair(fitfun.repair(bestArx.getColumn(0)), isMinimize ? bestFitness : -bestFitness); if (getConvergenceChecker() != null && lastResult != null && break generationLoop; final double[] sqrtDiagC = sqrt(diagC).getColumn(0); final double[] pcCol = pc.getColumn(0); for (int i = 0; i < dimension; i++) { if (sigma * FastMath.max(FastMath.abs(pcCol[i]), sqrtDiagC[i]) > stopTolX) { = new PointValuePair(bestArx.getColumn(0), isMinimize ? bestFitness : -bestFitness); if (lastResult != null &&
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least one column and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }
public TetradVector getColumn(int j) { if (zeroDimension()) { return new TetradVector(rows()); } return new TetradVector(apacheData.getColumn(j)); }
/** * Computes the correlation matrix for the columns of the * input matrix, using {@link #correlation(double[], double[])}. * * Throws MathIllegalArgumentException if the matrix does not have at least * two columns and two rows. Pairwise correlations are set to NaN if one * of the correlates has zero variance. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data * @see #correlation(double[], double[]) */ public RealMatrix computeCorrelationMatrix(RealMatrix matrix) { checkSufficientData(matrix); int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }
public void generateStartValues(RealMatrix x, RealMatrix mean, RealMatrix cov){ JDKRandomGenerator jg = new JDKRandomGenerator(); NormalizedRandomGenerator rg = new GaussianRandomGenerator(jg); CorrelatedRandomVectorGenerator sg = null; sg = new CorrelatedRandomVectorGenerator(mean.getColumn(0), cov, 0.00001, rg); mu = new Array2DRowRealMatrix(sg.nextVector()); }
/** * Compute the column means. * * @param matrix Matrix target * @return Array with the column means */ private double[] colMeans(RealMatrix matrix) { double sum; double[] column; double[] mean = new double[matrix.getColumnDimension()]; for (int i = 0; i < matrix.getColumnDimension(); i++) { sum = 0; column = matrix.getColumn(i); for (int j = 0; j < column.length; j++) { sum += column[j]; } mean[i] = sum / column.length; } return mean; }
/** * Computes the Kendall's Tau rank correlation matrix for the columns of * the input matrix. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix */ public RealMatrix computeCorrelationMatrix(final RealMatrix matrix) { int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }
final Set<Integer> nanPositions = new HashSet<Integer>(); for (int i = 0; i < matrix.getColumnDimension(); i++) { nanPositions.addAll(getNaNPositions(matrix.getColumn(i))); matrix.getColumnDimension()); for (int i = 0; i < transformed.getColumnDimension(); i++) { transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions)); transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
final Set<Integer> nanPositions = new HashSet<Integer>(); for (int i = 0; i < matrix.getColumnDimension(); i++) { nanPositions.addAll(getNaNPositions(matrix.getColumn(i))); matrix.getColumnDimension()); for (int i = 0; i < transformed.getColumnDimension(); i++) { transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions)); transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
/** * Computes the Kendall's Tau rank correlation matrix for the columns of * the input matrix. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix */ public RealMatrix computeCorrelationMatrix(final RealMatrix matrix) { int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least one column and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least one column and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }
/** * Computes the correlation matrix for the columns of the * input matrix, using {@link #correlation(double[], double[])}. * * Throws MathIllegalArgumentException if the matrix does not have at least * two columns and two rows. Pairwise correlations are set to NaN if one * of the correlates has zero variance. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data * @see #correlation(double[], double[]) */ public RealMatrix computeCorrelationMatrix(RealMatrix matrix) { checkSufficientData(matrix); int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }
/** * Computes the correlation matrix for the columns of the * input matrix, using {@link #correlation(double[], double[])}. * * Throws MathIllegalArgumentException if the matrix does not have at least * two columns and two rows. Pairwise correlations are set to NaN if one * of the correlates has zero variance. * * @param matrix matrix with columns representing variables to correlate * @return correlation matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data * @see #correlation(double[], double[]) */ public RealMatrix computeCorrelationMatrix(RealMatrix matrix) { checkSufficientData(matrix); int nVars = matrix.getColumnDimension(); RealMatrix outMatrix = new BlockRealMatrix(nVars, nVars); for (int i = 0; i < nVars; i++) { for (int j = 0; j < i; j++) { double corr = correlation(matrix.getColumn(i), matrix.getColumn(j)); outMatrix.setEntry(i, j, corr); outMatrix.setEntry(j, i, corr); } outMatrix.setEntry(i, i, 1d); } return outMatrix; }