private void FitBinomialModel() { // Algorithm based on this page modified to be a binomial mixture model // http://tinyheero.github.io/2016/01/03/gmm-em.html LogLikelihoods.Add(UpdateExpectation()); UpdateParameters(); double oldLogLikelihood = LogLikelihoods[0] + 100; int counter = 0; while (Math.Abs(LogLikelihoods[counter] - oldLogLikelihood) > 0.000001 && counter < 1000) { oldLogLikelihood = LogLikelihoods[counter]; LogLikelihoods.Add(UpdateExpectation()); UpdateParameters(); counter++; } UpdateClusteringAndQScore(); for (int k = 0; k < ClusterCounts.Length; k++) { if (ClusterCounts[k] == 0) { throw new MixtureModelException( "Germline adative genotyper failed because there are not enough variants to " + "fit the model. Please check that the sample is diploid. Consider enlarging the calling" + "region or using a pre-fit model."); } } }
private MixtureModel(IList <int> k, IList <int> n, double[] means, double[] priors) { Means = means; Array.Sort(Means); AlleleDepths = k; TotalDepths = n; QScores = new int[AlleleDepths.Count]; ClusterCounts = new int[3]; Clustering = new SparseArray <int>(TotalDepths.Count); MixtureWeights = priors; Posteriors = new double[AlleleDepths.Count, Means.Length]; LogLikelihoods.Add(UpdateExpectation()); }