use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class MarkovJumpsSubstitutionModelTest method testMarkovJumpsReward.
public void testMarkovJumpsReward() {
HKY substModel = new HKY(2.0, new FrequencyModel(Nucleotides.INSTANCE, // A,C,G,T
new double[] { 0.3, 0.2, 0.25, 0.25 }));
int states = substModel.getDataType().getStateCount();
double[] j = new double[states * states];
double[] c = new double[states * states];
double time = 1.0;
MarkovJumpsSubstitutionModel markovjumps = new MarkovJumpsSubstitutionModel(substModel, MarkovJumpsType.REWARDS);
double[] rewards = { 1.0, 1.0, 1.0, 1.0 };
markovjumps.setRegistration(rewards);
markovjumps.computeJointStatMarkovJumps(time, j);
markovjumps.computeCondStatMarkovJumps(time, c);
System.out.println("Rewards:");
MarkovJumpsCore.makeComparableToRPackage(rewards);
System.out.println("R = " + new Vector(rewards));
MarkovJumpsCore.makeComparableToRPackage(j);
System.out.println("J = " + new Vector(j));
assertEquals(rMarkovRewardsJ, j, tolerance);
MarkovJumpsCore.makeComparableToRPackage(c);
System.out.println("C = " + new Vector(c));
assertEquals(rMarkovRewardsC, c, tolerance);
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class CompleteHistorySimulatorTest method runSimulation.
protected void runSimulation(int N, Tree tree, GammaSiteRateModel siteModel, BranchRateModel branchRateModel, int nSites, double[][] registers, double analyticResult, Parameter variableParam, Parameter valuesParam) {
CompleteHistorySimulator simulator = new CompleteHistorySimulator(tree, siteModel, branchRateModel, nSites, false, variableParam, valuesParam);
for (int r = 0; r < registers.length; r++) {
Parameter registerParameter = new Parameter.Default(registers[r]);
registerParameter.setId("set" + (r + 1));
simulator.addRegister(registerParameter, MarkovJumpsType.COUNTS, false);
}
int nJumps = simulator.getNumberOfJumpProcess();
double[] results = new double[nJumps];
for (int rep = 0; rep < N; rep++) {
// Generate new history
simulator.simulate();
for (int jump = 0; jump < nJumps; jump++) {
results[jump] += accumulateJumpsOverTree(tree, simulator, jump);
}
}
for (int jump = 0; jump < nJumps; jump++) {
results[jump] /= (double) N * (double) nSites;
}
if (nJumps > 0) {
System.out.println("simulations = " + new Vector(results));
} else {
System.out.println("No jump processes!");
}
double simulationResult = accumulate(results);
assertEquals(analyticResult, simulationResult, 1E-2);
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class MathTestCase method printSquareMatrix.
protected void printSquareMatrix(double[] A, int dim) {
double[] row = new double[dim];
for (int i = 0; i < dim; i++) {
System.arraycopy(A, i * dim, row, 0, dim);
System.out.println(new Vector(row));
}
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class SpecificEigendecompositionTest method testEigendecomposition.
public void testEigendecomposition() {
System.out.println("Testing specific eigendecomposition...");
ComplexSubstitutionModel csm = setupModel(dim, testRates);
double[] tmp = new double[dim * dim];
csm.getInfinitesimalMatrix(tmp);
System.out.println("Rates: " + new Vector(tmp) + "\n");
EigenDecomposition e = csm.getEigenDecomposition();
System.out.println("Val: " + new Vector(e.getEigenValues()));
System.out.println("Vec: " + new Vector(e.getEigenVectors()));
System.out.println("Inv: " + new Vector(e.getInverseEigenVectors()));
csm.getTransitionProbabilities(1.0, tmp);
System.out.println(new Vector(tmp));
double[] eigenValues = e.getEigenValues();
Arrays.sort(eigenValues);
assertEquals(checkEigenvalues, e.getEigenValues(), tolerance);
}
Aggregations