本文整理汇总了Java中org.ojalgo.matrix.store.MatrixStore.doubleValue方法的典型用法代码示例。如果您正苦于以下问题:Java MatrixStore.doubleValue方法的具体用法?Java MatrixStore.doubleValue怎么用?Java MatrixStore.doubleValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ojalgo.matrix.store.MatrixStore
的用法示例。
在下文中一共展示了MatrixStore.doubleValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
/**
* Will solve the equation system [aMtrxV][aMtrxD][X]=[aMtrxSimilar]<sup>T</sup> and overwrite the
* solution [X] to [aV].
*/
private void solve(final PhysicalStore<N> aMtrxV, final MatrixStore<N> aMtrxD, final DiagonalBasicArray<N> aMtrxSimilar) {
final int tmpDim = (int) aMtrxV.countRows();
final int tmpLim = tmpDim - 1;
double tmpSingular;
for (int j = 0; j < tmpDim; j++) {
tmpSingular = aMtrxD.doubleValue(j, j);
final double value = tmpSingular;
if (PrimitiveScalar.isSmall(PrimitiveMath.ONE, value)) {
for (int i = 0; i < tmpDim; i++) {
aMtrxV.set(i, j, PrimitiveMath.ZERO);
}
} else {
for (int i = 0; i < tmpLim; i++) {
aMtrxV.set(i, j,
((aMtrxSimilar.doubleValue(i, i) * aMtrxV.doubleValue(i, j)) + (aMtrxSimilar.doubleValue(i, i + 1) * aMtrxV.doubleValue(i + 1, j)))
/ tmpSingular);
}
aMtrxV.set(tmpLim, j, (aMtrxSimilar.doubleValue(tmpLim, tmpLim) * aMtrxV.doubleValue(tmpLim, j)) / tmpSingular);
}
}
}
示例2: copyEigenvector
import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
/**
* @deprecated With Java 9 this will be made private. Use {@link #getEigenvectors()} or
* {@link #getEigenvector(int)} instead.
*/
@Deprecated
default void copyEigenvector(final int index, final Array1D<ComplexNumber> destination) {
final MatrixStore<N> tmpV = this.getV();
final MatrixStore<N> tmpD = this.getD();
final long tmpDimension = tmpD.countColumns();
final int prevCol = index - 1;
final int nextCol = index + 1;
if ((index < (tmpDimension - 1L)) && (tmpD.doubleValue(nextCol, index) != 0.0)) {
for (int i = 0; i < tmpDimension; i++) {
destination.set(i, ComplexNumber.of(tmpV.doubleValue(i, index), tmpV.doubleValue(i, nextCol)));
}
} else if ((index > 0) && (tmpD.doubleValue(prevCol, index) != 0.0)) {
for (int i = 0; i < tmpDimension; i++) {
destination.set(i, ComplexNumber.of(tmpV.doubleValue(i, prevCol), -tmpV.doubleValue(i, index)));
}
} else {
for (int i = 0; i < tmpDimension; i++) {
destination.set(i, tmpV.doubleValue(i, index));
}
}
}
示例3: solve2
import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
private DecompositionStore<N> solve2(final PhysicalStore<N> aMtrxV, final MatrixStore<N> aMtrxD, final DiagonalBasicArray<N> aMtrxSimilar) {
final int tmpDim = (int) aMtrxV.countRows();
final int tmpLim = tmpDim - 1;
final DecompositionStore<N> retVal = this.makeZero(tmpDim, tmpDim);
double tmpSingular;
for (int j = 0; j < tmpDim; j++) {
tmpSingular = aMtrxD.doubleValue(j, j);
final double value = tmpSingular;
if (PrimitiveScalar.isSmall(PrimitiveMath.ONE, value)) {
for (int i = 0; i < tmpDim; i++) {
retVal.set(i, j, aMtrxV.doubleValue(i, j));
}
} else {
for (int i = 0; i < tmpLim; i++) {
retVal.set(i, j,
((aMtrxSimilar.doubleValue(i, i) * aMtrxV.doubleValue(i, j)) + (aMtrxSimilar.doubleValue(i, i + 1) * aMtrxV.doubleValue(i + 1, j)))
/ tmpSingular);
}
retVal.set(tmpLim, j, (aMtrxSimilar.doubleValue(tmpLim, tmpLim) * aMtrxV.doubleValue(tmpLim, j)) / tmpSingular);
}
}
return retVal;
}
示例4: toCorrelations
import org.ojalgo.matrix.store.MatrixStore; //导入方法依赖的package包/类
/**
* Will extract the correlation coefficients from the input covariance matrix. If "cleaning" is enabled
* small and negative eigenvalues of the covariance matrix will be replaced with a new minimal value.
*/
public static PrimitiveMatrix toCorrelations(final Access2D<?> covariances, final boolean clean) {
final int tmpSize = (int) Math.min(covariances.countRows(), covariances.countColumns());
MatrixStore<Double> tmpCovariances = MatrixStore.PRIMITIVE.makeWrapper(covariances).get();
if (clean) {
final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(true);
tmpEvD.decompose(tmpCovariances);
final MatrixStore<Double> tmpV = tmpEvD.getV();
final PhysicalStore<Double> tmpD = tmpEvD.getD().copy();
final double tmpLargest = tmpEvD.getEigenvalues().get(0).norm();
final double tmpLimit = tmpLargest * tmpSize * PrimitiveFunction.SQRT.invoke(PrimitiveMath.MACHINE_EPSILON);
for (int ij = 0; ij < tmpSize; ij++) {
if (tmpD.doubleValue(ij, ij) < tmpLimit) {
tmpD.set(ij, ij, tmpLimit);
}
}
final MatrixStore<Double> tmpLeft = tmpV;
final MatrixStore<Double> tmpMiddle = tmpD;
final MatrixStore<Double> tmpRight = tmpLeft.transpose();
tmpCovariances = tmpLeft.multiply(tmpMiddle).multiply(tmpRight);
}
final Builder<PrimitiveMatrix> retVal = PrimitiveMatrix.FACTORY.getBuilder(tmpSize, tmpSize);
final double[] tmpVolatilities = new double[tmpSize];
for (int ij = 0; ij < tmpSize; ij++) {
tmpVolatilities[ij] = PrimitiveFunction.SQRT.invoke(tmpCovariances.doubleValue(ij, ij));
}
for (int j = 0; j < tmpSize; j++) {
final double tmpColVol = tmpVolatilities[j];
retVal.set(j, j, PrimitiveMath.ONE);
for (int i = j + 1; i < tmpSize; i++) {
final double tmpCovariance = tmpCovariances.doubleValue(i, j);
final double tmpCorrelation = tmpCovariance / (tmpVolatilities[i] * tmpColVol);
retVal.set(i, j, tmpCorrelation);
retVal.set(j, i, tmpCorrelation);
}
}
return retVal.get();
}
示例5: 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;
}
示例6: 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;
}