Skip to content

Commit

Permalink
refactor GLM getXBeta() / getRates() functions so that they perform a…
Browse files Browse the repository at this point in the history
…s named
  • Loading branch information
msuchard committed Oct 12, 2024
1 parent 48a9cfb commit 2aa3304
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/dr/evomodel/substmodel/GlmSubstitutionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/dr/evomodel/substmodel/LogAdditiveCtmcRateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions src/dr/inference/distribution/LogGaussianProcessModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
11 changes: 6 additions & 5 deletions src/dr/inference/distribution/LogLinearModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2aa3304

Please sign in to comment.