private static final double[][] convertLogged( double[][] loggedStore, int numberOfCategories, int numberOfPatterns) { double[][] result = new double[numberOfCategories][numberOfPatterns]; for (int c = 0; c < numberOfCategories; c++) { for (int p = 0; p < numberOfPatterns; p++) { result[c][p] = Math.exp(loggedStore[c][p]); } } return result; }
public SimpleSiteDetails( double[][] categoryPatternConditionalProbabilities, boolean isLoggedConditionals, SubstitutionModel model, int numberOfPatterns, int[] sitePatternMatchup, int numberOfSites, double[] siteLikelihoods) { final int numberOfCategories = model.getNumberOfTransitionCategories(); this.siteLikelihoods_ = pal.misc.Utils.getCopy(siteLikelihoods); this.siteLogLikelihoods_ = new double[numberOfSites]; double llh = 0; for (int i = 0; i < numberOfSites; i++) { this.siteLogLikelihoods_[i] = Math.log(this.siteLikelihoods_[i]); llh += this.siteLogLikelihoods_[i]; } System.out.println("Total:" + llh); if (isLoggedConditionals) { this.categoryPatternConditionalProbabilities_ = convertLogged( categoryPatternConditionalProbabilities, numberOfCategories, numberOfPatterns); } else { this.categoryPatternConditionalProbabilities_ = pal.misc.Utils.getCopy(categoryPatternConditionalProbabilities); } this.numberOfSites_ = numberOfSites; this.sitePatternMatchup_ = pal.misc.Utils.getCopy(sitePatternMatchup); this.patternPosteriors_ = new double[numberOfPatterns][numberOfCategories]; for (int p = 0; p < numberOfPatterns; p++) { double total = 0; for (int c = 0; c < numberOfCategories; c++) { total += categoryPatternConditionalProbabilities[c][p]; } for (int c = 0; c < numberOfCategories; c++) { patternPosteriors_[p][c] = categoryPatternConditionalProbabilities[c][p] / total; } } this.model_ = model; }