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


Java MatrixStore.multiply方法代码示例

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


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

示例1: makeInverse

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
protected final MatrixStore<N> makeInverse() {

        final MatrixStore<N> tmpV = this.getV();
        final MatrixStore<N> tmpD = this.getD();

        final int tmpDim = (int) tmpD.countRows();

        final PhysicalStore<N> tmpMtrx = tmpV.transpose().copy();

        final N tmpZero = this.scalar().zero().get();
        final BinaryFunction<N> tmpDivide = this.function().divide();

        for (int i = 0; i < tmpDim; i++) {
            if (tmpD.isSmall(i, i, PrimitiveMath.ONE)) {
                tmpMtrx.fillRow(i, 0, tmpZero);
            } else {
                tmpMtrx.modifyRow(i, 0, tmpDivide.second(tmpD.get(i, i)));
            }
        }

        return tmpV.multiply(tmpMtrx);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:23,代码来源:NewGeneralEvD.java

示例2: getInverse

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
public final MatrixStore<N> getInverse() {

        if (myInverse == null) {

            final MatrixStore<N> tmpV = this.getV();
            final MatrixStore<N> tmpD = this.getD();

            final int tmpDim = (int) tmpD.countRows();

            final PhysicalStore<N> tmpMtrx = tmpV.conjugate().copy();

            final N tmpZero = this.scalar().zero().get();
            final BinaryFunction<N> tmpDivide = this.function().divide();

            for (int i = 0; i < tmpDim; i++) {
                if (tmpD.isSmall(i, i, ONE)) {
                    tmpMtrx.fillRow(i, 0, tmpZero);
                } else {
                    tmpMtrx.modifyRow(i, 0, tmpDivide.second(tmpD.get(i, i)));
                }
            }

            myInverse = tmpV.multiply(tmpMtrx);
        }

        return myInverse;
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:28,代码来源:HermitianEvD.java

示例3: equals

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> boolean equals(final MatrixStore<N> matrix, final Eigenvalue<N> decomposition, final NumberContext context) {

        final MatrixStore<N> tmpD = decomposition.getD();
        final MatrixStore<N> tmpV = decomposition.getV();

        // Check that [A][V] == [V][D] ([A] == [V][D][V]<sup>T</sup> is not always true)
        final MatrixStore<N> tmpStore1 = matrix.multiply(tmpV);
        final MatrixStore<N> tmpStore2 = tmpV.multiply(tmpD);

        return Access2D.equals(tmpStore1, tmpStore2, context);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:12,代码来源:Eigenvalue.java

示例4: equals

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> boolean equals(final MatrixStore<N> matrix, final Schur<N> decomposition, final NumberContext context) {

        final MatrixStore<N> tmpU = decomposition.getU();
        final MatrixStore<N> tmpQ = decomposition.getQ();

        // Check that [A][Q] == [Q][U] ([A] == [Q][U][Q]<sup>T</sup> is not always true)
        final MatrixStore<N> tmpStore1 = matrix.multiply(tmpQ);
        final MatrixStore<N> tmpStore2 = tmpQ.multiply(tmpU);

        return Access2D.equals(tmpStore1, tmpStore2, context);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:12,代码来源:Schur.java

示例5: testWikipediaCase

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
public void testWikipediaCase() {

        final RawStore tmpA = new RawStore(new double[][] { { 4, 12, -16 }, { 12, 37, -43 }, { -16, -43, 98 } });
        final RawStore tmpL = new RawStore(new double[][] { { 1, 0, 0 }, { 3, 1, 0 }, { -4, 5, 1 } });
        final RawStore tmpD = new RawStore(new double[][] { { 4, 0, 0 }, { 0, 1, 0 }, { 0, 0, 9 } });

        final RawStore tmpReconstructed = tmpL.multiply(tmpD.multiply(tmpL.transpose()));
        TestUtils.assertEquals(tmpA, tmpReconstructed);

        final RawLDL tmpRawLDL = new RawLDL();
        tmpRawLDL.decompose(tmpA);

        final LDL<Double> tmpPrimLDL = new LDLDecomposition.Primitive();
        tmpPrimLDL.decompose(tmpA);

        //        BasicLogger.debug(tmpL);
        //        BasicLogger.debug(tmpD);

        //        BasicLogger.debug("RAW L", tmpRawLDL.getL());
        //        BasicLogger.debug("RAW D", tmpRawLDL.getD());
        //
        //        BasicLogger.debug("PRIM L", tmpPrimLDL.getL());
        //        BasicLogger.debug("PRIM D", tmpPrimLDL.getD());

        TestUtils.assertEquals(tmpL, tmpRawLDL.getL());
        TestUtils.assertEquals(tmpD, tmpRawLDL.getD());

        final MatrixStore<Double> tmpRawInv = tmpRawLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());
        final MatrixStore<Double> tmpPrimInv = tmpPrimLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());

        tmpRawInv.multiply(tmpA);
        tmpPrimInv.multiply(tmpA);

        tmpRawLDL.decompose(tmpRawInv);
        final MatrixStore<Double> tmpInverse2 = tmpRawLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());

        TestUtils.assertEquals(tmpA, tmpInverse2);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:39,代码来源:LDLTest.java

示例6: testPrimitiveAsComplex

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
public void testPrimitiveAsComplex() {

        final double[][] tmpData = new double[][] { { 1, 0, 3 }, { 0, 4, 1 }, { -5, 1, 0 } };
        final PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData);

        final int tmpLength = tmpData.length;

        final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(tmpA, false);

        tmpEvD.decompose(tmpA);

        final MatrixStore<Double> tmpD = tmpEvD.getD();
        final MatrixStore<Double> tmpV = tmpEvD.getV();

        final Array1D<ComplexNumber> tmpValues = tmpEvD.getEigenvalues();
        final MatrixStore<ComplexNumber> tmpVectors = tmpEvD.getEigenvectors();

        final ComplexDenseStore tmpCmplA = ComplexDenseStore.FACTORY.copy(tmpA);
        final ComplexDenseStore tmpCmplD = ComplexDenseStore.FACTORY.copy(tmpD);
        final ComplexDenseStore tmpCmplV = ComplexDenseStore.FACTORY.copy(tmpV);

        final MatrixStore<ComplexNumber> tmpExp1 = tmpCmplA.multiply(tmpCmplV);
        final MatrixStore<ComplexNumber> tmpAct1 = tmpCmplV.multiply(tmpCmplD);
        TestUtils.assertEquals(tmpExp1, tmpAct1);

        final ComplexDenseStore tmpAltD = ComplexDenseStore.FACTORY.makeZero(tmpLength, tmpLength);
        final MatrixStore<ComplexNumber> tmpAltV = tmpVectors;

        for (int j = 0; j < tmpLength; j++) {
            tmpAltD.set(j, j, tmpValues.get(j));
        }

        final MatrixStore<ComplexNumber> tmpExp2 = tmpCmplA.multiply(tmpAltV);
        final MatrixStore<ComplexNumber> tmpAct2 = tmpAltV.multiply(tmpAltD);
        TestUtils.assertEquals(tmpExp2, tmpAct2);

        tmpEvD.computeValuesOnly(tmpA);
        final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEvD.getEigenvalues();
        TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:41,代码来源:EigenvalueTest.java

示例7: performIteration

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
@Override
protected void performIteration() {

    this.getIterationQ();
    final MatrixStore<Double> tmpIterC = this.getIterationC();
    final MatrixStore<Double> tmpIterA = this.getIterationA();
    final MatrixStore<Double> tmpIterB = this.getIterationB();

    boolean solved = false;

    final PrimitiveDenseStore tmpIterX = myIterationX;
    final PrimitiveDenseStore tmpIterL = FACTORY.makeZero(tmpIterA.countRows(), 1L);

    if ((tmpIterA.countRows() < tmpIterA.countColumns()) && (solved = this.isSolvableQ())) {
        // Q is SPD
        // Actual/normal optimisation problem

        final MatrixStore<Double> tmpInvQAT = this.getSolutionQ(tmpIterA.transpose());
        // TODO Only 1 column change inbetween active set iterations (add or remove 1 column)

        // Negated Schur complement
        final MatrixStore<Double> tmpS = tmpIterA.multiply(tmpInvQAT);
        // TODO Symmetric, only need to calculate halv the Schur complement
        if (solved = this.computeGeneral(tmpS)) {

            // tmpX temporarely used to store tmpInvQC
            final MatrixStore<Double> tmpInvQC = this.getSolutionQ(tmpIterC, tmpIterX); //TODO Constant if C doesn't change

            this.getSolutionGeneral(tmpIterA.multiply(tmpInvQC).subtract(tmpIterB), tmpIterL);
            this.getSolutionQ(tmpIterC.subtract(tmpIterA.transpose().multiply(tmpIterL)), tmpIterX);
        }

    }

    if (!solved) {
        // The above failed, try solving the full KKT system instaed

        final PrimitiveDenseStore tmpXL = FACTORY.makeZero(this.countVariables() + this.countIterationConstraints(), 1L);

        if (solved = this.solveFullKKT(tmpXL)) {
            tmpIterX.fillMatching(tmpXL.logical().limits(this.countVariables(), 1).get());
            tmpIterL.fillMatching(tmpXL.logical().offsets(this.countVariables(), 0).get());
        }
    }

    if (solved) {

        this.setState(State.OPTIMAL);

        if (myFeasible) {
            this.getSolutionX().modifyMatching(PrimitiveFunction.ADD, tmpIterX);
        } else {
            this.getSolutionX().fillMatching(tmpIterX);
        }

        // this.getLE().fillMatching(tmpIterL);

    } else {

        if (myFeasible) {

            this.setState(State.FEASIBLE);

        } else {

            this.setState(State.INFEASIBLE);
            this.getSolutionX().fillAll(ZERO);
        }
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:71,代码来源:QPESolver.java

示例8: equals

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> boolean equals(final MatrixStore<N> matrix, final SingularValue<N> decomposition, final NumberContext context) {

        final int tmpRowDim = (int) matrix.countRows();
        final int tmpColDim = (int) matrix.countColumns();

        final MatrixStore<N> tmpQ1 = decomposition.getQ1();
        final MatrixStore<N> tmpD = decomposition.getD();
        final MatrixStore<N> tmpQ2 = decomposition.getQ2();

        MatrixStore<N> tmpThis;
        MatrixStore<N> tmpThat;

        boolean retVal = (tmpRowDim == tmpQ1.countRows()) && (tmpQ2.countRows() == tmpColDim);

        // Check that [A][Q2] == [Q1][D]
        if (retVal) {

            tmpThis = matrix.multiply(tmpQ2);
            tmpThat = tmpQ1.multiply(tmpD);

            retVal &= tmpThis.equals(tmpThat, context);
        }

        // If Q1 is square, then check if it is orthogonal/unitary.
        if (retVal && (tmpQ1.countRows() == tmpQ1.countColumns())) {

            tmpThis = tmpQ1.physical().makeEye(tmpRowDim, tmpRowDim);
            tmpThat = tmpQ1.logical().conjugate().get().multiply(tmpQ1);

            retVal &= tmpThis.equals(tmpThat, context);
        }

        // If Q2 is square, then check if it is orthogonal/unitary.
        if (retVal && (tmpQ2.countRows() == tmpQ2.countColumns())) {

            tmpThis = tmpQ2.physical().makeEye(tmpColDim, tmpColDim);
            tmpThat = tmpQ2.multiply(tmpQ2.logical().conjugate().get());

            retVal &= tmpThis.equals(tmpThat, context);
        }

        // Check the pseudoinverse.
        if (retVal) {
            retVal &= matrix.equals(matrix.multiply(decomposition.getInverse().multiply(matrix)), context);
        }

        // Check that the singular values are sorted in descending order
        if (retVal) {
            final Array1D<Double> tmpSV = decomposition.getSingularValues();
            for (int i = 1; retVal && (i < tmpSV.size()); i++) {
                retVal &= tmpSV.doubleValue(i - 1) >= tmpSV.doubleValue(i);
            }
            if (retVal && decomposition.isOrdered()) {
                for (int ij = 1; retVal && (ij < tmpD.countRows()); ij++) {
                    retVal &= tmpD.doubleValue(ij - 1, ij - 1) >= tmpD.doubleValue(ij, ij);
                }
            }
        }

        return retVal;
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:62,代码来源:SingularValue.java

示例9: reconstruct

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> MatrixStore<N> reconstruct(final Cholesky<N> decomposition) {
    final MatrixStore<N> tmpL = decomposition.getL();
    return tmpL.multiply(tmpL.conjugate());
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:5,代码来源:Cholesky.java

示例10: doTest

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
private void doTest(final PhysicalStore<Double> matrixA, final Array1D<Double> singularValues) {

        final MatrixStore<Double> tmpTranspA = matrixA.transpose();
        final MatrixStore<Double> tmpLeftA = matrixA.multiply(tmpTranspA);
        final MatrixStore<Double> tmpRightA = tmpTranspA.multiply(matrixA);

        final Eigenvalue<Double> tmpEigenvalue = Eigenvalue.PRIMITIVE.make(true);

        tmpEigenvalue.decompose(tmpLeftA);
        final MatrixStore<Double> tmpLeftD = tmpEigenvalue.getD();
        final MatrixStore<Double> tmpLeftV = tmpEigenvalue.getV();
        if (MatrixDecompositionTests.DEBUG) {
            BasicLogger.debug("Left D", tmpLeftD, new NumberContext(7, 6));
            BasicLogger.debug("Left V", tmpLeftV, new NumberContext(7, 6));
        }
        // Check that the eigenvalue decomposition of the "left" matrix is correct
        TestUtils.assertEquals(tmpLeftA, tmpEigenvalue, new NumberContext(7, 6));

        tmpEigenvalue.decompose(tmpRightA);
        final MatrixStore<Double> tmpRightD = tmpEigenvalue.getD();
        final MatrixStore<Double> tmpRightV = tmpEigenvalue.getV();
        if (MatrixDecompositionTests.DEBUG) {
            BasicLogger.debug("Right D", tmpRightD, new NumberContext(7, 6));
            BasicLogger.debug("Right V", tmpRightV, new NumberContext(7, 6));
        }
        // Check that the eigenvalue decomposition of the "right" matrix is correct
        TestUtils.assertEquals(tmpRightA, tmpEigenvalue, new NumberContext(7, 6));

        // Check that the, left and right, singular values are correct
        for (int ij = 0; ij < singularValues.length; ij++) {
            final double tmpExpected = singularValues.doubleValue(ij);
            final double tmpLeftSqrt = PrimitiveFunction.SQRT.invoke(PrimitiveFunction.ABS.invoke(tmpLeftD.doubleValue(ij, ij)));
            final double tmpRightSqrt = PrimitiveFunction.SQRT.invoke(PrimitiveFunction.ABS.invoke(tmpRightD.doubleValue(ij, ij)));
            TestUtils.assertEquals("Left " + ij, tmpExpected, tmpLeftSqrt, new NumberContext(7, 6));
            TestUtils.assertEquals("Right " + ij, tmpExpected, tmpRightSqrt, new NumberContext(7, 6));
        }

        // So far...

        final SingularValue<Double> tmpExperimental = SingularValue.PRIMITIVE.make();
        tmpExperimental.decompose(matrixA);

        if (MatrixDecompositionTests.DEBUG) {
            BasicLogger.debug();
            BasicLogger.debug("Experimental  S: {}.", tmpExperimental.getSingularValues());
            BasicLogger.debug("D", tmpExperimental.getD(), new NumberContext(7, 6));
            BasicLogger.debug("Q1", tmpExperimental.getQ1(), new NumberContext(7, 6));
            BasicLogger.debug("Q2", tmpExperimental.getQ2(), new NumberContext(7, 6));
        }

        TestUtils.assertEquals(matrixA, tmpExperimental, new NumberContext(7, 6));
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:53,代码来源:SVDbyEvD.java

示例11: testPaulsMathNote

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
public void testPaulsMathNote() {

        final double[][] tmpData = new double[][] { { 3, -9 }, { 4, -3 } };
        final PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData);
        final int tmpLength = tmpData.length;

        final Array1D<ComplexNumber> tmpExpVals = Array1D.COMPLEX.makeZero(2);
        tmpExpVals.set(0, ComplexNumber.of(0.0, THREE * SQRT.invoke(THREE)));
        tmpExpVals.set(1, tmpExpVals.get(0).conjugate());

        final Array2D<ComplexNumber> tmpExpVecs = Array2D.COMPLEX.makeZero(2, 2);
        tmpExpVecs.set(0, 0, ComplexNumber.of(THREE, ZERO));
        tmpExpVecs.set(1, 0, ComplexNumber.of(ONE, -SQRT.invoke(THREE)));
        tmpExpVecs.set(0, 1, ComplexNumber.of(THREE, ZERO));
        tmpExpVecs.set(1, 1, ComplexNumber.of(ONE, SQRT.invoke(THREE)));

        final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(tmpA, false);
        tmpEvD.decompose(tmpA);

        final MatrixStore<Double> tmpD = tmpEvD.getD();
        final MatrixStore<Double> tmpV = tmpEvD.getV();

        final Array1D<ComplexNumber> tmpValues = tmpEvD.getEigenvalues();
        final MatrixStore<ComplexNumber> tmpVectors = tmpEvD.getEigenvectors();

        TestUtils.assertEquals(tmpExpVals, tmpValues);
        for (int j = 0; j < tmpLength; j++) {
            final Array1D<ComplexNumber> tmpSliceColumn = tmpExpVecs.sliceColumn(0, j);
            final Access1D<ComplexNumber> tmpActual = tmpVectors.sliceColumn(0, j);

            final ComplexNumber tmpFactor = tmpActual.get(0).divide(tmpSliceColumn.get(0));

            TestUtils.assertEquals(tmpSliceColumn.get(1).multiply(tmpFactor), tmpActual.get(1));
        }

        final ComplexDenseStore tmpCmplA = ComplexDenseStore.FACTORY.copy(tmpA);
        final ComplexDenseStore tmpCmplD = ComplexDenseStore.FACTORY.copy(tmpD);
        final ComplexDenseStore tmpCmplV = ComplexDenseStore.FACTORY.copy(tmpV);

        final MatrixStore<ComplexNumber> tmpExp1 = tmpCmplA.multiply(tmpCmplV);
        final MatrixStore<ComplexNumber> tmpAct1 = tmpCmplV.multiply(tmpCmplD);
        TestUtils.assertEquals(tmpExp1, tmpAct1);

        final ComplexDenseStore tmpComplexD = ComplexDenseStore.FACTORY.makeZero(tmpLength, tmpLength);
        for (int j = 0; j < tmpLength; j++) {
            tmpComplexD.set(j, j, tmpValues.get(j));
        }

        final MatrixStore<ComplexNumber> tmpExp2 = tmpCmplA.multiply(tmpVectors);
        final MatrixStore<ComplexNumber> tmpAct2 = tmpVectors.multiply(tmpComplexD);
        TestUtils.assertEquals(tmpExp2, tmpAct2);

        tmpEvD.computeValuesOnly(tmpA);
        final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEvD.getEigenvalues();
        TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);

    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:58,代码来源:EigenvalueTest.java

示例12: equals

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> boolean equals(final MatrixStore<N> matrix, final QR<N> decomposition, final NumberContext context) {

        final MatrixStore<N> tmpQ = decomposition.getQ();
        final MatrixStore<N> tmpR = decomposition.getR();

        final MatrixStore<N> tmpStore = tmpQ.multiply(tmpR);

        return Access2D.equals(tmpStore, matrix, context);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:10,代码来源:QR.java

示例13: equals

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
static <N extends Number> boolean equals(final MatrixStore<N> matrix, final Hessenberg<N> decomposition, final NumberContext context) {

        final MatrixStore<N> tmpH = decomposition.getH();
        final MatrixStore<N> tmpQ = decomposition.getQ();

        final MatrixStore<N> tmpStore1 = matrix.multiply(tmpQ);
        final MatrixStore<N> tmpStore2 = tmpQ.multiply(tmpH);

        return Access2D.equals(tmpStore1, tmpStore2, context);
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:11,代码来源:Hessenberg.java


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