/* * MarkovJumpsCore.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.inference.markovjumps; import java.util.Arrays; /** * @author Marc Suchard * @author Vladimir Minin * * A base class for implementing Markov chain-induced counting processes (markovjumps) in BEAST using BEAGLE * This work is supported by NSF grant 0856099 * * Minin VN and Suchard MA (2008) Counting labeled transitions in continous-time Markov models of evolution. * Journal of Mathematical Biology, 56, 391-412. * */ public class MarkovJumpsCore { public MarkovJumpsCore(int stateCount) { this.stateCount = stateCount; this.stateCount2 = stateCount * stateCount; auxInt = new double[stateCount2]; tmp1 = new double[stateCount2]; tmp2 = new double[stateCount2]; expEvalScalar = new double[stateCount]; } //SEXP aux_mat1(SEXP x, SEXP y){ // int i, j, nx; // double *vec, scalar; // SEXP ans; // // nx = length(x); // x = coerceVector(x, REALSXP); // y = coerceVector(y, REALSXP); // // vec = REAL(x); // scalar = REAL(y)[0]; // // // PROTECT(ans = allocMatrix(REALSXP, nx, nx)); // // for(i = 0; i < nx; i++) { // for(j = 0; j < nx; j++){ // if ((vec[i]-vec[j]<10e-7) && (vec[i]-vec[j]>-10e-7)){ // REAL(ans)[i + nx*j] = exp(vec[j]*scalar)*scalar; // }else{ // REAL(ans)[i + nx*j] = (exp(vec[i]*scalar) - exp(vec[j]*scalar))/(vec[i] - vec[j]); // } // } // } // // UNPROTECT(1); // return(ans); //} private void populateAuxInt(double[] eval, double scalar, double[] auxInt) { for (int i = 0; i < stateCount; i++) { expEvalScalar[i] = Math.exp(eval[i] * scalar); } int index = 0; for (int i = 0; i < stateCount; i++) { for (int j = 0; j < stateCount; j++) { if (Math.abs(eval[i] - eval[j]) < 1E-7) { auxInt[index] = expEvalScalar[i] * scalar; } else { auxInt[index] = (expEvalScalar[i] - expEvalScalar[j]) / (eval[i] - eval[j]); } index++; } } } public void computeCondStatMarkovJumps(double[] evec, double[] ievc, double[] eval, double[] rateReg, double time, double[] transitionProbs, double[] countMatrix) { computeJointStatMarkovJumps(evec, ievc, eval, rateReg, time, countMatrix); for(int i=0; i