use of dr.oldevomodel.substmodel.OnePhaseModel in project beast-mcmc by beast-dev.
the class LinearBiasTest method testLinearBiasModel.
public void testLinearBiasModel() {
for (Instance test : all) {
OnePhaseModel subModel = test.getSubModel();
Microsatellite microsat = (Microsatellite) subModel.getDataType();
Parameter biasLinear = new Parameter.Default(1, test.getBiasLinearParam());
Parameter biasConstant = new Parameter.Default(1, test.getBiasConstantParam());
LinearBiasModel lbm = new LinearBiasModel(microsat, null, subModel, biasConstant, biasLinear, test.isLogistics(), false, false);
lbm.computeStationaryDistribution();
double[] statDist = lbm.getStationaryDistribution();
final double[] expectedStatDist = test.getExpectedPi();
for (int k = 0; k < statDist.length; ++k) {
assertEquals(statDist[k], expectedStatDist[k], 1e-10);
}
int stateCount = microsat.getStateCount();
double[] mat = new double[stateCount * stateCount];
lbm.getTransitionProbabilities(test.getDistance(), mat);
final double[] result = test.getExpectedResult();
int k;
for (k = 0; k < mat.length; ++k) {
assertEquals(result[k], mat[k], 5e-9);
//System.out.print(" " + (mat[k] - result[k]));
}
k = 0;
for (int i = 0; i < microsat.getStateCount(); i++) {
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[k++], lbm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 5e-9);
}
}
for (int j = 0; j < microsat.getStateCount(); j++) {
double[] colTransitionProb = lbm.getColTransitionProbabilities(test.getDistance(), j);
for (int i = 0; i < microsat.getStateCount(); i++) {
assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 5e-9);
}
}
for (int i = 0; i < microsat.getStateCount(); i++) {
double[] rowTransitionProb = lbm.getRowTransitionProbabilities(test.getDistance(), i);
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 5e-9);
}
}
}
}
use of dr.oldevomodel.substmodel.OnePhaseModel in project beast-mcmc by beast-dev.
the class TwoPhaseModelParser method parseXMLObject.
//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
Microsatellite dataType = (Microsatellite) xo.getChild(Microsatellite.class);
Parameter.Default geoParam = (Parameter.Default) xo.getElementFirstChild(GEO_PARAM);
Parameter paramP = (Parameter) xo.getElementFirstChild(ONEPHASEPR_PARAM);
Parameter limitE = null;
if (xo.hasChildNamed(TRANS_PARAM)) {
limitE = (Parameter) xo.getElementFirstChild(TRANS_PARAM);
}
boolean estimateSubmodelParams = xo.getAttribute(ESTIMATE_SUBMODEL_PARAMS, false);
FrequencyModel freqModel = null;
if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
}
return new TwoPhaseModel(dataType, freqModel, subModel, paramP, geoParam, limitE, estimateSubmodelParams);
}
use of dr.oldevomodel.substmodel.OnePhaseModel in project beast-mcmc by beast-dev.
the class LinearBiasModelParser method parseXMLObject.
//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
Microsatellite dataType = (Microsatellite) subModel.getDataType();
Parameter biasConst = null;
if (xo.hasChildNamed(BIAS_CONSTANT)) {
biasConst = (Parameter) xo.getElementFirstChild(BIAS_CONSTANT);
}
Parameter biasLin = null;
if (xo.hasChildNamed(BIAS_LINEAR)) {
biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR);
}
//get FrequencyModel
FrequencyModel freqModel = null;
if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
}
boolean estimateSubmodelParams = false;
if (xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)) {
estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS);
}
System.out.println("Is estimating submodel parameter(s): " + estimateSubmodelParams);
boolean logistics = false;
if (xo.hasAttribute(LOGISTICS)) {
logistics = xo.getBooleanAttribute(LOGISTICS);
}
System.out.println("Using logistic regression: " + logistics);
boolean isSubmodel = false;
if (xo.hasAttribute(IS_SUBMODEL)) {
isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL);
}
System.out.println("Is a submodel: " + isSubmodel);
return new LinearBiasModel(dataType, freqModel, subModel, biasConst, biasLin, logistics, estimateSubmodelParams, isSubmodel);
}
use of dr.oldevomodel.substmodel.OnePhaseModel in project beast-mcmc by beast-dev.
the class TwoPhaseModelTest method testTwoPhaseModel.
public void testTwoPhaseModel() {
for (Instance test : all) {
OnePhaseModel subModel = test.getSubModel();
Microsatellite microsat = (Microsatellite) subModel.getDataType();
Parameter pParam = new Parameter.Default(test.getPParam());
Parameter mParam = new Parameter.Default(test.getMParam());
TwoPhaseModel tpm = new TwoPhaseModel(microsat, null, subModel, pParam, mParam, null, false);
int k;
tpm.computeStationaryDistribution();
double[] statDist = tpm.getStationaryDistribution();
final double[] expectedStatDist = test.getPi();
for (k = 0; k < statDist.length; ++k) {
assertEquals(statDist[k], expectedStatDist[k], 1e-10);
}
int stateCount = microsat.getStateCount();
double[] mat = new double[stateCount * stateCount];
tpm.getTransitionProbabilities(test.getDistance(), mat);
final double[] result = test.getExpectedResult();
for (k = 0; k < mat.length; ++k) {
assertEquals(result[k], mat[k], 5e-9);
//System.out.print(" " + (mat[k]));// - result[k]));
}
k = 0;
for (int i = 0; i < microsat.getStateCount(); i++) {
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[k++], tpm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
}
}
for (int j = 0; j < microsat.getStateCount(); j++) {
double[] colTransitionProb = tpm.getColTransitionProbabilities(test.getDistance(), j);
for (int i = 0; i < microsat.getStateCount(); i++) {
assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
}
}
for (int i = 0; i < microsat.getStateCount(); i++) {
double[] rowTransitionProb = tpm.getRowTransitionProbabilities(test.getDistance(), i);
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
}
}
}
}
Aggregations