Examples of DecompositionResult


Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

      alpha1[1][i] = pdeData2.getAlpha(0, x);
      beta1[1][i] = pdeData2.getBeta(0, x);
    }

    final boolean first = true;
    DecompositionResult decompRes = null;

    for (int n = 1; n < tNodes; n++) {

      t1 = grid.getTimeNode(n - 1);
      t2 = grid.getTimeNode(n);
      dt = grid.getTimeStep(n - 1);

      for (int i = 0; i < xNodes; i++) {
        x = grid.getSpaceNode(i);
        alpha2[0][i] = pdeData1.getAlpha(t2, x);
        beta2[0][i] = pdeData1.getBeta(t2, x);
        alpha2[1][i] = pdeData2.getAlpha(t2, x);
        beta2[1][i] = pdeData2.getBeta(t2, x);
      }

      for (int i = 1; i < xNodes - 1; i++) {
        x = grid.getSpaceNode(i);
        x1st = grid.getFirstDerivativeCoefficients(i);
        x2nd = grid.getSecondDerivativeCoefficients(i);

        q[i] = f[i];
        q[i] -= (1 - theta) * dt * (x2nd[0] * a1[0][i - 1] * alpha1[0][i - 1] + x1st[0] * b1[0][i - 1] * beta1[0][i - 1]) * f[i - 1];
        q[i] -= (1 - theta) * dt * (x2nd[1] * a1[0][i - 1] * alpha1[0][i] + x1st[1] * b1[0][i - 1] * beta1[0][i] + c1[0][i - 1]) * f[i];
        q[i] -= (1 - theta) * dt * (x2nd[2] * a1[0][i - 1] * alpha1[0][i + 1] + x1st[2] * b1[0][i - 1] * beta1[0][i + 1]) * f[i + 1];
        q[i] -= (1 - theta) * dt * lambda1 * f[i + xNodes];

        q[xNodes + i] = f[xNodes + i];
        q[xNodes + i] -= (1 - theta) * dt * (x2nd[0] * a1[1][i - 1] * alpha1[1][i - 1] + x1st[0] * b1[1][i - 1] * beta1[1][i - 1]) * f[xNodes + i - 1];
        q[xNodes + i] -= (1 - theta) * dt * (x2nd[1] * a1[1][i - 1] * alpha1[1][i] + x1st[1] * b1[1][i - 1] * beta1[1][i] + c1[1][i - 1]) * f[xNodes + i];
        q[xNodes + i] -= (1 - theta) * dt * (x2nd[2] * a1[1][i - 1] * alpha1[1][i + 1] + x1st[2] * b1[1][i - 1] * beta1[1][i + 1]) * f[xNodes + i + 1];
        q[xNodes + i] -= (1 - theta) * dt * lambda2 * f[i];

        a2[0][i - 1] = pdeData1.getA(t2, x);
        b2[0][i - 1] = pdeData1.getB(t2, x);
        c2[0][i - 1] = pdeData1.getC(t2, x);
        a2[1][i - 1] = pdeData2.getA(t2, x);
        b2[1][i - 1] = pdeData2.getB(t2, x);
        c2[1][i - 1] = pdeData2.getC(t2, x);

        m[i][i - 1] = theta * dt * (x2nd[0] * a2[0][i - 1] * alpha2[0][i - 1] + x1st[0] * b2[0][i - 1] * beta2[0][i - 1]);
        m[i][i] = 1 + theta * dt * (x2nd[1] * a2[0][i - 1] * alpha2[0][i] + x1st[1] * b2[0][i - 1] * beta2[0][i] + c2[0][i - 1]);
        m[i][i + 1] = theta * dt * (x2nd[2] * a2[0][i - 1] * alpha2[0][i + 1] + x1st[2] * b2[0][i - 1] * beta2[0][i + 1]);
        m[i][i + xNodes] = dt * theta * lambda1;

        m[xNodes + i][xNodes + i - 1] = theta * dt * (x2nd[0] * a2[1][i - 1] * alpha2[1][i - 1] + x1st[0] * b2[1][i - 1] * beta2[1][i - 1]);
        m[xNodes + i][xNodes + i] = 1 + theta * dt * (x2nd[1] * a2[1][i - 1] * alpha2[1][i] + x1st[1] * b2[1][i - 1] * beta2[1][i] + c2[1][i - 1]);
        m[xNodes + i][xNodes + i + 1] = theta * dt * (x2nd[2] * a2[1][i - 1] * alpha2[1][i + 1] + x1st[2] * b2[1][i - 1] * beta2[1][i + 1]);
        m[xNodes + i][i] = dt * theta * lambda2;
      }

      double[] temp = lowerBoundary1.getLeftMatrixCondition(null, grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[0][k] = temp[k];
      }

      temp = upperBoundary1.getLeftMatrixCondition(null, grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[xNodes - 1][xNodes - temp.length + k] = temp[k];
      }

      temp = lowerBoundary2.getLeftMatrixCondition(null, grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[xNodes][xNodes + k] = temp[k];
      }

      temp = upperBoundary2.getLeftMatrixCondition(null, grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[2 * xNodes - 1][2 * xNodes - temp.length + k] = temp[k];
      }

      temp = lowerBoundary1.getRightMatrixCondition(null, grid, t1);
      double sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[k];
      }
      q[0] = sum + lowerBoundary1.getConstant(null, t2);

      temp = upperBoundary1.getRightMatrixCondition(null, grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[xNodes - 1 - k];
      }

      q[xNodes - 1] = sum + upperBoundary1.getConstant(null, t2);

      temp = lowerBoundary2.getRightMatrixCondition(null, grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[k];
      }
      q[xNodes] = sum + lowerBoundary2.getConstant(null, t2);

      temp = upperBoundary2.getRightMatrixCondition(null, grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[xNodes - 1 - k];
      }

      q[2 * xNodes - 1] = sum + upperBoundary2.getConstant(null, t2);

      if (first) {
        final DoubleMatrix2D mM = new DoubleMatrix2D(m);
        decompRes = dcomp.evaluate(mM);
        // first = false;
      }
      f = decompRes.solve(q);

      a1[0] = Arrays.copyOf(a2[0], xNodes - 2);
      b1[0] = Arrays.copyOf(b2[0], xNodes - 2);
      c1[0] = Arrays.copyOf(c2[0], xNodes - 2);
      alpha1[0] = Arrays.copyOf(alpha2[0], xNodes);
View Full Code Here

Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

      b1[1][i] = coeff2.getB(0, x);
      c1[1][i] = coeff2.getC(0, x);
    }

    final boolean first = true;
    DecompositionResult decompRes = null;

    for (int n = 1; n < tNodes; n++) {

      t1 = grid.getTimeNode(n - 1);
      t2 = grid.getTimeNode(n);
      dt = grid.getTimeStep(n - 1);

      for (int i = 1; i < xNodes - 1; i++) {

        x = grid.getSpaceNode(i);
        x1st = grid.getFirstDerivativeCoefficients(i);
        x2nd = grid.getSecondDerivativeCoefficients(i);

        q[i] = f[i];
        q[i] -= (1 - _theta) * dt * (x2nd[0] * a1[0][i - 1] + x1st[0] * b1[0][i - 1]) * f[i - 1];
        q[i] -= (1 - _theta) * dt * (x2nd[1] * a1[0][i - 1] + x1st[1] * b1[0][i - 1] + c1[0][i - 1]) * f[i];
        q[i] -= (1 - _theta) * dt * (x2nd[2] * a1[0][i - 1] + x1st[2] * b1[0][i - 1]) * f[i + 1];
        q[i] -= (1 - _theta) * dt * lambda1 * f[i + xNodes];

        q[xNodes + i] = f[xNodes + i];
        q[xNodes + i] -= (1 - _theta) * dt * (x2nd[0] * a1[1][i - 1] + x1st[0] * b1[1][i - 1]) * f[xNodes + i - 1];
        q[xNodes + i] -= (1 - _theta) * dt * (x2nd[1] * a1[1][i - 1] + x1st[1] * b1[1][i - 1] + c1[1][i - 1]) * f[xNodes + i];
        q[xNodes + i] -= (1 - _theta) * dt * (x2nd[2] * a1[1][i - 1] + x1st[2] * b1[1][i - 1]) * f[xNodes + i + 1];
        q[xNodes + i] -= (1 - _theta) * dt * lambda2 * f[i];

        a2[0][i - 1] = coeff1.getA(t2, x);
        b2[0][i - 1] = coeff1.getB(t2, x);
        c2[0][i - 1] = coeff1.getC(t2, x);

        a2[1][i - 1] = coeff2.getA(t2, x);
        b2[1][i - 1] = coeff2.getB(t2, x);
        c2[1][i - 1] = coeff2.getC(t2, x);

        m[i][i - 1] = _theta * dt * (x2nd[0] * a2[0][i - 1] + x1st[0] * b2[0][i - 1]);
        m[i][i] = 1 + _theta * dt * (x2nd[1] * a2[0][i - 1] + x1st[1] * b2[0][i - 1] + c2[0][i - 1]);
        m[i][i + 1] = _theta * dt * (x2nd[2] * a2[0][i - 1] + x1st[2] * b2[0][i - 1]);
        m[i][i + xNodes] = dt * _theta * lambda1;

        m[xNodes + i][xNodes + i - 1] = _theta * dt * (x2nd[0] * a2[1][i - 1] + x1st[0] * b2[1][i - 1]);
        m[xNodes + i][xNodes + i] = 1 + _theta * dt * (x2nd[1] * a2[1][i - 1] + x1st[1] * b2[1][i - 1] + c2[1][i - 1]);
        m[xNodes + i][xNodes + i + 1] = _theta * dt * (x2nd[2] * a2[1][i - 1] + x1st[2] * b2[1][i - 1]);
        m[xNodes + i][i] = dt * _theta * lambda2;
      }

      double[] temp = lower1.getLeftMatrixCondition(pdeData1.getCoefficients(), grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[0][k] = temp[k];
      }

      temp = upper1.getLeftMatrixCondition(pdeData1.getCoefficients(), grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[xNodes - 1][xNodes - temp.length + k] = temp[k];
      }

      temp = lower2.getLeftMatrixCondition(pdeData2.getCoefficients(), grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[xNodes][xNodes + k] = temp[k];
      }

      temp = upper2.getLeftMatrixCondition(pdeData2.getCoefficients(), grid, t2);
      for (int k = 0; k < temp.length; k++) {
        m[2 * xNodes - 1][2 * xNodes - temp.length + k] = temp[k];
      }

      temp = lower1.getRightMatrixCondition(pdeData1.getCoefficients(), grid, t1);
      double sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[k];
      }
      q[0] = sum + lower1.getConstant(pdeData1.getCoefficients(), t2);

      temp = upper1.getRightMatrixCondition(pdeData1.getCoefficients(), grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[xNodes - 1 - k];
      }

      q[xNodes - 1] = sum + upper1.getConstant(pdeData1.getCoefficients(), t2);

      temp = lower2.getRightMatrixCondition(pdeData2.getCoefficients(), grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[k];
      }
      q[xNodes] = sum + lower2.getConstant(pdeData2.getCoefficients(), t2);

      temp = upper2.getRightMatrixCondition(pdeData2.getCoefficients(), grid, t1);
      sum = 0;
      for (int k = 0; k < temp.length; k++) {
        sum += temp[k] * f[xNodes - 1 - k];
      }

      q[2 * xNodes - 1] = sum + upper2.getConstant(pdeData2.getCoefficients(), t2);

      //TODO work out why SOR does not converge here
      //      final DoubleMatrix2D mM = new DoubleMatrix2D(m);
      //      final DecompositionResult res = DCOMP.evaluate(mM);
      //      f = res.solve(q);

      //      // SOR
      //
      //      int count = sor(omega, grid, freeBoundary, xNodes, f, q, m, t2);
      //      if (oldCount > 0) {
      //        if ((omegaIncrease && count > oldCount) || (!omegaIncrease && count < oldCount)) {
      //          omega = Math.max(1.0, omega * 0.9);
      //          omegaIncrease = false;
      //        } else {
      //          omega = Math.min(1.99, 1.1 * omega);
      //          omegaIncrease = true;
      //        }
      //      }
      //      oldCount = count;

      if (first) {
        final DoubleMatrix2D mM = new DoubleMatrix2D(m);
        decompRes = DCOMP.evaluate(mM);

        // first = false;
      }

      f = decompRes.solve(q);

      a1 = a2;
      b1 = b2;
      c1 = c2;

View Full Code Here

Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

    }

    @SuppressWarnings({"synthetic-access" })
    private void solveByLU() {
      final DoubleMatrix2D temp = new DoubleMatrix2D(_m);
      final DecompositionResult res = DCOMP.evaluate(temp);
      final double[] f = res.solve(_q);
      for (int i = 0; i < f.length; i++) {
        _f[i] = f[i];
      }
    }
View Full Code Here

Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

   */
  private LeastSquaresRegressionResult regress(final DoubleMatrix2D xDataMatrix, final DoubleMatrix1D yDataVector, final int nData, final int degree) {

    final Decomposition<QRDecompositionResult> qrComm = new QRDecompositionCommons();

    final DecompositionResult decompResult = qrComm.evaluate(xDataMatrix);
    _qrResult = (QRDecompositionResult) decompResult;

    final DoubleMatrix2D qMatrix = _qrResult.getQ();
    final DoubleMatrix2D rMatrix = _qrResult.getR();

View Full Code Here

Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

  @Override
  public DoubleMatrix2D getInitializedMatrix(final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianFunction, final DoubleMatrix1D x) {
    Validate.notNull(jacobianFunction);
    Validate.notNull(x);
    final DoubleMatrix2D estimate = jacobianFunction.evaluate(x);
    final DecompositionResult decompositionResult = _decomposition.evaluate(estimate);
    return decompositionResult.solve(DoubleMatrixUtils.getIdentityMatrix2D(x.getNumberOfElements()));
  }
View Full Code Here

Examples of com.opengamma.analytics.math.linearalgebra.DecompositionResult

  @Override
  public DoubleMatrix1D getDirection(final DoubleMatrix2D estimate, final DoubleMatrix1D y) {
    Validate.notNull(estimate);
    Validate.notNull(y);
    final DecompositionResult result = _decomposition.evaluate(estimate);
    return result.solve(y);
  }
View Full Code Here

Examples of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.DecompositionResult

    public DecompositionResult decompose(double[] data, int level) {//TODO check can we have approximation of size 3?
        Assert.argNotNull(data);
        Assert.argCondition(level >= 1, "Level argument must be >= 1.");
        Assert.argCondition(data.length >= 2, "Data length must be >= 2.");

        DecompositionResult result = new DecompositionResult();
        double[] approximation;
        double[] details;
        for (int i = 1; i <= level; ++i) {
            approximation = decomposeLow(data);
            details = decomposeHigh(data);
            result.setApproximation(approximation);
            result.addDetails(details);
            result.setLevel(i);
            if(approximation.length == 1) {
                break; //we can`t decompose more...
            }
            data = approximation; //approximation is data for next decomposition
        }
View Full Code Here

Examples of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.DecompositionResult

        DWTransform1D instance = new HaarWaveletTransform();
        double[] approximationExpect = {2.121320343559, 4.949747468305, 7.778174593052, 4.949747468305};
        double[] detailExpect = {-0.707106781186, -0.707106781186, -0.707106781186, 4.949747468306};

        DecompositionResult result = instance.decompose(data, 1);
        assertArrayEquals(approximationExpect, result.getApproximation(), DOBLE_COMPARISON_DELTA);
        assertArrayEquals(detailExpect, result.getDetailsList().get(0), DOBLE_COMPARISON_DELTA);
    }
View Full Code Here

Examples of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.DecompositionResult

        DWTransform1D instance = new HaarWaveletTransform();
        double[] approximationExpect = {2.121320343559, 4.949747468305, 7.778174593052, 4.949747468305};
        double[] detailExpect = {-0.707106781186, -0.707106781186, -0.707106781186, 4.949747468306};

        DecompositionResult result = instance.decompose(data, 1);
        assertArrayEquals(approximationExpect, result.getApproximation(), DOBLE_COMPARISON_DELTA);
        assertArrayEquals(detailExpect, result.getDetailsList().get(0), DOBLE_COMPARISON_DELTA);

        double[] reconstructed = instance.reconstruct(result);
        assertArrayEquals(data, reconstructed, DOBLE_COMPARISON_DELTA);
    }
View Full Code Here

Examples of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.DecompositionResult

    public void testReconstructionFrom2LevelDecomposition() {
        double[] data = {0, 1, 2, 3, 4, 5, 6, 7};

        DWTransform1D instance = new HaarWaveletTransform();

        DecompositionResult result = instance.decompose(data, 2);

        double[] reconstructed = instance.reconstruct(result);
        assertArrayEquals(data, reconstructed, DOBLE_COMPARISON_DELTA);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.