Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/10 20:27:08 (15 years ago)
Author:
gkronber
Message:

Added 'special treatment' of operators that use LookupParameters instead of ScopeTreeLookupParameters contained in analyzers. #999

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r3681 r3683  
    8787    <Compile Include="Properties\AssemblyInfo.cs" />
    8888    <Compile Include="Symbolic\Analyzers\BestSymbolicRegressionSolutionAnalyzer.cs" />
     89    <Compile Include="Symbolic\Analyzers\SymbolicRegressionMeanSquaredErrorCalculator.cs" />
    8990    <Compile Include="Symbolic\Analyzers\ISymbolicRegressionAnalyzer.cs" />
    9091    <Compile Include="Symbolic\Analyzers\SymbolicRegressionModelQualityAnalyzer.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityAnalyzer.cs

    r3681 r3683  
    132132
    133133    [Storable]
     134    private SymbolicRegressionModelQualityCalculator trainingQualityCalculator;
     135    [Storable]
     136    private SymbolicRegressionModelQualityCalculator testQualityCalculator;
     137    [Storable]
    134138    private MinAverageMaxValueAnalyzer minAvgMaxTrainingMseAnalyzer;
    135139    [Storable]
     
    161165
    162166      #region operator initialization
    163       // should be extended to calculate MSE, rel. Error and R² on the training (validation) and test set
    164       UniformSubScopesProcessor subScopesProcessor = new UniformSubScopesProcessor();
    165       SymbolicRegressionModelQualityCalculator trainingQualityCalculator = new SymbolicRegressionModelQualityCalculator();
    166       SymbolicRegressionModelQualityCalculator testQualityCalculator = new SymbolicRegressionModelQualityCalculator();
     167      trainingQualityCalculator = new SymbolicRegressionModelQualityCalculator();
     168      testQualityCalculator = new SymbolicRegressionModelQualityCalculator();
    167169      minAvgMaxTrainingMseAnalyzer = new MinAverageMaxValueAnalyzer();
    168170      minAvgMaxTestMseAnalyzer = new MinAverageMaxValueAnalyzer();
     
    182184      trainingQualityCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    183185      trainingQualityCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
     186      trainingQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    184187      trainingQualityCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
    185188      trainingQualityCalculator.AverageRelativeErrorQualityParameter.ActualName = TrainingAverageRelativeErrorQualityParameterName;
     
    193196      testQualityCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    194197      testQualityCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
     198      testQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    195199      testQualityCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
    196200      testQualityCalculator.AverageRelativeErrorQualityParameter.ActualName = TestAverageRelativeErrorQualityParameterName;
     
    251255
    252256      #region operator graph
    253       OperatorGraph.InitialOperator = subScopesProcessor;
    254       subScopesProcessor.Operator = trainingQualityCalculator;
     257      OperatorGraph.InitialOperator = trainingQualityCalculator;
    255258      trainingQualityCalculator.Successor = testQualityCalculator;
    256       testQualityCalculator.Successor = null;
    257       subScopesProcessor.Successor = minAvgMaxTrainingMseAnalyzer;
     259      testQualityCalculator.Successor = minAvgMaxTrainingMseAnalyzer;
    258260      minAvgMaxTrainingMseAnalyzer.Successor = minAvgMaxTestMseAnalyzer;
    259261      minAvgMaxTestMseAnalyzer.Successor = minAvgMaxTrainingRSquaredAnalyzer;
     
    282284
    283285    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
     286      trainingQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     287      testQualityCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    284288      minAvgMaxTrainingMseAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    285289      minAvgMaxTrainingRelErrorAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityCalculator.cs

    r3681 r3683  
    5757
    5858    #region parameter properties
     59    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
     60      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     61    }
    5962    public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
    6063      get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
    61     }
    62     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    63       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    6464    }
    6565    public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
     
    9292      : base() {
    9393      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
    94       Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to analyze."));
     94      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to analyze."));
    9595      Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data containing the input varaibles for the symbolic regression problem."));
    9696      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition on which the model quality values should be calculated."));
     
    122122      simpleR2Evalator.ValuesParameter.ActualName = ValuesParameterName;
    123123      simpleR2Evalator.RSquaredParameter.ActualName = RSquaredQualityParameter.Name;
    124      
     124
    125125      simpleMseEvaluator.ValuesParameter.ActualName = ValuesParameterName;
    126126      simpleMseEvaluator.MeanSquaredErrorParameter.ActualName = MeanSquaredErrorQualityParameter.Name;
    127      
     127
    128128      simpleRelErrorEvaluator.ValuesParameter.ActualName = ValuesParameterName;
    129129      simpleRelErrorEvaluator.AverageRelativeErrorParameter.ActualName = AverageRelativeErrorQualityParameter.Name;
     
    143143
    144144    }
     145
     146    // need to create custom operations for each solution scope (this has to be adapted on basis of the depth value of SymbolicExpressionTreeParameter)
     147    public override IOperation Apply() {
     148      var scopes = GetScopesOnLevel(ExecutionContext.Scope, SymbolicExpressionTreeParameter.Depth);
     149      OperationCollection operations = new OperationCollection();
     150      foreach (IScope treeScopes in scopes) {
     151        operations.Add(ExecutionContext.CreateChildOperation(OperatorGraph.InitialOperator, treeScopes));
     152      }
     153      if (Successor != null) operations.Add(ExecutionContext.CreateOperation(Successor));
     154      return operations;
     155    }
     156
     157    private IEnumerable<IScope> GetScopesOnLevel(IScope scope, int d) {
     158      if (d == 0) yield return scope;
     159      else {
     160        foreach (IScope subScope in scope.SubScopes) {
     161          foreach (IScope scopesOfSubScope in GetScopesOnLevel(subScope, d - 1)) {
     162            yield return scopesOfSubScope;
     163          }
     164        }
     165      }
     166    }
    145167  }
    146168}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionSolutionLinearScaler.cs

    r3651 r3683  
    4747    private const string BetaParameterName = "Beta";
    4848
    49     public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    50       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     49    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
     50      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    5151    }
    52     public ILookupParameter<SymbolicExpressionTree> ScaledSymbolicExpressionTreeParameter {
    53       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ScaledSymbolicExpressionTreeParameterName]; }
     52    public ScopeTreeLookupParameter<SymbolicExpressionTree> ScaledSymbolicExpressionTreeParameter {
     53      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[ScaledSymbolicExpressionTreeParameterName]; }
    5454    }
    55     public ILookupParameter<DoubleValue> AlphaParameter {
    56       get { return (ILookupParameter<DoubleValue>)Parameters[AlphaParameterName]; }
     55    public ScopeTreeLookupParameter<DoubleValue> AlphaParameter {
     56      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[AlphaParameterName]; }
    5757    }
    58     public ILookupParameter<DoubleValue> BetaParameter {
    59       get { return (ILookupParameter<DoubleValue>)Parameters[BetaParameterName]; }
     58    public ScopeTreeLookupParameter<DoubleValue> BetaParameter {
     59      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[BetaParameterName]; }
    6060    }
    6161
    6262    public SymbolicRegressionSolutionLinearScaler()
    6363      : base() {
    64       Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to transform."));
    65       Parameters.Add(new LookupParameter<SymbolicExpressionTree>(ScaledSymbolicExpressionTreeParameterName, "The resulting symbolic expression trees after transformation."));
    66       Parameters.Add(new LookupParameter<DoubleValue>(AlphaParameterName, "Alpha parameter for linear transformation."));
    67       Parameters.Add(new LookupParameter<DoubleValue>(BetaParameterName, "Beta parameter for linear transformation."));
     64      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to transform."));
     65      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(ScaledSymbolicExpressionTreeParameterName, "The resulting symbolic expression trees after transformation."));
     66      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(AlphaParameterName, "Alpha parameter for linear transformation."));
     67      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(BetaParameterName, "Beta parameter for linear transformation."));
    6868    }
    6969
    7070    public override IOperation Apply() {
    71       SymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue;
    72       double alpha = AlphaParameter.ActualValue.Value;
    73       double beta = BetaParameter.ActualValue.Value;
     71      ItemArray<SymbolicExpressionTree> trees = SymbolicExpressionTreeParameter.ActualValue;
     72      ItemArray<DoubleValue> alphas = AlphaParameter.ActualValue;
     73      ItemArray<DoubleValue> betas = BetaParameter.ActualValue;
     74      ItemArray<SymbolicExpressionTree> scaledTrees = new ItemArray<SymbolicExpressionTree>(trees.Length);
     75      for (int i = 0; i < trees.Length; i++) {
     76        var mainBranch = trees[i].Root.SubTrees[0].SubTrees[0];
     77        var scaledMainBranch = MakeSum(MakeProduct(betas[i].Value, mainBranch), alphas[i].Value);
    7478
    75       var mainBranch = tree.Root.SubTrees[0].SubTrees[0];
    76       var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha);
    77 
    78       // remove the main branch before cloning to prevent cloning of sub-trees
    79       tree.Root.SubTrees[0].RemoveSubTree(0);
    80       var scaledTree = (SymbolicExpressionTree)tree.Clone();
    81       // insert main branch into the original tree again
    82       tree.Root.SubTrees[0].InsertSubTree(0, mainBranch);
    83       // insert the scaled main branch into the cloned tree
    84       scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch);
    85       ScaledSymbolicExpressionTreeParameter.ActualValue = scaledTree;
     79        // remove the main branch before cloning to prevent cloning of sub-trees
     80        trees[i].Root.SubTrees[0].RemoveSubTree(0);
     81        var scaledTree = (SymbolicExpressionTree)trees[i].Clone();
     82        // insert main branch into the original tree again
     83        trees[i].Root.SubTrees[0].InsertSubTree(0, mainBranch);
     84        // insert the scaled main branch into the cloned tree
     85        scaledTree.Root.SubTrees[0].InsertSubTree(0, scaledMainBranch);
     86        scaledTrees[i] = scaledTree;
     87      }
     88      ScaledSymbolicExpressionTreeParameter.ActualValue = scaledTrees;
    8689      return base.Apply();
    8790    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs

    r3681 r3683  
    9595    [Storable]
    9696    private BestSymbolicRegressionSolutionAnalyzer bestSolutionAnalyzer;
     97    [Storable]
     98    private SymbolicRegressionSolutionLinearScaler linearScaler;
     99    [Storable]
     100    private SymbolicRegressionMeanSquaredErrorCalculator validationMseCalculator;
    97101
    98102    public ValidationBestScaledSymbolicRegressionSolutionAnalyzer()
     
    110114
    111115      #region operator initialization
    112       UniformSubScopesProcessor subScopesProc = new UniformSubScopesProcessor();
    113       SymbolicRegressionSolutionLinearScaler linearScaler = new SymbolicRegressionSolutionLinearScaler();
    114       SymbolicRegressionMeanSquaredErrorEvaluator validationMseEvaluator = new SymbolicRegressionMeanSquaredErrorEvaluator();
     116      linearScaler = new SymbolicRegressionSolutionLinearScaler();
     117      validationMseCalculator = new SymbolicRegressionMeanSquaredErrorCalculator();
    115118      bestSolutionAnalyzer = new BestSymbolicRegressionSolutionAnalyzer();
    116119      validationQualityMemorizer = new BestQualityMemorizer();
     
    122125      #region parameter wiring
    123126      linearScaler.AlphaParameter.ActualName = AlphaParameterName;
     127      linearScaler.AlphaParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    124128      linearScaler.BetaParameter.ActualName = BetaParameterName;
     129      linearScaler.BetaParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    125130      linearScaler.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
     131      linearScaler.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    126132      linearScaler.ScaledSymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
    127 
    128       validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
    129       validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
    130       validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
    131       validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    132       validationMseEvaluator.QualityParameter.ActualName = QualityParameterName;
    133       validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
    134       validationMseEvaluator.SamplesStartParameter.ActualName = SamplesStartParameter.Name;
    135       validationMseEvaluator.SamplesEndParameter.ActualName = SamplesEndParameter.Name;
     133      linearScaler.ScaledSymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     134
     135      validationMseCalculator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
     136      validationMseCalculator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
     137      validationMseCalculator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
     138      validationMseCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     139      validationMseCalculator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
     140      validationMseCalculator.QualityParameter.ActualName = QualityParameterName;
     141      validationMseCalculator.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     142      validationMseCalculator.SamplesStartParameter.ActualName = SamplesStartParameter.Name;
     143      validationMseCalculator.SamplesEndParameter.ActualName = SamplesEndParameter.Name;
    136144
    137145      bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name;
     
    167175
    168176      #region operator graph
    169       OperatorGraph.InitialOperator = subScopesProc;
    170       subScopesProc.Operator = linearScaler;
    171       linearScaler.Successor = validationMseEvaluator;
    172       validationMseEvaluator.Successor = null;
    173       subScopesProc.Successor = bestSolutionAnalyzer;
     177      OperatorGraph.InitialOperator = linearScaler;
     178      linearScaler.Successor = validationMseCalculator;
     179      validationMseCalculator.Successor = bestSolutionAnalyzer;
    174180      bestSolutionAnalyzer.Successor = bestAvgWorstValidationQualityCalculator;
    175181      bestAvgWorstValidationQualityCalculator.Successor = validationQualityMemorizer;
     
    197203
    198204    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
     205      validationMseCalculator.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    199206      validationQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    200207      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     208      bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     209      linearScaler.AlphaParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     210      linearScaler.BetaParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     211      linearScaler.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
     212      linearScaler.ScaledSymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
    201213    }
    202214  }
Note: See TracChangeset for help on using the changeset viewer.