1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HEAL.Attic;
|
---|
7 | using HeuristicLab.Common;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Data;
|
---|
10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|