From eb2a37024d1289a0d82d6d190df048a1066ae229 Mon Sep 17 00:00:00 2001 From: Marc Suchard Date: Mon, 25 Sep 2023 13:05:32 -0700 Subject: [PATCH] missing function --- .../DifferentiableSubstitutionModelUtil.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/dr/evomodel/substmodel/DifferentiableSubstitutionModelUtil.java b/src/dr/evomodel/substmodel/DifferentiableSubstitutionModelUtil.java index 2231539327..c8f6469236 100644 --- a/src/dr/evomodel/substmodel/DifferentiableSubstitutionModelUtil.java +++ b/src/dr/evomodel/substmodel/DifferentiableSubstitutionModelUtil.java @@ -328,6 +328,25 @@ public static double[] getQQPlus(double[] eigenVectors, double[] inverseEigenVec return result; } + public static double[] getQPlusQ(double[] eigenVectors, double[] inverseEigenVectors, int index, int stateCount) { + + double[] result = new double[stateCount * stateCount]; + + for (int i = 0; i < stateCount; ++i) { + for (int j = 0; j < stateCount; ++j) { + double sum = 0.0; + for (int k = 0; k < stateCount; ++k) { + if (k != index) { + sum += inverseEigenVectors[i * stateCount + k] * eigenVectors[k * stateCount + j]; + } + } + result[i * stateCount + j] = sum; + } + } + + return result; + } + private static int index12(int i, int j, int stateCount) { return i * stateCount + j; }