protected double[][] evaluate(double[][] d1) throws EvaluationException { Array2DRowRealMatrix temp = new Array2DRowRealMatrix(d1); return temp.transpose().getData(); } };
final RealMatrix tmpMatrix = covMatEigenvectors.transpose();
protected double[][] evaluate(double[][] d1) throws EvaluationException { Array2DRowRealMatrix temp = new Array2DRowRealMatrix(d1); return temp.transpose().getData(); } };
/** * @deprecated avoid calculating matrix inverse, better use the solve methods */ @Deprecated public static final double[][] lowerTriangularMatrixInverse(double[][] L) throws Exception { double[][] LT = new Array2DRowRealMatrix(L).transpose().getData(); double[][] x = upperTriangularMatrixInverse(LT); return new Array2DRowRealMatrix(x).transpose().getData(); }
private void updateProjectionMatrix(){ final float zF = (float) (viewDepth * 1.5); final float zN = (float) (TRFactory.mapSquareSize / 10); final float fH = (float) (1. / Math.tan(getHorizontalFOVDegrees() * Math.PI / 360.)); final float fV = (float) (1. / Math.tan(getVerticalFOVDegrees() * Math.PI / 360.)); projectionMatrix = new Array2DRowRealMatrix(new double[][] { new double[] { fH , 0, 0, 0 }, new double[] { 0, fV, 0, 0 }, new double[] { 0, 0, (zF + zN) / (zN - zF), -1f }, new double[] { 0, 0, (2f * zF * zN) / (zN - zF), 0 } }).transpose(); } /**
EigenDecomposition eig = new EigenDecomposition(matA.transpose().multiply(matA));
public double[] scale(double[] predictors) { double[][] data = observations.getData(); //We need to scale the columns of the data matrix with along with the predictors Array2DRowRealMatrix matrix = new Array2DRowRealMatrix(data); Array2DRowRealMatrix transposed = (Array2DRowRealMatrix) matrix.transpose(); double[][] featureRows = transposed.getDataRef(); double[] scaledPredictors = new double[predictors.length]; for(int i=0; i<featureRows.length; i++) { double[] featureRow = featureRows[i]; double[] combinedFeatureRow = new double[featureRow.length+1]; System.arraycopy(featureRow, 0, combinedFeatureRow, 0, featureRow.length); combinedFeatureRow[featureRow.length] = predictors[i]; // Add the last feature from the predictor double[] scaledFeatures = MinMaxScaleEvaluator.scale(combinedFeatureRow, 0, 1); scaledPredictors[i] = scaledFeatures[featureRow.length]; System.arraycopy(scaledFeatures, 0, featureRow, 0, featureRow.length); } Array2DRowRealMatrix scaledFeatureMatrix = new Array2DRowRealMatrix(featureRows); Array2DRowRealMatrix scaledObservationsMatrix= (Array2DRowRealMatrix)scaledFeatureMatrix.transpose(); this.scaledObservations = new Matrix(scaledObservationsMatrix.getDataRef()); return scaledPredictors; }
/** * @deprecated avoid calculating matrix inverse, better use the solve methods */ @Deprecated public static final double[][] upperTriangularMatrixInverse(double[][] L) throws Exception { // Solve L*X = Id int dim = L.length; double[][] x = Utils.createConstantDiagonalMatrix(dim, 1.); for (int j = 0; j < dim; j++) { final double[] LJ = L[j]; final double LJJ = LJ[j]; final double[] xJ = x[j]; for (int k = 0; k < dim; ++k) { xJ[k] /= LJJ; } for (int i = j + 1; i < dim; i++) { final double[] xI = x[i]; final double LJI = LJ[i]; for (int k = 0; k < dim; ++k) { xI[k] -= xJ[k] * LJI; } } } return new Array2DRowRealMatrix(x).transpose().getData(); }
/** * Gets the correlation coefficients. * * @param data the data * @return the correlation coefficients */ protected List<Double> getCorrelationCoefficients(final double[][] data) { int n = data.length; int m = data[0].length; List<Double> correlationCoefficients = new LinkedList<Double>(); for (int i = 0; i < n; i++) { double[][] x = new double[n - 1][m]; int k = 0; for (int j = 0; j < n; j++) { if (j != i) { x[k++] = data[j]; } } // Transpose the matrix so that it fits the linear model double[][] xT = new Array2DRowRealMatrix(x).transpose().getData(); // RSquare is the "coefficient of determination" correlationCoefficients.add(MathUtil.createLinearRegression(xT, data[i]).calculateRSquared()); } return correlationCoefficients; }
/** * Gets the correlation coefficients. * * @param data the data * @return the correlation coefficients */ protected List<Double> getCorrelationCoefficients(final double[][] data) { int n = data.length; int m = data[0].length; List<Double> correlationCoefficients = new LinkedList<Double>(); for (int i = 0; i < n; i++) { double[][] x = new double[n - 1][m]; int k = 0; for (int j = 0; j < n; j++) { if (j != i) { x[k++] = data[j]; } } // Transpose the matrix so that it fits the linear model double[][] xT = new Array2DRowRealMatrix(x).transpose().getData(); // RSquare is the "coefficient of determination" correlationCoefficients.add(MathUtil.createLinearRegression(xT, data[i]).calculateRSquared()); } return correlationCoefficients; }
/** * Gets the correlation coefficients. * * @param data the data * @return the correlation coefficients */ protected List<Double> getCorrelationCoefficients(final double[][] data) { int n = data.length; int m = data[0].length; List<Double> correlationCoefficients = new LinkedList<Double>(); for (int i = 0; i < n; i++) { double[][] x = new double[n - 1][m]; int k = 0; for (int j = 0; j < n; j++) { if (j != i) { x[k++] = data[j]; } } // Transpose the matrix so that it fits the linear model double[][] xT = new Array2DRowRealMatrix(x).transpose().getData(); // RSquare is the "coefficient of determination" correlationCoefficients.add(MathUtil.createLinearRegression(xT, data[i]).calculateRSquared()); } return correlationCoefficients; }
/** * Gets the correlation coefficients. * * @param data the data * @return the correlation coefficients */ protected List<Double> getCorrelationCoefficients(final double[][] data) { final int rows = data.length; final int cols = data[0].length; final List<Double> correlationCoefficients = new LinkedList<>(); for (int i = 0; i < rows; i++) { final double[][] x = new double[rows - 1][cols]; int k = 0; for (int j = 0; j < rows; j++) { if (j != i) { x[k++] = data[j]; } } // Transpose the matrix so that it fits the linear model final double[][] xT = new Array2DRowRealMatrix(x).transpose().getData(); // RSquare is the "coefficient of determination" correlationCoefficients.add( MathUtil.createLinearRegression(xT, data[i]).calculateRSquared()); } return correlationCoefficients; }
public Matrix scale(Matrix predictors) { double[][] observationData = observations.getData(); //We need to scale the columns of the data matrix with along with the predictors Array2DRowRealMatrix observationMatrix = new Array2DRowRealMatrix(observationData); Array2DRowRealMatrix observationTransposed = (Array2DRowRealMatrix) observationMatrix.transpose(); double[][] observationFeatureRows = observationTransposed.getDataRef(); double[][] predictorsData = predictors.getData(); //We need to scale the columns of the data matrix with along with the predictors Array2DRowRealMatrix predictorMatrix = new Array2DRowRealMatrix(predictorsData); Array2DRowRealMatrix predictorTransposed = (Array2DRowRealMatrix) predictorMatrix.transpose(); double[][] predictorFeatureRows = predictorTransposed.getDataRef(); for(int i=0; i<observationFeatureRows.length; i++) { double[] observationFeatureRow = observationFeatureRows[i]; double[] predictorFeatureRow = predictorFeatureRows[i]; double[] combinedFeatureRow = new double[observationFeatureRow.length+predictorFeatureRow.length]; System.arraycopy(observationFeatureRow, 0, combinedFeatureRow, 0, observationFeatureRow.length); System.arraycopy(predictorFeatureRow, 0, combinedFeatureRow, observationFeatureRow.length, predictorFeatureRow.length); double[] scaledFeatures = MinMaxScaleEvaluator.scale(combinedFeatureRow, 0, 1); System.arraycopy(scaledFeatures, 0, observationFeatureRow, 0, observationFeatureRow.length); System.arraycopy(scaledFeatures, observationFeatureRow.length, predictorFeatureRow, 0, predictorFeatureRow.length); } Array2DRowRealMatrix scaledFeatureMatrix = new Array2DRowRealMatrix(observationFeatureRows); Array2DRowRealMatrix scaledObservationsMatrix= (Array2DRowRealMatrix)scaledFeatureMatrix.transpose(); this.scaledObservations = new Matrix(scaledObservationsMatrix.getDataRef()); Array2DRowRealMatrix scaledPredictorMatrix = new Array2DRowRealMatrix(predictorFeatureRows); Array2DRowRealMatrix scaledTransposedPredictorMatrix= (Array2DRowRealMatrix)scaledPredictorMatrix.transpose(); return new Matrix(scaledTransposedPredictorMatrix.getDataRef()); }
private Matrix distance(DistanceMeasure distanceMeasure, Matrix matrix) { double[][] data = matrix.getData(); Array2DRowRealMatrix realMatrix = new Array2DRowRealMatrix(data, false); realMatrix = (Array2DRowRealMatrix)realMatrix.transpose(); data = realMatrix.getDataRef(); double[][] distanceMatrix = new double[data.length][data.length]; for(int i=0; i<data.length; i++) { double[] row = data[i]; for(int j=0; j<data.length; j++) { double[] row2 = data[j]; double dist = distanceMeasure.compute(row, row2); distanceMatrix[i][j] = dist; } } return new Matrix(distanceMatrix); } }
@Override public Object doWork(Object value) throws IOException{ if(null == value){ return null; } else if(value instanceof Matrix) { Matrix matrix = (Matrix) value; double[][] data = matrix.getData(); Array2DRowRealMatrix amatrix = new Array2DRowRealMatrix(data, false); Array2DRowRealMatrix tmatrix = (Array2DRowRealMatrix)amatrix.transpose(); Matrix newMatrix = new Matrix(tmatrix.getDataRef()); //Switch the row and column labels newMatrix.setColumnLabels(matrix.getRowLabels()); newMatrix.setRowLabels(matrix.getColumnLabels()); return newMatrix; } else { throw new IOException("matrix parameter expected for transpose function"); } } }
final RealMatrix tmpMatrix = covMatEigenvectors.transpose();
final RealMatrix tmpMatrix = covMatEigenvectors.transpose();