当前位置: 首页>>代码示例>>Java>>正文


Java Matrix.multAdd方法代码示例

本文整理汇总了Java中no.uib.cipr.matrix.Matrix.multAdd方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.multAdd方法的具体用法?Java Matrix.multAdd怎么用?Java Matrix.multAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在no.uib.cipr.matrix.Matrix的用法示例。


在下文中一共展示了Matrix.multAdd方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    A.multAdd(-1, x, r.set(b));

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        M.apply(r, z);
        x.add(z);
        A.multAdd(-1, x, r.set(b));
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:15,代码来源:IR.java

示例2: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double alpha = 0, beta = 0, rho = 0, rho_1 = 0;

    A.multAdd(-1, x, r.set(b));

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        M.apply(r, z);
        rho = r.dot(z);

        if (iter.isFirst())
            p.set(z);
        else {
            beta = rho / rho_1;
            p.scale(beta).add(z);
        }

        A.mult(p, q);
        alpha = rho / p.dot(q);

        x.add(alpha, p);
        r.add(-alpha, q);

        rho_1 = rho;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:31,代码来源:CG.java

示例3: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double rho_1 = 1, rho_2 = 1, alpha = 1, beta = 1;

    A.multAdd(-1, x, r.set(b));
    rtilde.set(r);

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        M.apply(r, z);
        M.transApply(rtilde, ztilde);
        rho_1 = z.dot(rtilde);

        if (rho_1 == 0.)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "rho", iter);

        if (iter.isFirst()) {
            p.set(z);
            ptilde.set(ztilde);
        } else {
            beta = rho_1 / rho_2;
            p.scale(beta).add(z);
            ptilde.scale(beta).add(ztilde);
        }

        A.mult(p, q);
        A.transMult(ptilde, qtilde);

        alpha = rho_1 / ptilde.dot(q);
        x.add(alpha, p);
        r.add(-alpha, q);
        rtilde.add(-alpha, qtilde);

        rho_2 = rho_1;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:41,代码来源:BiCG.java

示例4: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double alpha = 0, beta = 0, c = 0, d = 0;

    A.multAdd(-1, x, r.set(b));

    c = (eigmax - eigmin) / 2.0;
    d = (eigmax + eigmin) / 2.0;

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        M.apply(r, z);

        if (iter.isFirst()) {
            p.set(z);
            alpha = 2.0 / d;
        } else {
            beta = (alpha * c) / 2.0;
            beta *= beta;
            alpha = 1.0 / (d - beta);
            p.scale(beta).add(z);
        }

        A.mult(p, q);
        x.add(alpha, p);
        r.add(-alpha, q);
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:32,代码来源:Chebyshev.java

示例5: testFactorization

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
@Override
void testFactorization(Matrix A, Vector x) {
    Vector b = A.mult(x, x.copy());

    ICC icc = new ICC(new CompRowMatrix(A));
    icc.setMatrix(A);
    icc.apply(b, x);

    Vector r = A.multAdd(-1, x, b.copy());

    assertEquals(0, r.norm(Vector.Norm.TwoRobust), 1e-5);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:13,代码来源:ICCTest.java

示例6: testFactorization

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
@Override
void testFactorization(Matrix A, Vector x) {
    Vector b = A.mult(x, x.copy());

    ILU ilu = new ILU(new CompRowMatrix(A));
    ilu.setMatrix(A);
    ilu.apply(b, x);

    Vector r = A.multAdd(-1, x, b.copy());

    assertEquals(0, r.norm(Vector.Norm.TwoRobust), 1e-5);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:13,代码来源:ILUTest.java

示例7: testFactorization

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
@Override
void testFactorization(Matrix A, Vector x) {
    Vector b = A.mult(x, x.copy());

    ILUT ilut = new ILUT(new FlexCompRowMatrix(A));
    ilut.setMatrix(A);
    ilut.apply(b, x);

    Vector r = A.multAdd(-1, x, b.copy());

    assertEquals(0, r.norm(Vector.Norm.TwoRobust), 1e-5);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:13,代码来源:ILUTTest.java

示例8: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double rho_1 = 1, rho_2 = 1, alpha = 1, beta = 1, omega = 1;

    A.multAdd(-1, x, r.set(b));
    rtilde.set(r);

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        rho_1 = rtilde.dot(r);

        if (rho_1 == 0)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "rho", iter);

        if (omega == 0)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "omega", iter);

        if (iter.isFirst())
            p.set(r);
        else {
            beta = (rho_1 / rho_2) * (alpha / omega);

            // temp = p - omega * v
            temp.set(-omega, v).add(p);

            // p = r + beta * temp = r + beta * (p - omega * v)
            p.set(r).add(beta, temp);
        }

        M.apply(p, phat);
        A.mult(phat, v);
        alpha = rho_1 / rtilde.dot(v);
        s.set(r).add(-alpha, v);

        x.add(alpha, phat);
        if (iter.converged(s, x))
            return x;

        M.apply(s, shat);
        A.mult(shat, t);
        omega = t.dot(s) / t.dot(t);
        x.add(omega, shat);
        r.set(s).add(-omega, t);

        rho_2 = rho_1;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:53,代码来源:BiCGstab.java

示例9: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double rho_1 = 0, rho_2 = 0, alpha = 0, beta = 0;

    A.multAdd(-1, x, r.set(b));
    rtilde.set(r);

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        rho_1 = rtilde.dot(r);

        if (rho_1 == 0)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "rho", iter);

        if (iter.isFirst()) {
            u.set(r);
            p.set(u);
        } else {
            beta = rho_1 / rho_2;
            u.set(r).add(beta, q);
            sum.set(q).add(beta, p);
            p.set(u).add(beta, sum);
        }

        M.apply(p, phat);
        A.mult(phat, vhat);
        alpha = rho_1 / rtilde.dot(vhat);
        q.set(-alpha, vhat).add(u);

        M.apply(sum.set(u).add(q), uhat);
        x.add(alpha, uhat);
        A.mult(uhat, qhat);
        r.add(-alpha, qhat);

        rho_2 = rho_1;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:42,代码来源:CGS.java

示例10: solve

import no.uib.cipr.matrix.Matrix; //导入方法依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    A.multAdd(-1, x, u.set(b));
    M.apply(u, r);
    double normr = r.norm(Norm.Two);
    M.apply(b, u);

    // Outer iteration
    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {

        v[0].set(1 / normr, r);
        s.zero().set(0, normr);
        int i = 0;

        // Inner iteration
        for (; i < restart && !iter.converged(Math.abs(s.get(i))); i++, iter
                .next()) {
            A.mult(v[i], u);
            M.apply(u, w);

            for (int k = 0; k <= i; k++) {
                H.set(k, i, w.dot(v[k]));
                w.add(-H.get(k, i), v[k]);
            }
            H.set(i + 1, i, w.norm(Norm.Two));
            v[i + 1].set(1. / H.get(i + 1, i), w);

            // QR factorization of H using Givens rotations
            for (int k = 0; k < i; ++k)
                rotation[k].apply(H, i, k, k + 1);

            rotation[i] = new GivensRotation(H.get(i, i), H.get(i + 1, i));
            rotation[i].apply(H, i, i, i + 1);
            rotation[i].apply(s, i, i + 1);
        }

        // Update solution in current subspace
        new UpperTriangDenseMatrix(H, i, false).solve(s, s);
        for (int j = 0; j < i; j++)
            x.add(s.get(j), v[j]);

        A.multAdd(-1, x, u.set(b));
        M.apply(u, r);
        normr = r.norm(Norm.Two);
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:51,代码来源:GMRES.java


注:本文中的no.uib.cipr.matrix.Matrix.multAdd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。