use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class ComplexDenseStore method divideAndCopyColumn.
public void divideAndCopyColumn(final int row, final int column, final BasicArray<ComplexNumber> destination) {
final ComplexNumber[] tmpData = data;
final int tmpRowDim = myRowDim;
final ComplexNumber[] tmpDestination = ((ComplexArray) destination).data;
int tmpIndex = row + (column * tmpRowDim);
final ComplexNumber tmpDenominator = tmpData[tmpIndex];
for (int i = row + 1; i < tmpRowDim; i++) {
tmpIndex++;
tmpDestination[i] = tmpData[tmpIndex] = tmpData[tmpIndex].divide(tmpDenominator);
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class PrimitiveDenseStore method computeInPlaceSchur.
public Array1D<ComplexNumber> computeInPlaceSchur(final PhysicalStore<Double> transformationCollector, final boolean eigenvalue) {
// final PrimitiveDenseStore tmpThisCopy = this.copy();
// final PrimitiveDenseStore tmpCollCopy = (PrimitiveDenseStore)
// aTransformationCollector.copy();
//
// tmpThisCopy.computeInPlaceHessenberg(true);
// Actual
final double[] tmpData = data;
final double[] tmpCollectorData = ((PrimitiveDenseStore) transformationCollector).data;
final double[] tmpVctrWork = new double[this.getMinDim()];
EvD1D.orthes(tmpData, tmpCollectorData, tmpVctrWork);
// BasicLogger.logDebug("Schur Step", this);
// BasicLogger.logDebug("Hessenberg", tmpThisCopy);
final double[][] tmpDiags = EvD1D.hqr2(tmpData, tmpCollectorData, eigenvalue);
final double[] aRawReal = tmpDiags[0];
final double[] aRawImag = tmpDiags[1];
final int tmpLength = Math.min(aRawReal.length, aRawImag.length);
final ComplexArray retVal = ComplexArray.make(tmpLength);
final ComplexNumber[] tmpRaw = retVal.data;
for (int i = 0; i < tmpLength; i++) {
tmpRaw[i] = ComplexNumber.of(aRawReal[i], aRawImag[i]);
}
return Array1D.COMPLEX.wrap(retVal);
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class HouseholderHermitian method invoke.
public static void invoke(final ComplexNumber[] data, final Householder.Complex householder, final ComplexNumber[] worker) {
final ComplexNumber[] tmpVector = householder.vector;
final int tmpFirst = householder.first;
final int tmpLength = tmpVector.length;
final ComplexNumber tmpBeta = householder.beta;
final int tmpCount = tmpLength - tmpFirst;
if (tmpCount > MultiplyHermitianAndVector.THRESHOLD) {
final DivideAndConquer tmpConqurer = new DivideAndConquer() {
@Override
protected void conquer(final int first, final int limit) {
MultiplyHermitianAndVector.invoke(worker, first, limit, data, tmpVector, tmpFirst, ComplexNumber.FACTORY);
}
};
tmpConqurer.invoke(tmpFirst, tmpLength, MultiplyHermitianAndVector.THRESHOLD);
} else {
MultiplyHermitianAndVector.invoke(worker, tmpFirst, tmpLength, data, tmpVector, tmpFirst, ComplexNumber.FACTORY);
}
ComplexNumber tmpVal = ComplexNumber.ZERO;
for (int c = tmpFirst; c < tmpLength; c++) {
// tmpVal += tmpVector[c] * worker[c];
tmpVal = tmpVal.add(tmpVector[c].conjugate().multiply(worker[c]));
}
// tmpVal *= (tmpBeta / TWO);
tmpVal = ComplexFunction.DIVIDE.invoke(tmpVal.multiply(tmpBeta), ComplexNumber.TWO);
for (int c = tmpFirst; c < tmpLength; c++) {
// worker[c] = tmpBeta * (worker[c] - (tmpVal * tmpVector[c]));
worker[c] = tmpBeta.multiply(worker[c].subtract(tmpVal.multiply(tmpVector[c])));
}
if (tmpCount > HermitianRank2Update.THRESHOLD) {
final DivideAndConquer tmpConqurer = new DivideAndConquer() {
@Override
protected void conquer(final int first, final int limit) {
HermitianRank2Update.invoke(data, first, limit, tmpVector, worker);
}
};
tmpConqurer.invoke(tmpFirst, tmpLength, HermitianRank2Update.THRESHOLD);
} else {
HermitianRank2Update.invoke(data, tmpFirst, tmpLength, tmpVector, worker);
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class EigenvalueTest method testPrimitiveAsComplex.
@Test
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);
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class EigenvalueTest method testP20061119Case.
@Test
public void testP20061119Case() {
final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.copy(P20061119Case.getProblematic());
final ComplexNumber tmp00 = ComplexNumber.valueOf(26.14421883828456);
final ComplexNumber tmp11 = ComplexNumber.of(2.727890580857718, 3.6223578444417908);
final ComplexNumber tmp22 = tmp11.conjugate();
final ComplexNumber tmp33 = ComplexNumber.ZERO;
final ComplexNumber tmp44 = tmp33;
final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { tmp00, tmp11, tmp22, tmp33, tmp44 });
final NumberContext accuracyContext = new NumberContext(7, 6);
MatrixStore<Double> tmpRecreatedMatrix;
final Eigenvalue<Double> tmpDecomposition = Eigenvalue.PRIMITIVE.make(tmpOriginalMatrix);
tmpDecomposition.decompose(tmpOriginalMatrix);
final Array1D<ComplexNumber> tmpEigenvalues = tmpDecomposition.getEigenvalues();
final MatrixStore<Double> tmpD = tmpDecomposition.getD();
final MatrixStore<Double> tmpV = tmpDecomposition.getV();
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Eigenvalues = {}", tmpEigenvalues);
BasicLogger.debug("D = {}", tmpD);
BasicLogger.debug("V = {}", tmpV);
}
tmpRecreatedMatrix = tmpV.multiply(tmpDecomposition.getD()).multiply(tmpV.transpose());
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Original = {}", tmpOriginalMatrix);
BasicLogger.debug("Recreated = {}", tmpRecreatedMatrix);
}
TestUtils.assertEquals(tmpOriginalMatrix.multiply(tmpV), tmpV.multiply(tmpDecomposition.getD()), accuracyContext);
tmpExpectedDiagonal.sortDescending();
tmpEigenvalues.sortDescending();
TestUtils.assertEquals(tmpExpectedDiagonal, tmpEigenvalues, accuracyContext);
tmpDecomposition.computeValuesOnly(tmpOriginalMatrix);
final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpDecomposition.getEigenvalues();
TestUtils.assertEquals(tmpExpectedDiagonal, tmpEigenvaluesOnly, accuracyContext);
}
Aggregations