/// <summary> /// Computes the specified tracing results. /// </summary> /// <param name="tracingResults">The tracing results.</param> /// <param name="dataset">The dataset.</param> /// <returns></returns> public override Metric Compute(SingleTracingResults tracingResults, TLDataset dataset) { LineSeries precisionRecallCurve = new LineSeries(MetricName, MetricDescription); //only if tracing results are not null... if (tracingResults != null) { var resultMatrix = tracingResults.ResultMatrix; var answerSet = dataset.AnswerSet; var sourceArtifacts = dataset.SourceArtifacts; TLLinksList resultLinks = resultMatrix.AllLinks; resultLinks.Sort(); int numberOfRelevant = 0; foreach (TLArtifact sourceArtifact in sourceArtifacts.Values) { numberOfRelevant += answerSet.GetCountOfLinksAboveThresholdForSourceArtifact(sourceArtifact.Id); } //add point only if number of relevant and number of retrieved links are greater than 0 //basically don't allow division by 0 if (numberOfRelevant == 0) { m_logger.Warn("Number of relevant links is 0, thus the recall value cannot be computed for the Precision Recall Curve"); } else { int numberOfCorrectlyRetrieved = 0; int numberOfRetrieved = 0; foreach (TLSingleLink link in resultLinks) { numberOfRetrieved++; //check if this is a relevant link if (answerSet.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId)) { numberOfCorrectlyRetrieved++; } double recall = (double)numberOfCorrectlyRetrieved / numberOfRelevant; //don't need to check if number of retrieved is greater than 0 as it is always the case double precision = (double)numberOfCorrectlyRetrieved / numberOfRetrieved; precisionRecallCurve.AddPoint(new Point(recall, precision)); } } } return(precisionRecallCurve); }
private static string ReferenceTypesAssemblies(List <string> typeDirectories, TraceLabSDK.ComponentLogger logger, out HashSet <string> assembliesReferenceLocations) { string usingKeyword = "using "; string semicolon = ";"; Dictionary <string, System.Reflection.Assembly> assemblies = new Dictionary <string, System.Reflection.Assembly>(); foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { var name = assembly.GetName(); assemblies[name.Name + System.Text.UTF8Encoding.UTF8.GetString(name.GetPublicKeyToken())] = assembly; } assembliesReferenceLocations = new HashSet <string>(); HashSet <string> namespaces = new HashSet <string>(); StringBuilder typesNamespaces = new StringBuilder(); //preadd fixed namespaces namespaces.Add("System"); namespaces.Add("System.Security.Permissions"); namespaces.Add("TraceLab.Core.ExperimentExecution"); namespaces.Add("TraceLab.Core.Experiments"); namespaces.Add("TraceLab.Core.Decisions"); namespaces.Add("TraceLabSDK"); foreach (string fixedNamespace in namespaces) { typesNamespaces.AppendLine(usingKeyword + fixedNamespace + semicolon); } //iterate through all type directories, search for all dll, and collect the namespaces of all found types in those assemblies foreach (string dir in typeDirectories) { string typesDir = System.IO.Path.GetFullPath(dir); var files = System.IO.Directory.GetFiles(typesDir, "*.dll"); foreach (string file in files) { var name = System.Reflection.AssemblyName.GetAssemblyName(file); var lookup = name.Name + System.Text.UTF8Encoding.UTF8.GetString(name.GetPublicKeyToken()); if (assemblies.ContainsKey(lookup)) { var assembly = assemblies[lookup]; try { Type[] typesInAssembly = assembly.GetTypes(); foreach (Type type in typesInAssembly) { if (namespaces.Contains(type.Namespace) == false && type.Namespace != String.Empty && type.Namespace != null) { namespaces.Add(type.Namespace); typesNamespaces.AppendLine(usingKeyword + NamespaceFix(type.Namespace) + semicolon); } } //collect also assemblies location - the assemblies must be added to the compiler parameters assembliesReferenceLocations.Add(assembly.Location); } catch (ReflectionTypeLoadException ex) { if (logger != null) { //log warnings logger.Warn(String.Format("Assembly {0} has been skipped in decision node compilation, because compiler was unable to load one or more of the requested types when compiling decision node. " + "See the Loader Exceptions for more information.", name), ex); int i = 1; foreach (Exception loaderException in ex.LoaderExceptions) { logger.Warn(String.Format("Loader exception {0}: {1}", i++, loaderException.Message)); } } } } } } return(typesNamespaces.ToString()); }