Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4128


Ignore:
Timestamp:
08/02/10 15:21:07 (14 years ago)
Author:
gkronber
Message:

Implemented multi-objective version of symbolic regression problem. #1118

Location:
trunk/sources
Files:
8 added
1 deleted
3 edited
5 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionNormalizedMeanSquaredErrorEvaluator.cs

    r4112 r4128  
    3333  [Item("SymbolicRegressionNormalizedMeanSquaredErrorEvaluator", "Calculates the normalized mean squared error of a symbolic regression solution.")]
    3434  [StorableClass]
    35   public class SymbolicRegressionNormalizedMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
     35  public class SymbolicRegressionNormalizedMeanSquaredErrorEvaluator : SingleObjectiveSymbolicRegressionEvaluator {
    3636    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    3737    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r4127 r4128  
    129129    <Compile Include="Symbolic\Analyzers\SymbolicRegressionVariableFrequencyAnalyzer.cs" />
    130130    <Compile Include="Symbolic\Analyzers\ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs" />
    131     <Compile Include="Symbolic\SymbolicRegressionPearsonsRSquaredEvaluator.cs" />
    132     <Compile Include="Symbolic\SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs" />
     131    <Compile Include="Symbolic\Evaluators\MultiObjectiveSymbolicRegressionEvaluator.cs" />
     132    <Compile Include="Symbolic\Evaluators\MultiObjectiveSymbolicRegressionPearsonsRSquaredEvaluator.cs" />
     133    <Compile Include="Symbolic\Evaluators\SingleObjectiveSymbolicRegressionEvaluator.cs" />
     134    <Compile Include="Symbolic\Evaluators\SymbolicRegressionMeanSquaredErrorEvaluator.cs" />
     135    <Compile Include="Symbolic\Evaluators\SymbolicRegressionPearsonsRSquaredEvaluator.cs" />
     136    <Compile Include="Symbolic\Evaluators\SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs" />
     137    <Compile Include="Symbolic\Evaluators\SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs" />
     138    <Compile Include="Symbolic\Interfaces\IMultiObjectiveSymbolicRegressionEvaluator.cs" />
     139    <Compile Include="Symbolic\Interfaces\ISymbolicRegressionEvaluator.cs" />
     140    <Compile Include="Symbolic\SymbolicRegressionProblem.cs" />
     141    <Compile Include="Symbolic\MultiObjectiveSymbolicRegressionProblem.cs" />
    133142    <Compile Include="Symbolic\SimpleSymbolicRegressionEvaluator.cs" />
    134     <Compile Include="Symbolic\SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs" />
    135143    <Compile Include="Symbolic\SymbolicRegressionSolution.cs" />
    136144    <Compile Include="Symbolic\SymbolicRegressionModel.cs" />
    137     <Compile Include="Symbolic\ISymbolicRegressionEvaluator.cs">
    138       <SubType>Code</SubType>
    139     </Compile>
    140     <Compile Include="Symbolic\SymbolicRegressionEvaluator.cs">
    141       <SubType>Code</SubType>
    142     </Compile>
    143     <Compile Include="Symbolic\SymbolicRegressionMeanSquaredErrorEvaluator.cs">
    144       <SubType>Code</SubType>
    145     </Compile>
    146     <Compile Include="Symbolic\SymbolicRegressionProblem.cs">
     145    <Compile Include="Symbolic\SymbolicRegressionProblemBase.cs">
    147146      <SubType>Code</SubType>
    148147    </Compile>
     
    251250    </BootstrapperPackage>
    252251  </ItemGroup>
     252  <ItemGroup />
    253253  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    254254  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r4127 r4128  
    3333  [Item("SymbolicRegressionMeanSquaredErrorEvaluator", "Calculates the mean squared error of a symbolic regression solution.")]
    3434  [StorableClass]
    35   public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
     35  public class SymbolicRegressionMeanSquaredErrorEvaluator : SingleObjectiveSymbolicRegressionEvaluator {
    3636    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    3737    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionPearsonsRSquaredEvaluator.cs

    r4127 r4128  
    3333  [Item("SymbolicRegressionPearsonsRSquaredEvaluator", "Calculates the pearson r² correlation coefficient of a symbolic regression solution.")]
    3434  [StorableClass]
    35   public class SymbolicRegressionPearsonsRSquaredEvaluator : SymbolicRegressionEvaluator {
     35  public class SymbolicRegressionPearsonsRSquaredEvaluator : SingleObjectiveSymbolicRegressionEvaluator {
    3636    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    3737    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs

    r4127 r4128  
    3737    private const string QualityVarianceParameterName = "QualityVariance";
    3838    private const string QualitySamplesParameterName = "QualitySamples";
     39    private const string DecompositionBiasParameterName = "QualityDecompositionBias";
     40    private const string DecompositionVarianceParameterName = "QualityDecompositionVariance";
     41    private const string DecompositionCovarianceParameterName = "QualityDecompositionCovariance";
     42    private const string ApplyScalingParameterName = "ApplyScaling";
    3943
    4044    #region parameter properties
     45    public IValueLookupParameter<BoolValue> ApplyScalingParameter {
     46      get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyScalingParameterName]; }
     47    }
    4148    public ILookupParameter<DoubleValue> AlphaParameter {
    4249      get { return (ILookupParameter<DoubleValue>)Parameters["Alpha"]; }
     
    5158      get { return (ILookupParameter<IntValue>)Parameters[QualitySamplesParameterName]; }
    5259    }
     60    public ILookupParameter<DoubleValue> DecompositionBiasParameter {
     61      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionBiasParameterName]; }
     62    }
     63    public ILookupParameter<DoubleValue> DecompositionVarianceParameter {
     64      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionVarianceParameterName]; }
     65    }
     66    public ILookupParameter<DoubleValue> DecompositionCovarianceParameter {
     67      get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionCovarianceParameterName]; }
     68    }
    5369
    5470    #endregion
    5571    #region properties
     72    public BoolValue ApplyScaling {
     73      get { return ApplyScalingParameter.ActualValue; }
     74    }
    5675    public DoubleValue Alpha {
    5776      get { return AlphaParameter.ActualValue; }
     
    7392    public SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator()
    7493      : base() {
     94      Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyScalingParameterName, "Determines if the estimated values should be scaled.", new BoolValue(true)));
    7595      Parameters.Add(new LookupParameter<DoubleValue>("Alpha", "Alpha parameter for linear scaling of the estimated values."));
    7696      Parameters.Add(new LookupParameter<DoubleValue>("Beta", "Beta parameter for linear scaling of the estimated values."));
    7797      Parameters.Add(new LookupParameter<DoubleValue>(QualityVarianceParameterName, "A parameter which stores the variance of the squared errors."));
    7898      Parameters.Add(new LookupParameter<IntValue>(QualitySamplesParameterName, " The number of evaluated samples."));
     99      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionBiasParameterName, "A parameter which stores the relativ bias of the MSE."));
     100      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionVarianceParameterName, "A parameter which stores the relativ bias of the MSE."));
     101      Parameters.Add(new LookupParameter<DoubleValue>(DecompositionCovarianceParameterName, "A parameter which stores the relativ bias of the MSE."));
    79102    }
    80103
     
    83106      double meanSE, varianceSE;
    84107      int count;
    85       double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count);
    86       Alpha = new DoubleValue(alpha);
    87       Beta = new DoubleValue(beta);
     108      double bias, variance, covariance;
     109      double mse;
     110      if (ApplyScaling.Value) {
     111        mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     112        Alpha = new DoubleValue(alpha);
     113        Beta = new DoubleValue(beta);
     114      } else {
     115        mse = CalculateWithScaling(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, 1, 0, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     116      }
    88117      QualityVariance = new DoubleValue(varianceSE);
    89118      QualitySamples = new IntValue(count);
     119      DecompositionBiasParameter.ActualValue = new DoubleValue(bias / meanSE);
     120      DecompositionVarianceParameter.ActualValue = new DoubleValue(variance / meanSE);
     121      DecompositionCovarianceParameter.ActualValue = new DoubleValue(covariance / meanSE);
    90122      return mse;
    91123    }
    92124
    93     public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count) {
     125    public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) {
    94126      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
    95127      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows);
    96128      CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);
    97129
    98       return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count);
    99     }
    100 
    101     public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count) {
     130      return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance);
     131    }
     132
     133    public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) {
    102134      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows);
    103135      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows);
     
    105137      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    106138      OnlineMeanAndVarianceCalculator seEvaluator = new OnlineMeanAndVarianceCalculator();
     139      OnlineMeanAndVarianceCalculator originalMeanEvaluator = new OnlineMeanAndVarianceCalculator();
     140      OnlineMeanAndVarianceCalculator estimatedMeanEvaluator = new OnlineMeanAndVarianceCalculator();
     141      OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
    107142
    108143      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     
    116151        error *= error;
    117152        seEvaluator.Add(error);
     153        originalMeanEvaluator.Add(original);
     154        estimatedMeanEvaluator.Add(estimated);
     155        r2Evaluator.Add(original, estimated);
    118156      }
    119157
     
    124162        varianceSE = seEvaluator.Variance;
    125163        count = seEvaluator.Count;
     164        bias = (originalMeanEvaluator.Mean - estimatedMeanEvaluator.Mean);
     165        bias *= bias;
     166
     167        double sO = Math.Sqrt(originalMeanEvaluator.Variance);
     168        double sE = Math.Sqrt(estimatedMeanEvaluator.Variance);
     169        variance = sO - sE;
     170        variance *= variance;
     171        double r = Math.Sqrt(r2Evaluator.RSquared);
     172        covariance = 2 * sO * sE * (1 - r);
    126173        return seEvaluator.Mean;
    127174      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r4127 r4128  
    3838
    3939namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    40   [Item("Symbolic Regression Problem", "Represents a symbolic regression problem.")]
     40  [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]
    4141  [Creatable("Problems")]
    4242  [StorableClass]
    43   public class SymbolicRegressionProblem : DataAnalysisProblem, ISingleObjectiveProblem {
     43  public class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveProblem {
    4444
    4545    #region Parameter Properties
     
    5050      get { return MaximizationParameter; }
    5151    }
    52     public new ValueParameter<SymbolicExpressionTreeCreator> SolutionCreatorParameter {
    53       get { return (ValueParameter<SymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }
    54     }
    55     IParameter IProblem.SolutionCreatorParameter {
    56       get { return SolutionCreatorParameter; }
    57     }
    58     public ValueParameter<DoubleValue> LowerEstimationLimitParameter {
    59       get { return (ValueParameter<DoubleValue>)Parameters["LowerEstimationLimit"]; }
    60     }
    61     public ValueParameter<DoubleValue> UpperEstimationLimitParameter {
    62       get { return (ValueParameter<DoubleValue>)Parameters["UpperEstimationLimit"]; }
    63     }
    64     public ValueParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
    65       get { return (ValueParameter<ISymbolicExpressionTreeInterpreter>)Parameters["SymbolicExpressionTreeInterpreter"]; }
    66     }
    6752    public new ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
    6853      get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
     
    7055    IParameter IProblem.EvaluatorParameter {
    7156      get { return EvaluatorParameter; }
    72     }
    73     public ValueParameter<ISymbolicExpressionGrammar> FunctionTreeGrammarParameter {
    74       get { return (ValueParameter<ISymbolicExpressionGrammar>)Parameters["FunctionTreeGrammar"]; }
    75     }
    76     public ValueParameter<IntValue> MaxExpressionLengthParameter {
    77       get { return (ValueParameter<IntValue>)Parameters["MaxExpressionLength"]; }
    78     }
    79     public ValueParameter<IntValue> MaxExpressionDepthParameter {
    80       get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
    81     }
    82     public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter {
    83       get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; }
    84     }
    85     public ValueParameter<IntValue> MaxFunctionArgumentsParameter {
    86       get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }
    8757    }
    8858    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
     
    9565
    9666    #region Properties
    97     public IntValue MaxExpressionLength {
    98       get { return MaxExpressionLengthParameter.Value; }
    99       set { MaxExpressionLengthParameter.Value = value; }
    100     }
    101     public IntValue MaxExpressionDepth {
    102       get { return MaxExpressionDepthParameter.Value; }
    103       set { MaxExpressionDepthParameter.Value = value; }
    104     }
    105     public IntValue MaxFunctionDefiningBranches {
    106       get { return MaxFunctionDefiningBranchesParameter.Value; }
    107       set { MaxFunctionDefiningBranchesParameter.Value = value; }
    108     }
    109     public IntValue MaxFunctionArguments {
    110       get { return MaxFunctionArgumentsParameter.Value; }
    111       set { MaxFunctionArgumentsParameter.Value = value; }
    112     }
    113     public new SymbolicExpressionTreeCreator SolutionCreator {
    114       get { return SolutionCreatorParameter.Value; }
    115       set { SolutionCreatorParameter.Value = value; }
    116     }
    117     ISolutionCreator IProblem.SolutionCreator {
    118       get { return SolutionCreatorParameter.Value; }
    119     }
    120     public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
    121       get { return SymbolicExpressionTreeInterpreterParameter.Value; }
    122       set { SymbolicExpressionTreeInterpreterParameter.Value = value; }
    123     }
    124     public DoubleValue LowerEstimationLimit {
    125       get { return LowerEstimationLimitParameter.Value; }
    126       set { LowerEstimationLimitParameter.Value = value; }
    127     }
    128     public DoubleValue UpperEstimationLimit {
    129       get { return UpperEstimationLimitParameter.Value; }
    130       set { UpperEstimationLimitParameter.Value = value; }
    131     }
    132 
    13367    public new ISymbolicRegressionEvaluator Evaluator {
    13468      get { return EvaluatorParameter.Value; }
     
    14175      get { return EvaluatorParameter.Value; }
    14276    }
    143     public ISymbolicExpressionGrammar FunctionTreeGrammar {
    144       get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; }
    145     }
    14677    public DoubleValue BestKnownQuality {
    14778      get { return BestKnownQualityParameter.Value; }
    14879    }
    149     public override IEnumerable<IOperator> Operators {
    150       get { return operators; }
    151     }
    152     public IEnumerable<ISymbolicRegressionAnalyzer> Analyzers {
    153       get { return operators.OfType<ISymbolicRegressionAnalyzer>(); }
    154     }
    155     public DoubleValue PunishmentFactor {
    156       get { return new DoubleValue(10.0); }
    157     }
    158     public IntValue TrainingSamplesStart {
    159       get { return new IntValue(DataAnalysisProblemData.TrainingSamplesStart.Value); }
    160     }
    161     public IntValue TrainingSamplesEnd {
    162       get {
    163         return new IntValue((DataAnalysisProblemData.TrainingSamplesStart.Value +
    164           DataAnalysisProblemData.TrainingSamplesEnd.Value) / 2);
    165       }
    166     }
    167     public IntValue ValidationSamplesStart {
    168       get { return TrainingSamplesEnd; }
    169     }
    170     public IntValue ValidationSamplesEnd {
    171       get { return new IntValue(DataAnalysisProblemData.TrainingSamplesEnd.Value); }
    172     }
    173     public IntValue TestSamplesStart {
    174       get { return DataAnalysisProblemData.TestSamplesStart; }
    175     }
    176     public IntValue TestSamplesEnd {
    177       get { return DataAnalysisProblemData.TestSamplesEnd; }
    178     }
    17980    #endregion
    180 
    181     [Storable]
    182     private List<IOperator> operators;
    18381
    18482    [StorableConstructor]
     
    18684    public SymbolicRegressionProblem()
    18785      : base() {
    188       SymbolicExpressionTreeCreator creator = new ProbabilisticTreeCreator();
    18986      var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator();
    190       var grammar = new FullFunctionalExpressionGrammar();
    191       var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar);
    192       var interpreter = new SimpleArithmeticExpressionInterpreter();
    19387      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly()));
    194       Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new symbolic regression solutions.", creator));
    195       Parameters.Add(new ValueParameter<ISymbolicExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to evaluate the symbolic expression tree.", interpreter));
    19688      Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
    197       Parameters.Add(new ValueParameter<DoubleValue>("LowerEstimationLimit", "The lower limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.NegativeInfinity)));
    198       Parameters.Add(new ValueParameter<DoubleValue>("UpperEstimationLimit", "The upper limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.PositiveInfinity)));
    19989      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
    200       Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("FunctionTreeGrammar", "The grammar that should be used for symbolic regression models.", globalGrammar));
    201       Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100)));
    202       Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10)));
    203       Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
    204       Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
    20590
    206       creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel";
    20791      evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
    20892
    209       ParameterizeSolutionCreator();
     93      InitializeOperators();
    21094      ParameterizeEvaluator();
    21195
    212       UpdateGrammar();
    213       UpdateEstimationLimits();
    214       InitializeOperators();
    21596      RegisterParameterEvents();
    21697      RegisterParameterValueEvents();
     
    219100    public override IDeepCloneable Clone(Cloner cloner) {
    220101      SymbolicRegressionProblem clone = (SymbolicRegressionProblem)base.Clone(cloner);
    221       clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
    222102      clone.RegisterParameterEvents();
    223103      clone.RegisterParameterValueEvents();
     
    226106
    227107    private void RegisterParameterValueEvents() {
    228       MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
    229       MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
    230       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    231108      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    232109    }
    233110
    234     private void RegisterParameterEvents() {
    235       MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    236       MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    237       SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
    238       Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    239     }
     111    private void RegisterParameterEvents() { }
    240112
    241113    #region event handling
     
    246118      ParameterizeEvaluator();
    247119      ParameterizeAnalyzers();
    248       // input variables could have been changed
    249       UpdateGrammar();
    250       // estimation limits have to be recalculated
    251       UpdateEstimationLimits();
    252     }
    253     protected virtual void OnArchitectureParameterChanged(EventArgs e) {
    254       UpdateGrammar();
    255     }
    256     protected virtual void OnGrammarChanged(EventArgs e) { }
    257     protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }
    258     protected virtual void OnSolutionCreatorChanged(EventArgs e) {
    259       SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
    260       ParameterizeSolutionCreator();
    261       OnSolutionParameterNameChanged(e);
    262       RaiseSolutionCreatorChanged(e);
    263120    }
    264121
    265     protected virtual void OnSolutionParameterNameChanged(EventArgs e) {
     122    protected override void OnSolutionParameterNameChanged(EventArgs e) {
     123      base.OnSolutionParameterNameChanged(e);
    266124      ParameterizeEvaluator();
    267125      ParameterizeAnalyzers();
    268       ParameterizeOperators();
    269126    }
    270127
    271     protected virtual void OnEvaluatorChanged(EventArgs e) {
    272       Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     128    protected override void OnEvaluatorChanged(EventArgs e) {
     129      base.OnEvaluatorChanged(e);
    273130      ParameterizeEvaluator();
    274131      ParameterizeAnalyzers();
    275132      RaiseEvaluatorChanged(e);
    276133    }
    277     protected virtual void OnQualityParameterNameChanged(EventArgs e) {
    278       ParameterizeAnalyzers();
    279     }
    280134    #endregion
    281135
    282136    #region event handlers
    283     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    284       OnSolutionCreatorChanged(e);
    285     }
    286     private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
    287       OnSolutionParameterNameChanged(e);
    288     }
    289137    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    290138      OnEvaluatorChanged(e);
    291     }
    292     private void ArchitectureParameter_ValueChanged(object sender, EventArgs e) {
    293       MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    294       MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
    295       OnArchitectureParameterChanged(e);
    296     }
    297     private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {
    298       OnArchitectureParameterChanged(e);
    299     }
    300     private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    301       OnQualityParameterNameChanged(e);
    302139    }
    303140    #endregion
     
    308145      // BackwardsCompatibility3.3
    309146      #region Backwards compatible code (remove with 3.4)
    310       if (operators == null) InitializeOperators();
     147      if (Operators == null || Operators.Count() == 0) InitializeOperators();
    311148      #endregion
    312149      RegisterParameterEvents();
     
    314151    }
    315152
    316     private void UpdateGrammar() {
    317       foreach (var varSymbol in FunctionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable>()) {
    318         varSymbol.VariableNames = DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value);
    319       }
    320       var globalGrammar = FunctionTreeGrammar as GlobalSymbolicExpressionGrammar;
    321       if (globalGrammar != null) {
    322         globalGrammar.MaxFunctionArguments = MaxFunctionArguments.Value;
    323         globalGrammar.MaxFunctionDefinitions = MaxFunctionDefiningBranches.Value;
    324       }
    325     }
    326 
    327     private void UpdateEstimationLimits() {
    328       if (TrainingSamplesStart.Value < TrainingSamplesEnd.Value &&
    329         DataAnalysisProblemData.Dataset.VariableNames.Contains(DataAnalysisProblemData.TargetVariable.Value)) {
    330         var targetValues = DataAnalysisProblemData.Dataset.GetVariableValues(DataAnalysisProblemData.TargetVariable.Value, TrainingSamplesStart.Value, TrainingSamplesEnd.Value);
    331         var mean = targetValues.Average();
    332         var range = targetValues.Max() - targetValues.Min();
    333         UpperEstimationLimit = new DoubleValue(mean + PunishmentFactor.Value * range);
    334         LowerEstimationLimit = new DoubleValue(mean - PunishmentFactor.Value * range);
    335       }
    336     }
    337 
    338153    private void InitializeOperators() {
    339       operators = new List<IOperator>();
    340       operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
    341       operators.Add(new SymbolicRegressionTournamentPruning());
    342       operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer());
    343       operators.Add(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
    344       operators.Add(new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer());
    345       operators.Add(new SymbolicRegressionModelQualityAnalyzer());
    346       ParameterizeOperators();
     154      AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
    347155      ParameterizeAnalyzers();
    348     }
    349 
    350     private void ParameterizeSolutionCreator() {
    351       SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
    352       SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
    353       SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
    354       SolutionCreator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
    355       SolutionCreator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
    356156    }
    357157
     
    389189          bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    390190        }
    391         var symbolicRegressionModelQualityAnalyzer = analyzer as SymbolicRegressionModelQualityAnalyzer;
    392         if (symbolicRegressionModelQualityAnalyzer != null) {
    393           symbolicRegressionModelQualityAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
    394           symbolicRegressionModelQualityAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
    395           symbolicRegressionModelQualityAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
    396           symbolicRegressionModelQualityAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    397           symbolicRegressionModelQualityAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    398         }
    399         var varFreqAnalyzer = analyzer as SymbolicRegressionVariableFrequencyAnalyzer;
    400         if (varFreqAnalyzer != null) {
    401           varFreqAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
    402         }
    403         var pruningOperator = analyzer as SymbolicRegressionTournamentPruning;
    404         if (pruningOperator != null) {
    405           pruningOperator.SamplesStartParameter.Value = TrainingSamplesStart;
    406           pruningOperator.SamplesEndParameter.Value = TrainingSamplesEnd;
    407           pruningOperator.DataAnalysisProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
    408           pruningOperator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    409           pruningOperator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    410           pruningOperator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
    411           pruningOperator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
    412         }
    413       }
    414       foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
    415         analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    416       }
    417     }
    418 
    419     private void ParameterizeOperators() {
    420       foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) {
    421         op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
    422         op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
    423         op.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
    424       }
    425       foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    426         op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    427         op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    428       }
    429       foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
    430         op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    431       }
    432       foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {
    433         op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
    434         op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
    435191      }
    436192    }
Note: See TracChangeset for help on using the changeset viewer.