1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Problems.DataAnalysis;
|
---|
10 | using HeuristicLab.Parameters;
|
---|
11 | using HeuristicLab.Common;
|
---|
12 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
13 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Problems.TradeRules
|
---|
16 | {
|
---|
17 | [Item("TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for single objective symbolic regression problems.")]
|
---|
18 | [StorableClass]
|
---|
19 | public sealed class TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>,
|
---|
20 | ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator
|
---|
21 | {
|
---|
22 | private const string ProblemDataParameterName = "ProblemData";
|
---|
23 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
|
---|
24 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
25 | private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
|
---|
26 | #region parameter properties
|
---|
27 | public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
|
---|
28 | get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
|
---|
29 | }
|
---|
30 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
31 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
32 | }
|
---|
33 | public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
34 | get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
35 | }
|
---|
36 | public IValueParameter<BoolValue> ApplyLinearScalingParameter {
|
---|
37 | get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
|
---|
38 | }
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region properties
|
---|
42 | public BoolValue ApplyLinearScaling {
|
---|
43 | get { return ApplyLinearScalingParameter.Value; }
|
---|
44 | }
|
---|
45 | #endregion
|
---|
46 |
|
---|
47 | [StorableConstructor]
|
---|
48 | private TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
49 | private TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer(TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
50 | public TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer()
|
---|
51 | : base() {
|
---|
52 | Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
|
---|
53 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
|
---|
54 | Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
|
---|
55 | Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(false)));
|
---|
56 | }
|
---|
57 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
58 | return new TradeRulesSingleObjectiveTrainingBestSolutionAnalyzer(this, cloner);
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
|
---|
62 | var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
|
---|
63 | if (ApplyLinearScaling.Value)
|
---|
64 | SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
|
---|
65 | return new TradingRulesSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|