public void RunAlgorithm() { foreach (Experiment e in Experiments) { // depending on the size of the dataset table, this could take a second or a few seconds to load e.LoadDatasetTable(); // compute pairwise correlation CorrelationTable ct = new CorrelationTable(); CalculatePairwiseCorrelations(e, ct); // select the rows which correspond to the supplied identifiers List<CorrelationResult> selectedIdentifiersCorrelationVector = new List<CorrelationResult>(); List<CorrelationResult> filteredCorrelationsVector = new List<CorrelationResult>(); for (int i = ct.Correlations.Count - 1; i >= 0; i--) { CorrelationResult cr = ct.Correlations[i]; if (Identifiers.Contains(cr.IdentifierA) && Identifiers.Contains(cr.IdentifierB)) { selectedIdentifiersCorrelationVector.Add(cr); ct.Correlations.RemoveAt(i); } else if (Identifiers.Contains(cr.IdentifierA) || Identifiers.Contains(cr.IdentifierB)) { filteredCorrelationsVector.Add(cr); ct.Correlations.RemoveAt(i); } } // compute t-tests TTestTable ttt = new TTestTable(); for (int i = 0; i < selectedIdentifiersCorrelationVector.Count; i++) { CorrelationResult crA = selectedIdentifiersCorrelationVector[i]; for (int k = 0; k < filteredCorrelationsVector.Count; k++) { CorrelationResult crB = filteredCorrelationsVector[k]; if (!ttt.TTestExist(crA.IdentifierA, crA.IdentifierB, crB.IdentifierA, crB.IdentifierB)) { TTest stt = new TTest(new double[] { crA.Value }, filteredCorrelationsVector[k].Value); ttt.TTests.Add(stt); } } } } }
private static void CalculatePairwiseCorrelations(Experiment e, CorrelationTable ct) { for (int i = 0; i < e.DatasetTable.Count; i++) { DatasetTableRow rowA = e.DatasetTable[i]; for (int k = i + 1; k < e.DatasetTable.Count; k++) { DatasetTableRow rowB = e.DatasetTable[k]; string id_a = rowA.Identifier; string id_b = rowB.Identifier; if (!ct.CorrelationExist(id_a, id_b)) { double[] valuesA = ExperimentHelper.MakeArrayFromStringValues(rowA.Value); double[] valuesB = ExperimentHelper.MakeArrayFromStringValues(rowB.Value); double correlation = Correlation.Pearson(valuesA, valuesB); CorrelationResult cr = new CorrelationResult(id_a, id_b, correlation); ct.Correlations.Add(cr); } } } }