Skip to content

Commit

Permalink
Make fewer objects, crash less
Browse files Browse the repository at this point in the history
  • Loading branch information
afmagee committed Sep 10, 2023
1 parent 5b606bd commit 44a4290
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class SubstitutionModelRandomEffectClassifier extends TreeStatistic imple
private GammaSiteRateModel siteModel;
private BranchRateModel branchRates;

private Parameter proxyRates;
private ComplexSubstitutionModel proxy;
private MarkovJumpsSubstitutionModel markovJumps;

private final boolean usingRateVariation;
private final boolean usingEpochs;
private boolean[] epochUsesTargetModel;
Expand Down Expand Up @@ -93,6 +97,11 @@ public SubstitutionModelRandomEffectClassifier(String name,
idx++;
}
}

this.proxyRates = new Parameter.Default(dim);
this.proxy = new ComplexSubstitutionModel("internalGlmProxyForSubstitutionModelRandomEffectClassifier",
glmSubstitutionModel.getDataType(),glmSubstitutionModel.getFrequencyModel(),proxyRates);
this.markovJumps = new MarkovJumpsSubstitutionModel(proxy, MarkovJumpsType.COUNTS);
}

@Override
Expand All @@ -110,7 +119,7 @@ public int getDimension() {
return dim;
}

private ComplexSubstitutionModel makeProxyModel(int index, boolean includeRandomEffect) {
private void makeProxyModel(int index, boolean includeRandomEffect) {
double[] relativeRates = new double[dim];
glmSubstitutionModel.setupRelativeRates(relativeRates);

Expand All @@ -120,13 +129,12 @@ private ComplexSubstitutionModel makeProxyModel(int index, boolean includeRandom
relativeRates[index] /= Math.exp(copiedParameterValues[index]);
}

Parameter relativeRateDummyParameter = new Parameter.Default(dim);
for (int i = 0; i < dim; i++) {
relativeRateDummyParameter.setParameterValueQuietly(i,relativeRates[i]);
proxyRates.setParameterValue(i,relativeRates[i]);
}

return new ComplexSubstitutionModel("internalGlmProxyForSubstitutionModelRandomEffectClassifier",
glmSubstitutionModel.getDataType(),glmSubstitutionModel.getFrequencyModel(),relativeRateDummyParameter);
// return new ComplexSubstitutionModel("internalGlmProxyForSubstitutionModelRandomEffectClassifier",
// glmSubstitutionModel.getDataType(),glmSubstitutionModel.getFrequencyModel(),relativeRateDummyParameter);

}

Expand Down Expand Up @@ -190,8 +198,7 @@ private double getDoubleResult(double countDiff) {
// }

private double getCountForRateCategory(int index, double time, boolean includeRandomEffect, boolean countAll) {
ComplexSubstitutionModel proxy = makeProxyModel(index, includeRandomEffect);
MarkovJumpsSubstitutionModel markovJumps = new MarkovJumpsSubstitutionModel(proxy, MarkovJumpsType.COUNTS);
makeProxyModel(index, includeRandomEffect);

double[] register = new double[nStates * nStates];
double[] jointCounts = new double[nStates * nStates];
Expand Down

0 comments on commit 44a4290

Please sign in to comment.