本文整理汇总了Java中org.ojalgo.matrix.store.MatrixStore类的典型用法代码示例。如果您正苦于以下问题:Java MatrixStore类的具体用法?Java MatrixStore怎么用?Java MatrixStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatrixStore类属于org.ojalgo.matrix.store包,在下文中一共展示了MatrixStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertEquals
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public static <N extends Number> void assertEquals(final MatrixStore<N> expected, final Eigenvalue<N> actual, final NumberContext context) {
if (!Eigenvalue.equals(expected, actual, context)) {
Assert.failNotEquals("Eigenvalue<N>", expected, actual);
}
if (actual.isOrdered()) {
final MatrixStore<N> mtrxD = actual.getD();
double bigger = Double.MAX_VALUE;
final Array1D<ComplexNumber> tmpEigenvalues = actual.getEigenvalues();
for (int i = 0; i < tmpEigenvalues.length; i++) {
final ComplexNumber value = tmpEigenvalues.get(i);
Assert.assertTrue(bigger >= value.getModulus());
Assert.assertEquals(value.doubleValue(), mtrxD.doubleValue(i, i), context.epsilon());
bigger = value.getModulus();
}
}
}
示例2: testCaseData
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public void testCaseData() {
final MatrixStore<Double> tmpExpected = myBE;
MatrixStore<Double> tmpActual = myAE.multiply(myXE);
Access2D.equals(tmpExpected, tmpActual, myEvaluationContext);
tmpActual = myAE.multiply(myXI);
TestUtils.assertEquals(tmpExpected, tmpActual, myEvaluationContext);
if ((myAI != null) && (myBI != null)) {
final PhysicalStore<Double> tmpSlack = myBI.copy();
tmpSlack.modifyMatching(PrimitiveFunction.SUBTRACT, myAI.multiply(myXI));
for (int i = 0; i < tmpSlack.countRows(); i++) {
TestUtils.assertTrue(tmpSlack.doubleValue(i, 0) > -myEvaluationContext.epsilon());
}
}
}
示例3: resetActivator
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
void resetActivator() {
myActivator.excludeAll();
final int numbEqus = this.countEqualityConstraints();
final int numbVars = this.countVariables();
if (this.hasInequalityConstraints()) {
final MatrixStore<Double> slack = this.getSlackI();
final int[] excl = this.getExcluded();
for (int i = 0; i < excl.length; i++) {
if (options.feasibility.isZero(slack.doubleValue(excl[i])) && (!options.solution.isZero(this.getSolutionL().doubleValue(numbEqus + excl[i])))) {
this.include(excl[i]);
}
}
}
while (((numbEqus + this.countIncluded()) >= numbVars) && (this.countIncluded() > 0)) {
this.shrink();
}
if (this.isDebug() && ((numbEqus + this.countIncluded()) > numbVars)) {
this.log("Redundant contraints!");
}
}
示例4: getRank
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public int getRank() {
int retVal = 0;
final MatrixStore<Double> tmpR = this.getR();
final int tmpMinDim = (int) Math.min(tmpR.countRows(), tmpR.countColumns());
final AggregatorFunction<Double> tmpLargest = PrimitiveAggregator.LARGEST.get();
tmpR.visitDiagonal(0L, 0L, tmpLargest);
final double tmpLargestValue = tmpLargest.doubleValue();
for (int ij = 0; ij < tmpMinDim; ij++) {
if (!tmpR.isSmall(ij, ij, tmpLargestValue)) {
retVal++;
}
}
return retVal;
}
示例5: doTest
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
private void doTest(final MatrixDecomposition.Solver<Double> decomposition, final MatrixStore<Double> body, final MatrixStore<Double> rhs,
final MatrixStore<Double> solution, final NumberContext accuracy) {
decomposition.decompose(body);
TestUtils.assertEquals(solution, decomposition.getSolution(rhs), accuracy);
final MatrixStore<Double> tmpI = body.physical().makeEye(body.countRows(), body.countColumns());
final MatrixStore<Double> tmpExpectedInverse = decomposition.getSolution(tmpI);
decomposition.reset();
decomposition.decompose(body);
TestUtils.assertEquals(tmpExpectedInverse, decomposition.getInverse(), accuracy);
TestUtils.assertEquals(tmpI, tmpExpectedInverse.multiply(body), accuracy);
TestUtils.assertEquals(tmpI, body.multiply(tmpExpectedInverse), accuracy);
}
示例6: getR
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
/**
* Return the upper triangular factor
*
* @return R
*/
public MatrixStore<Double> getR() {
final int tmpColDim = this.getColDim();
final double[][] tmpData = this.getRawInPlaceData();
final RawStore retVal = new RawStore(tmpColDim, tmpColDim);
final double[][] retData = retVal.data;
double[] tmpRow;
for (int i = 0; i < tmpColDim; i++) {
tmpRow = retData[i];
tmpRow[i] = myDiagonalR[i];
for (int j = i + 1; j < tmpColDim; j++) {
tmpRow[j] = tmpData[j][i];
}
}
return retVal;
}
示例7: toVolatilities
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
/**
* Will extract the standard deviations (volatilities) from the input covariance matrix. If "cleaning" is
* enabled small variances will be replaced with a new minimal value.
*/
public static PrimitiveMatrix toVolatilities(final Access2D<?> covariances, final boolean clean) {
final int tmpSize = (int) Math.min(covariances.countRows(), covariances.countColumns());
final Builder<PrimitiveMatrix> retVal = PrimitiveMatrix.FACTORY.getBuilder(tmpSize);
if (clean) {
final AggregatorFunction<Double> tmpLargest = PrimitiveAggregator.LARGEST.get();
MatrixStore.PRIMITIVE.makeWrapper(covariances).get().visitDiagonal(0, 0, tmpLargest);
final double tmpLimit = tmpLargest.doubleValue() * tmpSize * PrimitiveFunction.SQRT.invoke(PrimitiveMath.MACHINE_EPSILON);
for (int ij = 0; ij < tmpSize; ij++) {
final double tmpVariance = covariances.doubleValue(ij, ij);
if (tmpVariance < tmpLimit) {
retVal.set(ij, PrimitiveFunction.SQRT.invoke(tmpLimit));
} else {
retVal.set(ij, PrimitiveFunction.SQRT.invoke(tmpVariance));
}
}
} else {
for (int ij = 0; ij < tmpSize; ij++) {
retVal.set(ij, PrimitiveFunction.SQRT.invoke(covariances.doubleValue(ij, ij)));
}
}
return retVal.get();
}
示例8: compute
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
@Override
public Iterator<MatrixStore<N>> compute(final Partition partition, final TaskContext context) {
ProgrammingError.throwIfNull(partition, context);
if (partition instanceof Partition2D) {
return this.compute((Partition2D) partition, context);
} else {
throw new IllegalArgumentException();
}
}
示例9: getProjectionMatrix
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
/**
* Returns an orthonormal projection Matrix that can be used to project input vectors into the
* k-dimensional space represented by the sketch.
* @return An orthonormal Matrix object
*/
public Matrix getProjectionMatrix() {
final SingularValue<Double> svd = SingularValue.make(B_);
svd.compute(B_);
final MatrixStore<Double> m = svd.getQ2().transpose();
// not super efficient...
final Matrix result = Matrix.builder().build(k_, d_);
for (int i = 0; i < k_ - 1; ++i) { // last SV is 0
result.setRow(i, m.sliceRow(i).toRawCopy1D());
}
return result;
}
示例10: calc
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public Matrix calc(Matrix source) {
MatrixStore<Double> matrix = null;
if (source instanceof OjalgoDenseDoubleMatrix2D) {
matrix = ((OjalgoDenseDoubleMatrix2D) source).getWrappedObject();
} else {
matrix = new OjalgoDenseDoubleMatrix2D(source).getWrappedObject();
}
org.ojalgo.matrix.decomposition.LU<Double> lu = LUDecomposition.makePrimitive();
lu.compute(matrix);
return new OjalgoDenseDoubleMatrix2D(lu.getInverse());
}
示例11: calc
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public Matrix calc(Matrix source) {
MatrixStore<Double> matrix = null;
if (source instanceof OjalgoDenseDoubleMatrix2D) {
matrix = ((OjalgoDenseDoubleMatrix2D) source).getWrappedObject();
} else {
matrix = new OjalgoDenseDoubleMatrix2D(source).getWrappedObject();
}
Cholesky<Double> chol = CholeskyDecomposition.makePrimitive();
chol.compute(matrix);
return new OjalgoDenseDoubleMatrix2D(chol.getInverse());
}
示例12: testCholeskySolveInverse
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public void testCholeskySolveInverse() {
final PhysicalStore<ComplexNumber> tmpRandomComplexStore = MatrixUtils.makeRandomComplexStore(4, 9);
final PhysicalStore<Double> tmpVctr = PrimitiveDenseStore.FACTORY.copy(tmpRandomComplexStore);
final MatrixStore<Double> tmpMtrx = tmpVctr.multiply(tmpVctr.transpose());
this.doTestSolveInverse(Cholesky.PRIMITIVE.make(), tmpMtrx);
}
示例13: invert
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public MatrixStore<Double> invert(final Access2D<?> original, final PhysicalStore<Double> preallocated) throws RecoverableCondition {
final double[][] tmpData = this.reset(original, false);
this.getRawInPlaceStore().fillMatching(original);
this.doDecompose(tmpData, false);
if (this.isSolvable()) {
return this.getInverse(preallocated);
} else {
throw RecoverableCondition.newMatrixNotInvertible();
}
}
示例14: getQ2
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public MatrixStore<N> getQ2() {
if (!myValuesOnly && this.isComputed() && (myQ2 == null)) {
if (myTransposed) {
myQ2 = this.makeQ1();
} else {
myQ2 = this.makeQ2();
}
}
return myQ2;
}
示例15: _testQR
import org.ojalgo.matrix.store.MatrixStore; //导入依赖的package包/类
public void _testQR() {
final MatrixStore<Double> tmpProblematic = ExtremeElementsCase.getVerySmall();
final QR<BigDecimal> tmpBig = QR.BIG.make();
final QR<ComplexNumber> tmpComplex = QR.COMPLEX.make();
final QR<Double> tmpPrimitive = QR.PRIMITIVE.make();
final QR<Double> tmpJama = new RawQR();
TestUtils.assertTrue("Big.compute()", tmpBig.decompose(MatrixStore.BIG.makeWrapper(tmpProblematic)));
TestUtils.assertTrue("Complex.compute()", tmpComplex.decompose(MatrixStore.COMPLEX.makeWrapper(tmpProblematic)));
TestUtils.assertTrue("Primitive.compute()", tmpPrimitive.decompose(tmpProblematic));
TestUtils.assertTrue("Jama.compute()", tmpJama.decompose(tmpProblematic));
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Big Q", tmpBig.getQ());
BasicLogger.debug("Complex Q", tmpComplex.getQ());
BasicLogger.debug("Primitive Q", tmpPrimitive.getQ());
BasicLogger.debug("Jama Q", tmpJama.getQ());
}
TestUtils.assertEquals("QR.reconstruct() Big", tmpProblematic, tmpBig.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Complex", tmpProblematic, tmpComplex.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Primitive", tmpProblematic, tmpPrimitive.reconstruct(), PRECISION);
TestUtils.assertEquals("QR.reconstruct() Jama", tmpProblematic, tmpJama.reconstruct(), PRECISION);
final SingularValue<Double> tmpSVD = new RawSingularValue();
tmpSVD.decompose(tmpProblematic);
TestUtils.assertEquals("rank() SVD vs Big", tmpSVD.getRank(), tmpBig.getRank());
TestUtils.assertEquals("rank() SVD vs Complex", tmpSVD.getRank(), tmpComplex.getRank());
TestUtils.assertEquals("rank() SVD vs Primitive", tmpSVD.getRank(), tmpPrimitive.getRank());
TestUtils.assertEquals("rank() SVD vs Jama", tmpSVD.getRank(), tmpJama.getRank());
}