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


Java MatrixStore.countRows方法代码示例

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


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

示例1: validate

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

    super.validate();

    final MatrixStore<Double> iterA = this.getIterationA();
    final MatrixStore<Double> iterB = this.getIterationB();

    if (((iterA != null) && (iterB == null)) || ((iterA == null) && (iterB != null))) {
        throw new IllegalArgumentException("Either A or B is null, and the other one is not!");
    }

    if (iterA != null) {
        this.computeGeneral(iterA.countRows() < iterA.countColumns() ? iterA.transpose() : iterA);
        if (this.getRankGeneral() != iterA.countRows()) {
            throw new IllegalArgumentException("A must have full (row) rank!");
        }
    }

    this.setState(State.VALID);
    return true;
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:23,代码来源:ConstrainedSolver.java

示例2: 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

示例3: isFeasible

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
private boolean isFeasible() {

        boolean retVal = true;

        final MatrixStore<Double> tmpSE = this.getSE();
        for (int i = 0; retVal && (i < tmpSE.countRows()); i++) {
            if (!options.feasibility.isZero(tmpSE.doubleValue(i))) {
                retVal = false;
            }
        }

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

示例4: make

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
@Override
public InverterTask<Double> make(final MatrixStore<Double> template, final boolean symmetric, final boolean positiveDefinite) {

    final long tmpDim = template.countRows();

    if (symmetric) {
        if (tmpDim == 1L) {
            return AbstractInverter.FULL_1X1;
        } else if (tmpDim == 2L) {
            return AbstractInverter.SYMMETRIC_2X2;
        } else if (tmpDim == 3L) {
            return AbstractInverter.SYMMETRIC_3X3;
        } else if (tmpDim == 4L) {
            return AbstractInverter.SYMMETRIC_4X4;
        } else if (tmpDim == 5L) {
            return AbstractInverter.SYMMETRIC_5X5;
        } else {
            return positiveDefinite ? Cholesky.PRIMITIVE.make(template) : LU.PRIMITIVE.make(template);
        }
    } else if (template.isSquare()) {
        if (tmpDim == 1L) {
            return AbstractInverter.FULL_1X1;
        } else if (tmpDim == 2L) {
            return AbstractInverter.FULL_2X2;
        } else if (tmpDim == 3L) {
            return AbstractInverter.FULL_3X3;
        } else if (tmpDim == 4L) {
            return AbstractInverter.FULL_4X4;
        } else if (tmpDim == 5L) {
            return AbstractInverter.FULL_5X5;
        } else {
            return LU.PRIMITIVE.make(template);
        }
    } else if (template.isTall()) {
        return QR.PRIMITIVE.make(template);
    } else {
        return SingularValue.PRIMITIVE.make(template);
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:40,代码来源:InverterTask.java

示例5: make

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
@Override
public DeterminantTask<Double> make(final MatrixStore<Double> template, final boolean symmetric, final boolean positiveDefinite) {
    final long tmpDim = template.countRows();
    if (tmpDim == 1L) {
        return AbstractDeterminator.FULL_1X1;
    } else if (symmetric) {
        if (tmpDim == 2L) {
            return AbstractDeterminator.SYMMETRIC_2X2;
        } else if (tmpDim == 3L) {
            return AbstractDeterminator.SYMMETRIC_3X3;
        } else if (tmpDim == 4L) {
            return AbstractDeterminator.SYMMETRIC_4X4;
        } else if (tmpDim == 5L) {
            return AbstractDeterminator.SYMMETRIC_5X5;
        } else {
            return positiveDefinite ? Cholesky.PRIMITIVE.make(template) : LU.PRIMITIVE.make(template);
        }
    } else {
        if (tmpDim == 2L) {
            return AbstractDeterminator.FULL_2X2;
        } else if (tmpDim == 3L) {
            return AbstractDeterminator.FULL_3X3;
        } else if (tmpDim == 4L) {
            return AbstractDeterminator.FULL_4X4;
        } else if (tmpDim == 5L) {
            return AbstractDeterminator.FULL_5X5;
        } else {
            return LU.PRIMITIVE.make(template);
        }
    }
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:32,代码来源:DeterminantTask.java

示例6: getInverseOldVersion

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

        if (myInverse == null) {

            final MatrixStore<N> tmpQ1 = this.getQ1();
            final Array1D<Double> tmpSingulars = this.getSingularValues();
            final MatrixStore<N> tmpQ2 = this.getQ2();

            final int tmpRowDim = (int) tmpSingulars.count();
            final int tmpColDim = (int) tmpQ1.countRows();
            final PhysicalStore<N> tmpMtrx = this.makeZero(tmpRowDim, tmpColDim);

            double tmpValue;
            final int rank = this.getRank();
            for (int i = 0; i < rank; i++) {
                tmpValue = tmpSingulars.doubleValue(i);
                for (int j = 0; j < tmpColDim; j++) {
                    tmpMtrx.set(i, j, tmpQ1.toScalar(j, i).conjugate().divide(tmpValue).get());
                }
            }

            preallocated.fillByMultiplying(tmpQ2, tmpMtrx);
            myInverse = preallocated;
        }

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

示例7: 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

示例8: computeAndTest

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
private void computeAndTest(final MatrixStore<Double> aMtrx) {

        if (aMtrx.countRows() == aMtrx.countColumns()) {

            // Requires square matrices

            CHOLESKY.decompose(aMtrx);
            if (CHOLESKY.isSolvable()) {
                TestUtils.assertEquals(aMtrx, CHOLESKY, EVAL_CNTXT);
            }

            EIGENVALUE.decompose(aMtrx);
            if (EIGENVALUE.isComputed()) {
                TestUtils.assertEquals(aMtrx, EIGENVALUE, EVAL_CNTXT);
            }
        }

        if (aMtrx.countRows() >= aMtrx.countColumns()) {

            // The Jama QR decomposition can't handle matrices that are fat,
            // and it's not the most common use case for this decomposition.

            QR.decompose(aMtrx);
            if (QR.isSolvable()) {
                TestUtils.assertEquals(aMtrx, QR, EVAL_CNTXT);
            }
        }

        LU.decompose(aMtrx);
        if (LU.isSolvable()) {
            TestUtils.assertEquals(aMtrx, LU, EVAL_CNTXT);
        }

        SINGULAR_VALUE.decompose(aMtrx);
        if (SINGULAR_VALUE.isSolvable()) {
            TestUtils.assertEquals(aMtrx, SINGULAR_VALUE, EVAL_CNTXT);
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:39,代码来源:TestJama.java

示例9: suggestConstraintToExclude

import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
/**
 * Find the minimum (largest negative) lagrange multiplier - for the active inequalities - to potentially
 * deactivate.
 */
protected int suggestConstraintToExclude() {

    int retVal = -1;

    final int[] tmpIncluded = myActivator.getIncluded();
    final int tmpLastIncluded = myActivator.getLastIncluded();
    int tmpIndexOfLast = -1;

    double tmpMin = POSITIVE_INFINITY;
    double tmpVal;

    // final MatrixStore<Double> tmpLI = this.getLI(tmpIncluded);
    final MatrixStore<Double> tmpLI = this.getSolutionL().logical().offsets(this.countEqualityConstraints(), 0).row(tmpIncluded).get();

    if (this.isDebug() && (tmpLI.count() > 0L)) {
        this.log("Looking for the largest negative lagrange multiplier among these: {}.", tmpLI.copy().asList());
    }

    for (int i = 0; i < tmpLI.countRows(); i++) {

        if (tmpIncluded[i] != tmpLastIncluded) {

            tmpVal = tmpLI.doubleValue(i, 0);

            if ((tmpVal < ZERO) && (tmpVal < tmpMin) && !options.solution.isZero(tmpVal)) {
                tmpMin = tmpVal;
                retVal = i;
                if (this.isDebug()) {
                    this.log("Best so far: {} @ {} ({}).", tmpMin, retVal, tmpIncluded[i]);
                }
            }

        } else {

            tmpIndexOfLast = i;
        }
    }

    if ((retVal < 0) && (tmpIndexOfLast >= 0)) {

        tmpVal = tmpLI.doubleValue(tmpIndexOfLast, 0);

        if ((tmpVal < ZERO) && (tmpVal < tmpMin) && !options.solution.isZero(tmpVal)) {
            tmpMin = tmpVal;
            retVal = tmpIndexOfLast;
            if (this.isDebug()) {
                this.log("Only the last included needs to be excluded: {} @ {} ({}).", tmpMin, retVal, tmpIncluded[retVal]);
            }
        }
    }

    return retVal >= 0 ? tmpIncluded[retVal] : retVal;
}
 
开发者ID:optimatika,项目名称:ojAlgo,代码行数:58,代码来源:ActiveSetSolver.java

示例10: 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

示例11: 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

示例12: equals

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

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

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

        final MatrixStore<N> tmpConjugatedQ1 = tmpQ1.logical().conjugate().get();
        final MatrixStore<N> tmpConjugatedQ2 = tmpQ2.logical().conjugate().get();

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

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

        // Check that it's possible to reconstruct the original matrix.
        if (retVal) {

            tmpThis = matrix;
            tmpThat = decomposition.reconstruct();

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

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

            tmpThis = tmpQ1;
            tmpThat = tmpQ1.multiply(tmpConjugatedQ1).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;
            tmpThat = tmpQ2.multiply(tmpConjugatedQ2).multiply(tmpQ2);

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

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


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