Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/13/17 08:14:29 (7 years ago)
Author:
gkronber
Message:

#2796 added collection of Pareto-optimal solutions

Location:
branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4

    • Property svn:ignore set to
      Plugin.cs
  • branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg.csproj

    r15359 r15360  
    1010    <RootNamespace>HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg</RootNamespace>
    1111    <AssemblyName>HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg</AssemblyName>
    12     <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
     12    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    1313    <FileAlignment>512</FileAlignment>
    1414    <TargetFrameworkProfile />
  • branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionAlgorithm.cs

    r14523 r15360  
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3434using HeuristicLab.Problems.DataAnalysis;
     35using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    3536
    3637namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
     
    228229      var gradEvals = new IntValue();
    229230      Results.Add(new Result("Gradient evaluations", gradEvals));
     231      var paretoBestModelsResult = new Result("ParetoBestModels", typeof(ItemList<ISymbolicRegressionSolution>));
     232      Results.Add(paretoBestModelsResult);
    230233
    231234
     
    283286          totalRollouts.Value = state.TotalRollouts;
    284287
     288          paretoBestModelsResult.Value = new ItemList<ISymbolicRegressionSolution>(state.ParetoBestModels);
     289
    285290          table.Rows["Best quality"].Values.Add(bestQuality.Value);
    286291          table.Rows["Current best quality"].Values.Add(curQuality.Value);
  • branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionStatic.cs

    r14185 r15360  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Optimization;
    2930using HeuristicLab.Problems.DataAnalysis;
    3031using HeuristicLab.Problems.DataAnalysis.Symbolic;
     
    4445      double BestSolutionTrainingQuality { get; }
    4546      double BestSolutionTestQuality { get; }
     47      IEnumerable<ISymbolicRegressionSolution> ParetoBestModels { get; }
    4648      int TotalRollouts { get; }
    4749      int EffectiveRollouts { get; }
     
    7678      private readonly int constOptIterations;
    7779      private readonly double lowerEstimationLimit, upperEstimationLimit;
     80      private readonly List<ISymbolicRegressionSolution> paretoBestModels = new List<ISymbolicRegressionSolution>();
     81      private readonly List<double[]> paretoFront = new List<double[]>(); // matching the models
    7882
    7983      private readonly ExpressionEvaluator evaluator, testEvaluator;
     
    182186        }
    183187      }
     188      public IEnumerable<ISymbolicRegressionSolution> ParetoBestModels {
     189        get { return paretoBestModels; }
     190      }
    184191
    185192      public int TotalRollouts { get { return totalRollouts; } }
     
    195202        Eval(code, nParams, out q, out optConsts);
    196203
     204        // single objective best
    197205        if (q > bestRSq) {
    198206          bestRSq = q;
     
    204212          Array.Copy(optConsts, bestConsts, bestNParams);
    205213        }
     214        // multi-objective best
     215        var complexity = // SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity() TODO
     216          Array.FindIndex(code, (opc)=>opc==(byte)OpCodes.Exit);
     217        UpdateParetoFront(q, complexity, code, optConsts, nParams, scalingFactor, scalingOffset);
    206218
    207219        return q;
     220      }
     221
     222      private void UpdateParetoFront(double q, int complexity, byte[] code, double[] param, int nParam,
     223        double[] scalingFactor, double[] scalingOffset) {
     224        double[] best = new double[2];
     225        double[] cur = new double[2] { q, complexity };
     226        bool[] max = new[] { true, false };
     227        var isNonDominated = true;
     228        foreach (var e in paretoFront) {
     229          var domRes = DominationCalculator<int>.Dominates(cur, e, max, true);
     230          if (domRes == DominationResult.IsDominated) {
     231            isNonDominated = false;
     232            break;
     233          }
     234        }
     235        if(isNonDominated) {
     236          paretoFront.Add(cur);
     237
     238          // create model
     239          var treeGen = new SymbolicExpressionTreeGenerator(problemData.AllowedInputVariables.ToArray());
     240          var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
     241
     242          var t = new SymbolicExpressionTree(treeGen.Exec(code, param, nParam, scalingFactor, scalingOffset));
     243          var model = new SymbolicRegressionModel(problemData.TargetVariable, t, interpreter, lowerEstimationLimit, upperEstimationLimit);
     244
     245          var sol = model.CreateRegressionSolution(this.problemData);
     246          sol.Name = string.Format("{0:N5} {1}", q, complexity);
     247         
     248          paretoBestModels.Add(sol);
     249        }
     250        for(int i=paretoFront.Count-2;i>=0;i--) {
     251          var @ref = paretoFront[i];
     252          var domRes = DominationCalculator<int>.Dominates(cur, @ref, max, true);
     253          if(domRes == DominationResult.Dominates) {
     254            paretoFront.RemoveAt(i);
     255            paretoBestModels.RemoveAt(i);
     256          }
     257        }
    208258      }
    209259
Note: See TracChangeset for help on using the changeset viewer.