/** * Get the row from the tableau. * @param row the row index * @return the reference to the underlying row data */ protected final double[] getRow(int row) { return tableau.getDataRef()[row]; }
/** Rescale the instance. * <p>Since the scaled and Nordsieck arrays are shared with the caller, * this method has the side effect of rescaling this arrays in the caller too.</p> * @param stepSize new step size to use in the scaled and Nordsieck arrays */ public void rescale(final double stepSize) { final double ratio = stepSize / scalingH; for (int i = 0; i < scaled.length; ++i) { scaled[i] *= ratio; } final double[][] nData = nordsieck.getDataRef(); double power = ratio; for (int i = 0; i < nData.length; ++i) { power *= ratio; final double[] nDataI = nData[i]; for (int j = 0; j < nDataI.length; ++j) { nDataI[j] *= power; } } scalingH = stepSize; }
/** 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]); } } }
/** {@inheritDoc} */ @Override protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH) { final double x = interpolatedTime - referenceTime; final double normalizedAbscissa = x / scalingH; Arrays.fill(stateVariation, 0.0); Arrays.fill(interpolatedDerivatives, 0.0); // apply Taylor formula from high order to low order, // for the sake of numerical accuracy final double[][] nData = nordsieck.getDataRef(); for (int i = nData.length - 1; i >= 0; --i) { final int order = i + 2; final double[] nDataI = nData[i]; final double power = FastMath.pow(normalizedAbscissa, order); for (int j = 0; j < nDataI.length; ++j) { final double d = nDataI[j] * power; stateVariation[j] += d; interpolatedDerivatives[j] += order * d; } } for (int j = 0; j < currentState.length; ++j) { stateVariation[j] += scaled[j] * normalizedAbscissa; interpolatedState[j] = currentState[j] + stateVariation[j]; interpolatedDerivatives[j] = (interpolatedDerivatives[j] + scaled[j] * normalizedAbscissa) / x; } }
/** Copy constructor. * @param interpolator interpolator to copy from. The copy is a deep * copy: its arrays are separated from the original arrays of the * instance */ public NordsieckStepInterpolator(final NordsieckStepInterpolator interpolator) { super(interpolator); scalingH = interpolator.scalingH; referenceTime = interpolator.referenceTime; if (interpolator.scaled != null) { scaled = interpolator.scaled.clone(); } if (interpolator.nordsieck != null) { nordsieck = new Array2DRowRealMatrix(interpolator.nordsieck.getDataRef(), true); } if (interpolator.stateVariation != null) { stateVariation = interpolator.stateVariation.clone(); } }
double[][] augIData = augI.getDataRef(); for (int i = 0; i < n; i++) { for (int j =0; j < n; j++) {
matrix.setEntry(zIndex, zIndex, maximize ? 1 : -1); RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.toArray(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1, maximize ? f.getConstantTerm() : -1 * f.getConstantTerm()); copyArray(constraint.getCoefficients().toArray(), matrix.getDataRef()[row]);
RealVector objectiveCoefficients = maximize ? f.getCoefficients().mapMultiply(-1) : f.getCoefficients(); copyArray(objectiveCoefficients.toArray(), matrix.getDataRef()[zIndex]); matrix.setEntry(zIndex, width - 1, maximize ? f.getConstantTerm() : -1 * f.getConstantTerm()); copyArray(constraint.getCoefficients().toArray(), matrix.getDataRef()[row]);
/** * Get the row from the tableau. * @param row the row index * @return the reference to the underlying row data */ protected final double[] getRow(int row) { return tableau.getDataRef()[row]; }
/** * Get the row from the tableau. * @param row the row index * @return the reference to the underlying row data */ protected final double[] getRow(int row) { return tableau.getDataRef()[row]; }
/** Rescale the instance. * <p>Since the scaled and Nordsieck arrays are shared with the caller, * this method has the side effect of rescaling this arrays in the caller too.</p> * @param stepSize new step size to use in the scaled and Nordsieck arrays */ public void rescale(final double stepSize) { final double ratio = stepSize / scalingH; for (int i = 0; i < scaled.length; ++i) { scaled[i] *= ratio; } final double[][] nData = nordsieck.getDataRef(); double power = ratio; for (int i = 0; i < nData.length; ++i) { power *= ratio; final double[] nDataI = nData[i]; for (int j = 0; j < nDataI.length; ++j) { nDataI[j] *= power; } } scalingH = stepSize; }
/** Rescale the instance. * <p>Since the scaled and Nordsieck arrays are shared with the caller, * this method has the side effect of rescaling this arrays in the caller too.</p> * @param stepSize new step size to use in the scaled and Nordsieck arrays */ public void rescale(final double stepSize) { final double ratio = stepSize / scalingH; for (int i = 0; i < scaled.length; ++i) { scaled[i] *= ratio; } final double[][] nData = nordsieck.getDataRef(); double power = ratio; for (int i = 0; i < nData.length; ++i) { power *= ratio; final double[] nDataI = nData[i]; for (int j = 0; j < nDataI.length; ++j) { nDataI[j] *= power; } } scalingH = stepSize; }
/** 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]); } } }
@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()); }
Array2DRowRealMatrix matrix2 = new Array2DRowRealMatrix(data2, false); Array2DRowRealMatrix matrix3 = matrix1.add(matrix2); return new Matrix(matrix3.getDataRef()); } else { throw new IOException("Parameters for ebeAdd must either be two numeric arrays or two matrices. ");
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; }
/** Copy constructor. * @param interpolator interpolator to copy from. The copy is a deep * copy: its arrays are separated from the original arrays of the * instance */ public NordsieckStepInterpolator(final NordsieckStepInterpolator interpolator) { super(interpolator); scalingH = interpolator.scalingH; referenceTime = interpolator.referenceTime; if (interpolator.scaled != null) { scaled = interpolator.scaled.clone(); } if (interpolator.nordsieck != null) { nordsieck = new Array2DRowRealMatrix(interpolator.nordsieck.getDataRef(), true); } if (interpolator.stateVariation != null) { stateVariation = interpolator.stateVariation.clone(); } }
/** Copy constructor. * @param interpolator interpolator to copy from. The copy is a deep * copy: its arrays are separated from the original arrays of the * instance */ public NordsieckStepInterpolator(final NordsieckStepInterpolator interpolator) { super(interpolator); scalingH = interpolator.scalingH; referenceTime = interpolator.referenceTime; if (interpolator.scaled != null) { scaled = Cloner.clone(interpolator.scaled); } if (interpolator.nordsieck != null) { nordsieck = new Array2DRowRealMatrix(interpolator.nordsieck.getDataRef(), true); } if (interpolator.stateVariation != null) { stateVariation = Cloner.clone(interpolator.stateVariation); } }
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"); } } }