use of dr.inference.distribution.LogLinearModel in project beast-mcmc by beast-dev.
the class GeneralizedLinearModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
// System.err.println("PASSED 0");
XMLObject cxo = xo.getChild(DEPENDENT_VARIABLES);
Parameter dependentParam = null;
if (cxo != null)
dependentParam = (Parameter) cxo.getChild(Parameter.class);
String family = xo.getStringAttribute(FAMILY);
GeneralizedLinearModel glm;
if (family.compareTo(LOGISTIC_REGRESSION) == 0) {
glm = new LogisticRegression(dependentParam);
} else if (family.compareTo(NORMAL_REGRESSION) == 0) {
glm = new LinearRegression(dependentParam, false);
} else if (family.compareTo(LOG_NORMAL_REGRESSION) == 0) {
glm = new LinearRegression(dependentParam, true);
} else if (family.compareTo(LOG_LINEAR) == 0) {
glm = new LogLinearModel(dependentParam);
} else
throw new XMLParseException("Family '" + family + "' is not currently implemented");
if (glm.requiresScale()) {
cxo = xo.getChild(SCALE_VARIABLES);
Parameter scaleParameter = null;
// DesignMatrix designMatrix = null;
Parameter scaleDesign = null;
if (cxo != null) {
scaleParameter = (Parameter) cxo.getChild(Parameter.class);
XMLObject gxo = cxo.getChild(INDICATOR);
if (gxo != null)
scaleDesign = (Parameter) gxo.getChild(Parameter.class);
// designMatrix = (DesignMatrix) cxo.getChild(DesignMatrix.class);
}
if (scaleParameter == null)
throw new XMLParseException("Family '" + family + "' requires scale parameters");
if (scaleDesign == null)
scaleDesign = new Parameter.Default(dependentParam.getDimension(), 0.0);
else {
if (scaleDesign.getDimension() != dependentParam.getDimension())
throw new XMLParseException("Scale (" + dependentParam.getDimension() + ") and scaleDesign parameters (" + scaleDesign.getDimension() + ") must be the same dimension");
for (int i = 0; i < scaleDesign.getDimension(); i++) {
double value = scaleDesign.getParameterValue(i);
if (value < 1 || value > scaleParameter.getDimension())
throw new XMLParseException("Invalid scaleDesign value");
scaleDesign.setParameterValue(i, value - 1);
}
}
glm.addScaleParameter(scaleParameter, scaleDesign);
}
// System.err.println("START 0");
addIndependentParameters(xo, glm, dependentParam);
// System.err.println("START 1");
addRandomEffects(xo, glm, dependentParam);
// System.err.println("START 2");
boolean checkIdentifiability = xo.getAttribute(CHECK_IDENTIFIABILITY, true);
if (checkIdentifiability) {
if (!glm.getAllIndependentVariablesIdentifiable()) {
throw new XMLParseException("All design matrix predictors are not identifiable in " + xo.getId());
}
}
// System.err.println("PASSED B");
checkFullRankOfMatrix = xo.getAttribute(CHECK_FULL_RANK, true);
// System.err.println("PASSED C");
return glm;
}
use of dr.inference.distribution.LogLinearModel in project beast-mcmc by beast-dev.
the class OldGLMSubstitutionModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null)
dataType = (DataType) xo.getChild(DataType.class);
int rateCount = (dataType.getStateCount() - 1) * dataType.getStateCount();
LogLinearModel glm = (LogLinearModel) xo.getChild(GeneralizedLinearModel.class);
int length = glm.getXBeta().length;
if (length != rateCount) {
throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length);
}
XMLObject cxo = xo.getChild(dr.oldevomodelxml.substmodel.ComplexSubstitutionModelParser.ROOT_FREQUENCIES);
FrequencyModel rootFreq = (FrequencyModel) cxo.getChild(FrequencyModel.class);
if (dataType != rootFreq.getDataType()) {
throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its rootFrequencyModel.");
}
return new OldGLMSubstitutionModel(xo.getId(), dataType, rootFreq, glm);
}
use of dr.inference.distribution.LogLinearModel in project beast-mcmc by beast-dev.
the class GLMSubstitutionModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null)
dataType = (DataType) xo.getChild(DataType.class);
int rateCount = (dataType.getStateCount() - 1) * dataType.getStateCount();
LogLinearModel glm = (LogLinearModel) xo.getChild(GeneralizedLinearModel.class);
int length = glm.getXBeta().length;
if (length != rateCount) {
throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length);
}
XMLObject cxo = xo.getChild(ComplexSubstitutionModelParser.ROOT_FREQUENCIES);
FrequencyModel rootFreq = (FrequencyModel) cxo.getChild(FrequencyModel.class);
if (dataType != rootFreq.getDataType()) {
throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its rootFrequencyModel.");
}
return new GLMSubstitutionModel(xo.getId(), dataType, rootFreq, glm);
}
Aggregations