From 2aa33048a7943e17567c9b487ac11b7ec238e42a Mon Sep 17 00:00:00 2001 From: "Marc A. Suchard" Date: Sat, 12 Oct 2024 07:31:00 -0700 Subject: [PATCH] refactor GLM getXBeta() / getRates() functions so that they perform as named --- .../substmodel/GlmSubstitutionModel.java | 2 +- .../substmodel/LogAdditiveCtmcRateProvider.java | 4 ++-- .../substmodel/GlmSubstitutionModelParser.java | 2 +- .../distribution/LogGaussianProcessModel.java | 17 +++++++++-------- .../inference/distribution/LogLinearModel.java | 11 ++++++----- .../substmodel/NotUsedGlmSubstitutionModel.java | 3 ++- .../NotUsedGlmSubstitutionModelParser.java | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/dr/evomodel/substmodel/GlmSubstitutionModel.java b/src/dr/evomodel/substmodel/GlmSubstitutionModel.java index 4ba7659982..fdf4ea64a2 100644 --- a/src/dr/evomodel/substmodel/GlmSubstitutionModel.java +++ b/src/dr/evomodel/substmodel/GlmSubstitutionModel.java @@ -71,7 +71,7 @@ public GeneralizedLinearModel getGeneralizedLinearModel() { } protected void setupRelativeRates(double[] rates) { - System.arraycopy(glm.getXBeta(),0,rates,0,rates.length); + System.arraycopy(glm.getRates(),0,rates,0,rates.length); } @Override diff --git a/src/dr/evomodel/substmodel/LogAdditiveCtmcRateProvider.java b/src/dr/evomodel/substmodel/LogAdditiveCtmcRateProvider.java index df7effdbbf..c8b47ad049 100644 --- a/src/dr/evomodel/substmodel/LogAdditiveCtmcRateProvider.java +++ b/src/dr/evomodel/substmodel/LogAdditiveCtmcRateProvider.java @@ -69,8 +69,8 @@ public Basic(String name, Parameter transformedRateParameter) { public Parameter getLogRateParameter() { return transformedRateParameter; } @Override - public double[] getXBeta() { // TODO this function should _not_ exponentiate - return transformedRateParameter.getParameterValues(); + public double[] getXBeta() { + return getLogRateParameter().getParameterValues(); } @Override diff --git a/src/dr/evomodelxml/substmodel/GlmSubstitutionModelParser.java b/src/dr/evomodelxml/substmodel/GlmSubstitutionModelParser.java index d38b6d3286..597845c9c4 100644 --- a/src/dr/evomodelxml/substmodel/GlmSubstitutionModelParser.java +++ b/src/dr/evomodelxml/substmodel/GlmSubstitutionModelParser.java @@ -65,7 +65,7 @@ public Object parseXMLObject(XMLObject xo) throws XMLParseException { glm = new LogAdditiveCtmcRateProvider.DataAugmented.Basic(logRates.getId(), logRates); } - int length = glm.getXBeta().length; + int length = glm.getRates().length; if (length != rateCount) { throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length); diff --git a/src/dr/inference/distribution/LogGaussianProcessModel.java b/src/dr/inference/distribution/LogGaussianProcessModel.java index e674e33c8d..369116f792 100644 --- a/src/dr/inference/distribution/LogGaussianProcessModel.java +++ b/src/dr/inference/distribution/LogGaussianProcessModel.java @@ -222,14 +222,15 @@ public void precision(double noiseVar) { @Override public double[] getXBeta() { // compute the mean and then exponentiate - final int fieldDim = dependentParam.getDimension(); - double[] rates = new double[fieldDim]; - - // here we just exponentiate the log-mean rate into the actual mean rates - for (int i = 0; i < fieldDim; i++) { - rates[i] = Math.exp(dependentParam.getParameterValue(i)); - } - return rates; +// final int fieldDim = dependentParam.getDimension(); +// double[] rates = new double[fieldDim]; +// +// // here we just exponentiate the log-mean rate into the actual mean rates +// for (int i = 0; i < fieldDim; i++) { +// rates[i] = Math.exp(dependentParam.getParameterValue(i)); +// } +// return rates; + return dependentParam.getParameterValues(); } } \ No newline at end of file diff --git a/src/dr/inference/distribution/LogLinearModel.java b/src/dr/inference/distribution/LogLinearModel.java index 264b618caf..c41727c5d5 100644 --- a/src/dr/inference/distribution/LogLinearModel.java +++ b/src/dr/inference/distribution/LogLinearModel.java @@ -48,11 +48,12 @@ public double[] getSuperXBeta() { @Override public double[] getXBeta() { - double[] xBeta = super.getXBeta(); - for(int i = 0; i < xBeta.length; i++) { - xBeta[i] = Math.exp(xBeta[i]); - } - return xBeta; +// double[] xBeta = super.getXBeta(); +// for(int i = 0; i < xBeta.length; i++) { +// xBeta[i] = Math.exp(xBeta[i]); +// } +// return xBeta; + return super.getXBeta(); } public Parameter getLogRateParameter() { diff --git a/src/dr/oldevomodel/substmodel/NotUsedGlmSubstitutionModel.java b/src/dr/oldevomodel/substmodel/NotUsedGlmSubstitutionModel.java index e1c36b4711..5fe82fc967 100644 --- a/src/dr/oldevomodel/substmodel/NotUsedGlmSubstitutionModel.java +++ b/src/dr/oldevomodel/substmodel/NotUsedGlmSubstitutionModel.java @@ -56,7 +56,8 @@ public NotUsedGlmSubstitutionModel(String name, DataType dataType, FrequencyMode } public double[] getRates() { - return glm.getXBeta(); + throw new RuntimeException("No longer supported"); +// return glm.getXBeta(); } diff --git a/src/dr/oldevomodelxml/substmodel/NotUsedGlmSubstitutionModelParser.java b/src/dr/oldevomodelxml/substmodel/NotUsedGlmSubstitutionModelParser.java index e5b92abc15..af5958bc1c 100644 --- a/src/dr/oldevomodelxml/substmodel/NotUsedGlmSubstitutionModelParser.java +++ b/src/dr/oldevomodelxml/substmodel/NotUsedGlmSubstitutionModelParser.java @@ -57,7 +57,7 @@ public Object parseXMLObject(XMLObject xo) throws XMLParseException { LogLinearModel glm = (LogLinearModel) xo.getChild(GeneralizedLinearModel.class); - int length = glm.getXBeta().length; + int length = glm.getRates().length; if (length != rateCount) { throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length);