use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class ComplexSubstitutionModel method printLastProbabilityMatrix.
public void printLastProbabilityMatrix() {
getLogLikelihood();
System.err.println((probability == null) ? "Null probability vector" : "Not null probability vector");
if (probability == null) {
boolean test = BayesianStochasticSearchVariableSelection.Utils.connectedAndWellConditioned(probability, this);
System.err.println("BSSVS valid = " + test);
}
System.err.println(new Vector(probability));
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class HKY method main.
public static void main(String[] args) {
// double kappa = 2.0;
// double[] pi = new double[]{0.15,0.30,0.20,0.35};
// double time = 0.1;
double kappa = 1.0;
double[] pi = new double[] { 0.25, 0.25, 0.25, 0.25 };
double time = 0.1;
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, pi);
HKY hky = new HKY(kappa, freqModel);
EigenDecomposition decomp = hky.getEigenDecomposition();
// Matrix evec = new Matrix(decomp.getEigenVectors());
// Matrix ivec = new Matrix(decomp.getInverseEigenVectors());
// System.out.println("Evec =\n"+evec);
// System.out.println("Ivec =\n"+ivec);
Vector eval = new Vector(decomp.getEigenValues());
System.out.println("Eval = " + eval);
double[] probs = new double[16];
hky.getTransitionProbabilities(time, probs);
System.out.println("new probs = " + new Vector(probs));
// check against old implementation
dr.oldevomodel.substmodel.FrequencyModel oldFreq = new dr.oldevomodel.substmodel.FrequencyModel(Nucleotides.INSTANCE, pi);
dr.oldevomodel.substmodel.HKY oldHKY = new dr.oldevomodel.substmodel.HKY(kappa, oldFreq);
oldHKY.setKappa(kappa);
oldHKY.getTransitionProbabilities(time, probs);
System.out.println("old probs = " + new Vector(probs));
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class WishartStatisticsWrapper method simulateMissingTraits.
private void simulateMissingTraits() {
// Force new sample!
likelihoodDelegate.fireModelChanged();
// ProcessSimulationDelegate.MeanAndVariance mv =
// (ProcessSimulationDelegate.MeanAndVariance) tipFullConditionalTrait.getTrait(
// dataLikelihood.getTree(), dataLikelihood.getTree().getExternalNode(1));
//
// System.err.println("DONE");
// System.exit(-1);
double[] sample = (double[]) tipSampleTrait.getTrait(dataLikelihood.getTree(), null);
if (DEBUG) {
System.err.println("Attempting to simulate missing traits");
System.err.println(new Vector(sample));
}
final ContinuousDiffusionIntegrator cdi = outerProductDelegate.getIntegrator();
assert (cdi instanceof ContinuousDiffusionIntegrator.Basic);
double[] buffer = new double[dimPartial * numTrait];
for (int trait = 0; trait < numTrait; ++trait) {
buffer[trait * dimPartial + dimTrait] = Double.POSITIVE_INFINITY;
}
for (int tip = 0; tip < tipCount; ++tip) {
int sampleOffset = tip * dimTrait * numTrait;
int bufferOffset = 0;
for (int trait = 0; trait < numTrait; ++trait) {
System.arraycopy(sample, sampleOffset, buffer, bufferOffset, dimTrait);
sampleOffset += dimTrait;
bufferOffset += dimPartial;
}
outerProductDelegate.setTipDataDirectly(tip, buffer);
}
if (DEBUG) {
System.err.println("Finished draw");
}
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class KernelDensityEstimator2D method main.
public static void main(String[] arg) {
double[] x = { 3.4, 1.2, 5.6, 2.2, 3.1 };
double[] y = { 1.0, 2.0, 1.0, 2.0, 1.0 };
KernelDensityEstimator2D kde = new KernelDensityEstimator2D(x, y, 4);
System.out.println(new Vector(kde.getXGrid()));
System.out.println(new Vector(kde.getYGrid()));
System.out.println(new Matrix(kde.getKDE()));
System.exit(-1);
}
use of dr.math.matrixAlgebra.Vector in project beast-mcmc by beast-dev.
the class MarkovJumpsSubstitutionModelTest method testMarkovJumpsCounts.
public void testMarkovJumpsCounts() {
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();
MarkovJumpsSubstitutionModel markovjumps = new MarkovJumpsSubstitutionModel(substModel, MarkovJumpsType.COUNTS);
double[] r = new double[states * states];
double[] q = new double[states * states];
double[] j = new double[states * states];
double[] c = new double[states * states];
double[] p = new double[states * states];
double time = 1.0;
// A
int from = 0;
// C
int to = 1;
MarkovJumpsCore.fillRegistrationMatrix(r, from, to, states, 1.0);
markovjumps.setRegistration(r);
substModel.getInfinitesimalMatrix(q);
substModel.getTransitionProbabilities(time, p);
markovjumps.computeJointStatMarkovJumps(time, j);
markovjumps.computeCondStatMarkovJumps(time, c);
MarkovJumpsCore.makeComparableToRPackage(q);
System.out.println("Q = " + new Vector(q));
MarkovJumpsCore.makeComparableToRPackage(p);
System.out.println("P = " + new Vector(p));
System.out.println("Counts:");
MarkovJumpsCore.makeComparableToRPackage(r);
System.out.println("R = " + new Vector(r));
MarkovJumpsCore.makeComparableToRPackage(j);
System.out.println("J = " + new Vector(j));
assertEquals(rMarkovJumpsJ, j, tolerance);
MarkovJumpsCore.makeComparableToRPackage(c);
System.err.println("C = " + new Vector(c));
assertEquals(rMarkovJumpsC, c, tolerance);
}
Aggregations