public void PrintProbabilities(int noOfGroups) { List <IntersectionResultAnalysis> iras = IntersectionResult.IntersectionResultAnalysis(intersectionResults, noOfGroups); foreach (IntersectionResultAnalysis ira in iras) { Console.WriteLine("NoRep: {0}\t %: {1}\t groupSize: {2}\t Prob: {3}", ira.NoReplicatesAppeared, Math.Round(ira.PercentageOfUniqueness, 3), ira.NoCandidatesInGroup, Math.Round(ira.BayesianProbability, 3)); } }
//------------------------------------------------------------------------------------------ public void CalculateProbabilitiesForClass(int classOfInterest, double minSignal, double maxSignal) { //First we generate a cloned sparse matrix containing only the vectors that belong to the class of interest. SparseMatrix subSparseMatrix = new SparseMatrix(); foreach (sparseMatrixRow r in sparseMatrix.theMatrixInRows) { if (r.Lable == classOfInterest) { subSparseMatrix.addRow(r.Clone()); } } //Now we need to make sure that all the rows in the sparse matrix contain only signal within the predefined bounds List <int> dimsToEliminate = new List <int>(); List <int> allDimsTmp = subSparseMatrix.allDims(); foreach (int dim in allDimsTmp) { double avgSignal = subSparseMatrix.ExtractDimValues(dim, 0, true).Average(); if (avgSignal < minSignal || avgSignal > maxSignal) { dimsToEliminate.Add(dim); } } foreach (int dim in dimsToEliminate) { subSparseMatrix.eliminateDim(dim, 0, true); } //--- int noReplicates = subSparseMatrix.theMatrixInRows.Select(a => a.Lable = classOfInterest).ToList().Count; List <int> allDims = subSparseMatrix.allDims(); if (noReplicates > 9) { throw new Exception("To many replicates for the combination engine"); } if (noReplicates < 2) { throw new Exception("You need at least two repplicates for each class"); } //Step 1, obtain a list of lists of all combination of the number of classes List <List <int> > classCombinations = pTools.GetClassCombinations(noReplicates); classCombinations.Sort((a, b) => a.Count.CompareTo(b.Count)); //Step 2 - Find the Intersection of all dims List <int> intersectionOfAllDims = GetIntersection(classCombinations[classCombinations.Count - 1], subSparseMatrix.theMatrixInRows); //Step 3 - Calculate all possible intersections intersectionResults = new List <IntersectionResult>(); foreach (List <int> theRows in classCombinations) { List <int> intersectionOfDims = GetIntersection(theRows, subSparseMatrix.theMatrixInRows); IntersectionResult ir = new IntersectionResult(theRows, intersectionOfDims); intersectionResults.Add(ir); } //Step 4 - Calculate the percentage of uniqueness for each overlap double noUniqueCount = 0; foreach (IntersectionResult ir in intersectionResults) { //Find the union of all other assays not belonging to the one at hand List <int> allOther = new List <int>(); for (int i = 0; i < noReplicates; i++) { if (!ir.TheSparseMatrixRows.Contains(i)) { allOther.AddRange(subSparseMatrix.theMatrixInRows[i].Dims); } } allOther = allOther.Distinct().ToList(); List <int> intersectOfThisWithAllOthers = ir.IntersectingDims.Intersect(allOther).ToList(); ir.NoUniqueComparedToTotal = ir.IntersectingDims.Count - intersectOfThisWithAllOthers.Count; noUniqueCount += (double)ir.NoUniqueComparedToTotal; double percentageOfUniqueness = (double)ir.NoUniqueComparedToTotal / (double)allDims.Count; ir.PercentageUniqueness = percentageOfUniqueness; } }
public List <IntersectionResultAnalysis> GetIntersectionResultAnalysis(int noOfGroups) { return(IntersectionResult.IntersectionResultAnalysis(intersectionResults, noOfGroups)); }