Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/12/21 15:24:18 (3 years ago)
Author:
dpiringe
Message:

#3026

  • added ResultFormatter to add an extra layer of result transformation logic (converting a result value to a string with a defined logic, e.g. MatlabResultFormatter for ISymbolicRegressionSolution)
  • extended the IResultJsonItem with two properties for result formatting
  • added a new control to selected a result formatter for a result value
  • refactored the Runner for the new result formatting process
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/HeuristicLab.JsonInterface.App.csproj

    r17599 r17834  
    102102      <Private>False</Private>
    103103    </ProjectReference>
    104     <ProjectReference Include="..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    105       <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
    106       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
    107       <Private>False</Private>
    108     </ProjectReference>
    109104    <ProjectReference Include="..\HeuristicLab.JsonInterface\HeuristicLab.JsonInterface.csproj">
    110105      <Project>{0e3aab5e-f152-44e0-a054-4d9a83ecee08}</Project>
     
    125120      <Project>{94186a6a-5176-4402-ae83-886557b53cca}</Project>
    126121      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    127       <Private>False</Private>
    128     </ProjectReference>
    129     <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj">
    130       <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project>
    131       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name>
    132       <Private>False</Private>
    133     </ProjectReference>
    134     <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    135       <Project>{3d28463f-ec96-4d82-afee-38be91a0ca00}</Project>
    136       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    137       <Private>False</Private>
    138     </ProjectReference>
    139     <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
    140       <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
    141       <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
    142122      <Private>False</Private>
    143123    </ProjectReference>
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/Runner.cs

    r17828 r17834  
    33using System.IO;
    44using System.Linq;
    5 using System.Text;
    65using System.Threading;
    76using System.Threading.Tasks;
    87using HeuristicLab.Optimization;
    9 using HeuristicLab.ParallelEngine;
    10 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    11 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    12 using HeuristicLab.SequentialEngine;
    138using Newtonsoft.Json.Linq;
    149
     
    4237      File.WriteAllText(file, FetchResults(optimizer, configuredResultItem));
    4338
    44     private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItem) {
     39    private static IEnumerable<IResultFormatter> ResultFormatter { get; } =
     40      PluginInfrastructure.ApplicationManager.Manager.GetInstances<IResultFormatter>();
     41
     42    private static IResultFormatter GetResultFormatter(string fullName) =>
     43      ResultFormatter?.Where(x => x.GetType().FullName == fullName).Last();
     44
     45    private static string FetchResults(IOptimizer optimizer, IEnumerable<IResultJsonItem> configuredResultItems) {
    4546      JArray arr = new JArray();
    46       IEnumerable<string> configuredResults = configuredResultItem.Select(x => x.Name);
     47      IEnumerable<string> configuredResults = configuredResultItems.Select(x => x.Name);
    4748
    4849      foreach (var run in optimizer.Runs) {
     
    5152        obj.Add("Run", JToken.FromObject(run.ToString()));
    5253
    53         // add empty values for configured results
    54         var emptyToken = JToken.FromObject("");
    55         foreach (var cr in configuredResults) {
    56           obj.Add(cr, emptyToken);
    57         }
     54        // zip and filter the results with the ResultJsonItems
     55        var filteredResults = configuredResultItems.Zip(
     56          run.Results.Where(x => configuredResultItems.Any(y => y.Name == x.Key)),
     57          (x, y) => new { Item = x, Value = y.Value });
    5858
    59         // change empty values with calculated values
    60         var formatter = new SymbolicDataAnalysisExpressionMATLABFormatter();
    61         foreach (var res in run.Results) {
    62           if(obj.ContainsKey(res.Key)) {
    63             if (res.Value is ISymbolicRegressionSolution solution) {
    64               var formattedModel = formatter.Format(solution.Model.SymbolicExpressionTree);
    65               obj[res.Key] = JToken.FromObject(formattedModel);
    66             } else {
    67               obj[res.Key] = JToken.FromObject(res.Value.ToString());
    68             }
    69           }
     59        // add results to the JObject
     60        foreach(var result in filteredResults) {
     61          var formatter = GetResultFormatter(result.Item.ResultFormatterType);
     62          obj.Add(result.Item.Name, formatter.Format(result.Value));
    7063        }
    7164      }
Note: See TracChangeset for help on using the changeset viewer.