Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3076_IA_evaluators_analyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSingleObjectiveMetaModelAnalyzer.cs @ 17771

Last change on this file since 17771 was 17771, checked in by dpiringe, 4 years ago

#3076

  • added a new analyzer (and an abstract base class) for finding the best meta model for multiple datasets
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HEAL.Attic;
7using HeuristicLab.Common;
8using HeuristicLab.Core;
9using HeuristicLab.Data;
10using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
11
12namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
13  [StorableType("4B69A82A-265B-46DA-9055-B6E0EB6C3EC8")]
14  public class SymbolicRegressionSingleObjectiveMetaModelAnalyzer
15    : SymbolicRegressionMetaModelAnalyzer<SymbolicRegressionSingleObjectiveProblem>, ISymbolicExpressionTreeAnalyzer {
16
17    [StorableConstructor]
18    protected SymbolicRegressionSingleObjectiveMetaModelAnalyzer(StorableConstructorFlag _) : base(_) { }
19
20    protected SymbolicRegressionSingleObjectiveMetaModelAnalyzer(SymbolicRegressionSingleObjectiveMetaModelAnalyzer original, Cloner cloner) : base(original, cloner) { }
21
22    public SymbolicRegressionSingleObjectiveMetaModelAnalyzer() { }
23
24    [StorableHook(HookType.AfterDeserialization)]
25    private void AfterDeserialization() { }
26
27    public override IDeepCloneable Clone(Cloner cloner) => new SymbolicRegressionSingleObjectiveMetaModelAnalyzer(this, cloner);
28
29    protected override void PerformApply(SymbolicRegressionSingleObjectiveProblem problem, string targetVariable) {
30      double bestQuality = problem.Maximization.Value ? double.MinValue : double.MaxValue;
31      SymbolicRegressionSolution bestMetaModel = null;
32      foreach (var tree in this.SymbolicExpressionTree.ToArray()) {
33        IDataset dataset = problem.ProblemData.Dataset;
34        IEnumerable<int> rows = Enumerable.Range(0, dataset.Rows);
35        var quality = problem.Evaluator.Evaluate(ExecutionContext, tree, problem.ProblemData, rows);
36       
37        bool isBetter = problem.Maximization.Value ? (bestQuality < quality) : (bestQuality > quality);
38        if(isBetter) {
39          bestQuality = quality;
40          var model = new SymbolicRegressionModel(
41            targetVariable,
42            (ISymbolicExpressionTree)tree.Clone(),
43            new SymbolicDataAnalysisExpressionTreeInterpreter());
44          bestMetaModel = new SymbolicRegressionSolution(model, problem.ProblemData);
45        }
46      }
47      BestMetaModelParameter.ActualValue = bestMetaModel;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.