Search in sources :

Example 31 with ComplexNumber

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);
    }
}
Also used : ComplexArray(org.ojalgo.array.ComplexArray) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 32 with ComplexNumber

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);
}
Also used : ComplexArray(org.ojalgo.array.ComplexArray) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 33 with ComplexNumber

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);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 34 with ComplexNumber

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);
}
Also used : ComplexDenseStore(org.ojalgo.matrix.store.ComplexDenseStore) ComplexNumber(org.ojalgo.scalar.ComplexNumber) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 35 with ComplexNumber

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);
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Aggregations

ComplexNumber (org.ojalgo.scalar.ComplexNumber)53 Test (org.junit.jupiter.api.Test)20 NumberContext (org.ojalgo.type.context.NumberContext)16 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)7 ComplexArray (org.ojalgo.array.ComplexArray)5 BigDecimal (java.math.BigDecimal)4 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)4 BasicMatrix (org.ojalgo.matrix.BasicMatrix)3 Householder (org.ojalgo.matrix.transformation.Householder)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2 ComplexDenseStore (org.ojalgo.matrix.store.ComplexDenseStore)2 Normal (org.ojalgo.random.Normal)2 Quaternion (org.ojalgo.scalar.Quaternion)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Uniform (org.ojalgo.random.Uniform)1