Java Code Examples for org.apache.commons.math3.linear.Array2DRowRealMatrix#getDataRef()

The following examples show how to use org.apache.commons.math3.linear.Array2DRowRealMatrix#getDataRef() . 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: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Compute the "hat" matrix.
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * <p>The implementation here uses the QR decomposition to compute the
 * hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
 * p-dimensional identity matrix augmented by 0's.  This computational
 * formula is from "The Hat Matrix in Regression and ANOVA",
 * David C. Hoaglin and Roy E. Welsch,
 * <i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
 * </p>
 * <p>Data for the model must have been successfully loaded using one of
 * the {@code newSampleData} methods before invoking this method; otherwise
 * a {@code NullPointerException} will be thrown.</p>
 *
 * @return the hat matrix
 */
public RealMatrix calculateHat() {
    // Create augmented identity matrix
    RealMatrix Q = qr.getQ();
    final int p = qr.getR().getColumnDimension();
    final int n = Q.getColumnDimension();
    // No try-catch or advertised NotStrictlyPositiveException - NPE above if n < 3
    Array2DRowRealMatrix augI = new Array2DRowRealMatrix(n, n);
    double[][] augIData = augI.getDataRef();
    for (int i = 0; i < n; i++) {
        for (int j =0; j < n; j++) {
            if (i == j && i < p) {
                augIData[i][j] = 1d;
            } else {
                augIData[i][j] = 0d;
            }
        }
    }

    // Compute and return Hat matrix
    // No DME advertised - args valid if we get here
    return Q.multiply(augI).multiply(Q.transpose());
}
 
Example 2
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Compute the "hat" matrix.
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * <p>The implementation here uses the QR decomposition to compute the
 * hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
 * p-dimensional identity matrix augmented by 0's.  This computational
 * formula is from "The Hat Matrix in Regression and ANOVA",
 * David C. Hoaglin and Roy E. Welsch,
 * <i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
 * </p>
 * <p>Data for the model must have been successfully loaded using one of
 * the {@code newSampleData} methods before invoking this method; otherwise
 * a {@code NullPointerException} will be thrown.</p>
 *
 * @return the hat matrix
 * @throws NullPointerException unless method {@code newSampleData} has been
 * called beforehand.
 */
public RealMatrix calculateHat() {
    // Create augmented identity matrix
    RealMatrix Q = qr.getQ();
    final int p = qr.getR().getColumnDimension();
    final int n = Q.getColumnDimension();
    // No try-catch or advertised NotStrictlyPositiveException - NPE above if n < 3
    Array2DRowRealMatrix augI = new Array2DRowRealMatrix(n, n);
    double[][] augIData = augI.getDataRef();
    for (int i = 0; i < n; i++) {
        for (int j =0; j < n; j++) {
            if (i == j && i < p) {
                augIData[i][j] = 1d;
            } else {
                augIData[i][j] = 0d;
            }
        }
    }

    // Compute and return Hat matrix
    // No DME advertised - args valid if we get here
    return Q.multiply(augI).multiply(Q.transpose());
}
 
Example 3
Source File: KnnRegressionEvaluator.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Compute the "hat" matrix.
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * <p>The implementation here uses the QR decomposition to compute the
 * hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
 * p-dimensional identity matrix augmented by 0's.  This computational
 * formula is from "The Hat Matrix in Regression and ANOVA",
 * David C. Hoaglin and Roy E. Welsch,
 * <i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
 *
 * @return the hat matrix
 */
public RealMatrix calculateHat() {
    // Create augmented identity matrix
    RealMatrix Q = qr.getQ();
    final int p = qr.getR().getColumnDimension();
    final int n = Q.getColumnDimension();
    Array2DRowRealMatrix augI = new Array2DRowRealMatrix(n, n);
    double[][] augIData = augI.getDataRef();
    for (int i = 0; i < n; i++) {
        for (int j =0; j < n; j++) {
            if (i == j && i < p) {
                augIData[i][j] = 1d;
            } else {
                augIData[i][j] = 0d;
            }
        }
    }

    // Compute and return Hat matrix
    return Q.multiply(augI).multiply(Q.transpose());
}
 
Example 5
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Compute the "hat" matrix.
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * <p>The implementation here uses the QR decomposition to compute the
 * hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
 * p-dimensional identity matrix augmented by 0's.  This computational
 * formula is from "The Hat Matrix in Regression and ANOVA",
 * David C. Hoaglin and Roy E. Welsch,
 * <i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
 *
 * @return the hat matrix
 */
public RealMatrix calculateHat() {
    // Create augmented identity matrix
    RealMatrix Q = qr.getQ();
    final int p = qr.getR().getColumnDimension();
    final int n = Q.getColumnDimension();
    Array2DRowRealMatrix augI = new Array2DRowRealMatrix(n, n);
    double[][] augIData = augI.getDataRef();
    for (int i = 0; i < n; i++) {
        for (int j =0; j < n; j++) {
            if (i == j && i < p) {
                augIData[i][j] = 1d;
            } else {
                augIData[i][j] = 0d;
            }
        }
    }

    // Compute and return Hat matrix
    return Q.multiply(augI).multiply(Q.transpose());
}
 
Example 6
Source File: OLSMultipleLinearRegression.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Compute the "hat" matrix.
 * </p>
 * <p>The hat matrix is defined in terms of the design matrix X
 *  by X(X<sup>T</sup>X)<sup>-1</sup>X<sup>T</sup>
 * </p>
 * <p>The implementation here uses the QR decomposition to compute the
 * hat matrix as Q I<sub>p</sub>Q<sup>T</sup> where I<sub>p</sub> is the
 * p-dimensional identity matrix augmented by 0's.  This computational
 * formula is from "The Hat Matrix in Regression and ANOVA",
 * David C. Hoaglin and Roy E. Welsch,
 * <i>The American Statistician</i>, Vol. 32, No. 1 (Feb., 1978), pp. 17-22.
 * </p>
 * <p>Data for the model must have been successfully loaded using one of
 * the {@code newSampleData} methods before invoking this method; otherwise
 * a {@code NullPointerException} will be thrown.</p>
 *
 * @return the hat matrix
 * @throws NullPointerException unless method {@code newSampleData} has been
 * called beforehand.
 */
public RealMatrix calculateHat() {
    // Create augmented identity matrix
    RealMatrix Q = qr.getQ();
    final int p = qr.getR().getColumnDimension();
    final int n = Q.getColumnDimension();
    // No try-catch or advertised NotStrictlyPositiveException - NPE above if n < 3
    Array2DRowRealMatrix augI = new Array2DRowRealMatrix(n, n);
    double[][] augIData = augI.getDataRef();
    for (int i = 0; i < n; i++) {
        for (int j =0; j < n; j++) {
            if (i == j && i < p) {
                augIData[i][j] = 1d;
            } else {
                augIData[i][j] = 0d;
            }
        }
    }

    // Compute and return Hat matrix
    // No DME advertised - args valid if we get here
    return Q.multiply(augI).multiply(Q.transpose());
}
 
Example 7
Source File: TransposeEvaluator.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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");
  }
}
 
Example 8
Source File: DemoMihcComputation.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private static void fastMultiply(final Array2DRowRealMatrix mat, final double[] v, final double[] out) {
    final int n = v.length;
    for (int row = 0; row < n; row++) {
        final double[] dataRow = mat.getDataRef()[row];
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += dataRow[i] * v[i];
        }
        out[row] = sum;
    }
}
 
Example 9
Source File: EBESubtractEvaluator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public Object doWork(Object first, Object second) throws IOException{
  if(null == first){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
  }
  if(null == second){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
  }
  if(first instanceof List && second instanceof List) {
    double[] result = MathArrays.ebeSubtract(
        ((List) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(),
        ((List) second).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray()
    );

    List<Number> numbers = new ArrayList<>();
    for (double d : result) {
      numbers.add(d);
    }

    return numbers;
  } else if(first instanceof Matrix && second instanceof Matrix) {
    double[][] data1 = ((Matrix) first).getData();
    double[][] data2 = ((Matrix) second).getData();
    Array2DRowRealMatrix matrix1 = new Array2DRowRealMatrix(data1, false);
    Array2DRowRealMatrix matrix2 = new Array2DRowRealMatrix(data2, false);
    Array2DRowRealMatrix matrix3 = matrix1.subtract(matrix2);
    return new Matrix(matrix3.getDataRef());
  } else {
    throw new IOException("Parameters for ebeSubtract must either be two numeric arrays or two matrices. ");
  }
}
 
Example 10
Source File: MatrixMultiplyEvaluator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Object doWork(Object first, Object second) throws IOException {
  if(null == first){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
  }
  if(null == second){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
  }

  Array2DRowRealMatrix realMatrix1 = getMatrix(first);
  Array2DRowRealMatrix realMatrix2 = getMatrix(second);
  Array2DRowRealMatrix realMatrix3 = realMatrix1.multiply(realMatrix2);
  return new Matrix(realMatrix3.getDataRef());

}
 
Example 11
Source File: KnnRegressionEvaluator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 12
Source File: MultiplexImageReader.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private void fastMultiply(final Array2DRowRealMatrix mat, final double[] v, final double[] out) {
    final int n = v.length;
    for (int row = 0; row < n; row++) {
        final double[] dataRow = mat.getDataRef()[row];
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += dataRow[i] * v[i];
        }
        out[row] = sum;
    }
}
 
Example 13
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 14
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 15
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 16
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 17
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 18
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 19
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}
 
Example 20
Source File: AdamsNordsieckTransformer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Update the high order scaled derivatives Adams integrators (phase 2).
 * <p>The complete update of high order derivatives has a form similar to:
 * <pre>
 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
 * </pre>
 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
 * <p>Phase 1 of the update must already have been performed.</p>
 * @param start first order scaled derivatives at step start
 * @param end first order scaled derivatives at step end
 * @param highOrder high order scaled derivatives, will be modified
 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
 */
public void updateHighOrderDerivativesPhase2(final double[] start,
                                             final double[] end,
                                             final Array2DRowRealMatrix highOrder) {
    final double[][] data = highOrder.getDataRef();
    for (int i = 0; i < data.length; ++i) {
        final double[] dataI = data[i];
        final double c1I = c1[i];
        for (int j = 0; j < dataI.length; ++j) {
            dataI[j] += c1I * (start[j] - end[j]);
        }
    }
}