/// <summary> /// Adapts the specified collection of matrices into group of tracing results to comply with engine api /// </summary> /// <param name="matrices">The matrices.</param> /// <returns></returns> public static GroupOfTracingResults <SingleTracingResults> Adapt(TLSimilarityMatricesCollection matrices, string techniqueName) { GroupOfTracingResults <SingleTracingResults> results = new GroupOfTracingResults <SingleTracingResults>(techniqueName); if (matrices != null) { foreach (TLSimilarityMatrix matrix in matrices) { results.Add(new SingleTracingResults(matrix)); } } return(results); }
public override void Compute() { // Loading artifacts & datasets from workspace TLArtifactsCollection sourceArtifacts = (TLArtifactsCollection)Workspace.Load("sourceArtifacts"); TLArtifactsCollection targetArtifacts = (TLArtifactsCollection)Workspace.Load("targetArtifacts"); TLSimilarityMatrix answerMatrix = (TLSimilarityMatrix)Workspace.Load("answerMatrix"); TLSimilarityMatrix similarityMatrix = (TLSimilarityMatrix)Workspace.Load("similarityMatrix"); // Checking for null arguments if (sourceArtifacts == null) { throw new ComponentException("The loaded source artifacts cannot be null!"); } if (targetArtifacts == null) { throw new ComponentException("The loaded target artifacts cannot be null!"); } if (answerMatrix == null) { throw new ComponentException("The loaded answer matrix cannot be null!"); } if (similarityMatrix == null) { throw new ComponentException("The loaded similarity matrix cannot be null!"); } // Results calculation TLDatasetsList datasets = new TLDatasetsList(); var dataset = new TLDataset("Experiment results"); dataset.AnswerSet = answerMatrix; dataset.SourceArtifacts = sourceArtifacts; dataset.TargetArtifacts = targetArtifacts; datasets.Add(dataset); TLSimilarityMatricesCollection similarityMatrices = new TLSimilarityMatricesCollection(); similarityMatrix.Name = "Experiment results"; similarityMatrices.Add(similarityMatrix); MetricComputationEngine engine = new MetricComputationEngine(datasets, Logger, m_config); //wrap result similarity matrix into TracingResult var tracingResults = GroupOfTracingResults <SingleTracingResults> .Adapt(similarityMatrices, "Experiment results"); engine.AddTracingResults(tracingResults); var results = engine.ComputeResults(); // Store the results in the workspace Workspace.Store("results", results); }
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 AddTracingResults(GroupOfTracingResults <T> tracingResults) { m_allTracingResults.Add(tracingResults); }