| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.substmodel; |
| 27 |
|
| 28 |
import cern.colt.matrix.DoubleMatrix2D; |
| 29 |
import dr.math.matrixAlgebra.RobustEigenDecomposition; |
| 30 |
|
| 31 |
import java.util.Arrays; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class ComplexColtEigenSystem extends ColtEigenSystem { |
| 37 |
|
| 38 |
public ComplexColtEigenSystem(int stateCount) { |
| 39 |
super(stateCount); |
| 40 |
} |
| 41 |
|
| 42 |
public ComplexColtEigenSystem(int stateCount, boolean checkConditioning, int maxConditionNumber, int maxIterations) { |
| 43 |
super(stateCount, checkConditioning, maxConditionNumber, maxIterations); |
| 44 |
} |
| 45 |
|
| 46 |
protected double[] getAllEigenValues(RobustEigenDecomposition decomposition) { |
| 47 |
double[] realEval = decomposition.getRealEigenvalues().toArray(); |
| 48 |
double[] imagEval = decomposition.getImagEigenvalues().toArray(); |
| 49 |
|
| 50 |
final int dim = realEval.length; |
| 51 |
double[] merge = new double[2 * dim]; |
| 52 |
System.arraycopy(realEval, 0, merge, 0, dim); |
| 53 |
System.arraycopy(imagEval, 0, merge, dim, dim); |
| 54 |
return merge; |
| 55 |
} |
| 56 |
|
| 57 |
protected double[] getEmptyAllEigenValues(int dim) { |
| 58 |
return new double[2 * dim]; |
| 59 |
} |
| 60 |
|
| 61 |
protected boolean validDecomposition(DoubleMatrix2D eigenV) { |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
public double computeExponential(EigenDecomposition eigen, double distance, int i, int j) { |
| 66 |
throw new RuntimeException("Not yet implemented"); |
| 67 |
} |
| 68 |
|
| 69 |
public void computeExponential(EigenDecomposition eigen, double distance, double[] matrix) { |
| 70 |
double temp; |
| 71 |
|
| 72 |
if (eigen == null) { |
| 73 |
Arrays.fill(matrix, 0.0); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
double[] Evec = eigen.getEigenVectors(); |
| 78 |
double[] Eval = eigen.getEigenValues(); |
| 79 |
double[] EvalImag = new double[stateCount]; |
| 80 |
System.arraycopy(Eval, stateCount, EvalImag, 0, stateCount); |
| 81 |
double[] Ievc = eigen.getInverseEigenVectors(); |
| 82 |
|
| 83 |
double[][] iexp = new double[stateCount][stateCount]; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
for (int i = 0; i < stateCount; i++) { |
| 99 |
|
| 100 |
if (EvalImag[i] == 0) { |
| 101 |
|
| 102 |
temp = Math.exp(distance * Eval[i]); |
| 103 |
for (int j = 0; j < stateCount; j++) { |
| 104 |
iexp[i][j] = Ievc[i * stateCount + j] * temp; |
| 105 |
} |
| 106 |
} else { |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
int i2 = i + 1; |
| 111 |
double b = EvalImag[i]; |
| 112 |
double expat = Math.exp(distance * Eval[i]); |
| 113 |
double expatcosbt = expat * Math.cos(distance * b); |
| 114 |
double expatsinbt = expat * Math.sin(distance * b); |
| 115 |
|
| 116 |
for (int j = 0; j < stateCount; j++) { |
| 117 |
iexp[i][j] = expatcosbt * Ievc[i * stateCount + j] + |
| 118 |
expatsinbt * Ievc[i2 * stateCount + j]; |
| 119 |
iexp[i2][j] = expatcosbt * Ievc[i2 * stateCount + j] - |
| 120 |
expatsinbt * Ievc[i * stateCount + j]; |
| 121 |
} |
| 122 |
i++; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
int u = 0; |
| 127 |
for (int i = 0; i < stateCount; i++) { |
| 128 |
for (int j = 0; j < stateCount; j++) { |
| 129 |
temp = 0.0; |
| 130 |
for (int k = 0; k < stateCount; k++) { |
| 131 |
temp += Evec[i * stateCount + k] * iexp[k][j]; |
| 132 |
} |
| 133 |
matrix[u] = Math.abs(temp); |
| 134 |
u++; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
} |