/// <summary> /// Generates a TLExperimentsResultsCollection containing summary data of results. /// This operation is thread-safe. /// </summary> /// <returns>Results summaries</returns> public TLExperimentsResultsCollection GenerateSummaryResults() { lock (_lock) { TLExperimentsResultsCollection ExperimentsResultsCollection = new TLExperimentsResultsCollection(); // iterate over techniques foreach (string technique in _techniques) { TLExperimentResults TechniqueResults = new TLExperimentResults(technique); // iterate over datasets foreach (string dataset in _datasets) { // get list of results for technique + dataset List <IMetricComputation> list = null; string key = ComputeKey(technique, dataset); _results.TryGetValue(key, out list); if (list != null) { DatasetResults data = new DatasetResults(dataset); // add results to dataset foreach (IMetricComputation computation in list) { if (!computation.HasRun) { computation.Compute(); } data.AddMetric(computation.GenerateSummary()); } // add dataset to technique if (data.Metrics.Count() > 0) { TechniqueResults.AddDatasetResult(data); } } } // add technique to collection if (TechniqueResults.DatasetsResults.Count() > 0) { ExperimentsResultsCollection.Add(TechniqueResults); } } return(ExperimentsResultsCollection); } }
private TLExperimentResults ComputeMetricResultsForDataset(GroupOfTracingResults <T> tracingResults) { //create experiment results container for this technique TLExperimentResults experimentResult = new TLExperimentResults(tracingResults.TechniqueName); foreach (TLDataset dataset in m_datasets) { DatasetResults datasetResults = new DatasetResults(dataset.Name); //iterate through all computation and calculate metric results for this dataset foreach (MetricComputationForSingleDataset <T> computation in metricComputationsPerDataset) { T tracingResult = default(T); if (tracingResults.Contains(dataset.Name)) { tracingResult = tracingResults[dataset.Name]; } var metric = computation.Compute(tracingResult, dataset); if (metric == null) { throw new InvalidOperationException("The metric computation method failed to return the metric. " + "Even if tracing results are empty computation must return metric with name and description, although it may have empty data"); } if (computation is IStatisticallyComparableMetric <T> ) { //collect results, so that statistical comparison can be computed afterwards, if there are two techniques } datasetResults.AddMetric(metric); } experimentResult.AddDatasetResult(datasetResults); } //compute also set of metrics across all datasets combined //experimentResult.AcrossAllDatasetsResults = ComputeMetricResultsAcrossAllDatasets(tracingResults); return(experimentResult); }
public void ExperimentResultsRawSerializationTest() { int n = 0; TLExperimentResults expResultsIn = new TLExperimentResults("Technique " + n++); for (int k = 0; k < 5; k++) { DatasetResults dataResults = new DatasetResults("Dataset " + n++); for (int i = 0; i < 10; i++) { LineSeries line = new LineSeries("Line " + i, "Description " + n++); for (int j = 1000 * i; j < 1000; j++) { line.AddPoint(new Point(j, j + 1)); } dataResults.AddMetric(line); BoxSummaryData box = new BoxSummaryData("Box " + i, "Description " + n++); for (int j = 0; j < 100; j++) { box.AddPoint(new BoxPlotPoint(j, j + 1, j + 2, j + 3, j + 4, j + 5, j + 6, j + 7)); } dataResults.AddMetric(box); } expResultsIn.AddDatasetResult(dataResults); } BinaryWriter binWriter = new BinaryWriter(new MemoryStream()); BinaryReader binReader = new BinaryReader(binWriter.BaseStream); expResultsIn.WriteData(binWriter); binReader.BaseStream.Position = 0; TLExperimentResults expResultsOut = (TLExperimentResults)Activator.CreateInstance(typeof(TLExperimentResults), true); expResultsOut.ReadData(binReader); Assert.AreEqual(expResultsIn.TechniqueName, expResultsOut.TechniqueName); Assert.AreEqual(expResultsIn.DatasetsResults.Count(), expResultsOut.DatasetsResults.Count()); foreach (DatasetResults result1 in expResultsIn.DatasetsResults) { bool sameDatasetResultExists = false; DatasetResults result2 = null; foreach (DatasetResults res in expResultsOut.DatasetsResults) { if (res.DatasetName == result1.DatasetName) { sameDatasetResultExists = true; result2 = res; break; } } Assert.IsTrue(sameDatasetResultExists); Assert.AreEqual(result1.DatasetName, result2.DatasetName); Assert.AreEqual(result1.Metrics.Count(), result2.Metrics.Count()); foreach (Metric m1 in result1.Metrics) { bool sameMetricExists = false; Metric m2 = null; foreach (Metric metric in result2.Metrics) { if (m1.MetricName == metric.MetricName) { sameMetricExists = true; m2 = metric; break; } } Assert.IsTrue(sameMetricExists); Assert.AreEqual(m1.Description, m2.Description); if (m1 is LineSeries) { Assert.IsTrue(m2 is LineSeries); LineSeries l1 = (LineSeries)m1; LineSeries l2 = (LineSeries)m2; Assert.AreEqual(l1.Points.Count(), l2.Points.Count()); } else { Assert.IsTrue(m2 is BoxSummaryData); BoxSummaryData b1 = (BoxSummaryData)m1; BoxSummaryData b2 = (BoxSummaryData)m2; Assert.AreEqual(b1.Points.Count(), b2.Points.Count()); } } } }