Changeset 13220


Ignore:
Timestamp:
11/17/15 15:45:55 (3 years ago)
Author:
mkommend
Message:

#2175: Improve source code and usability of complexity calculator.

Location:
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r12130 r13220  
    4141    private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities";
    4242    private const string UpdateAlwaysParameterName = "Always update best solutions";
    43 
    4443    private const string TrainingBestSolutionParameterName = "Best training solution";
    45     private const string TrainingBestSolutionQualityParameterName = "Best training solution quality";
    46     private const string TrainingBestSolutionGenerationParameterName = "Best training solution generation";
    4744
    4845    #region parameter properties
     
    5855    #endregion
    5956    #region properties
    60     public ItemList<T> TrainingBestSolutions {
     57    private ItemList<T> TrainingBestSolutions {
    6158      get { return TrainingBestSolutionsParameter.ActualValue; }
    6259      set { TrainingBestSolutionsParameter.ActualValue = value; }
    6360    }
    64     public ItemList<DoubleArray> TrainingBestSolutionQualities {
     61    private ItemList<DoubleArray> TrainingBestSolutionQualities {
    6562      get { return TrainingBestSolutionQualitiesParameter.ActualValue; }
    6663      set { TrainingBestSolutionQualitiesParameter.ActualValue = value; }
    6764    }
    68     public BoolValue UpdateAlways {
    69       get { return UpdateAlwaysParameter.Value; }
     65    public bool UpdateAlways {
     66      get { return UpdateAlwaysParameter.Value.Value; }
     67      set { UpdateAlwaysParameter.Value.Value = value; }
    7068    }
    7169    #endregion
     
    106104      //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions
    107105      List<double[]> trainingBestQualities;
    108       if (UpdateAlways.Value) {
     106      if (UpdateAlways) {
    109107        trainingBestQualities = new List<double[]>();
    110108      } else {
     
    144142        }
    145143
    146         var sortedNonDominatedSolutions = nonDominatedSolutions.OrderByDescending(x => x.Qualities[0]);
     144        //assumes the the first objective is always the accuracy
     145        var sortedNonDominatedSolutions = maximization[0]
     146          ? nonDominatedSolutions.OrderByDescending(x => x.Qualities[0])
     147          : nonDominatedSolutions.OrderBy(x => x.Qualities[0]);
    147148        var trainingBestSolution = sortedNonDominatedSolutions.Select(s => s.Solution).First();
    148149        results[TrainingBestSolutionParameterName].Value = trainingBestSolution;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r13213 r13220  
    182182  </ItemGroup>
    183183  <ItemGroup>
    184     <Compile Include="Analyzers\SymbolicDataAnalysisModelComplexityAnalyzer.cs" />
     184    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
     185    <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" />
    185186    <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" />
    186187    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
     
    249250    <Compile Include="SymbolicDataAnalysisProblem.cs" />
    250251    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
    251     <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
    252252    <Compile Include="Symbols\Addition.cs" />
    253253    <Compile Include="Symbols\And.cs" />
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs

    r12849 r13220  
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    30   public class SymbolicDataAnalysisExpressionTreeSimplificationOperator : SingleSuccessorOperator {
     30  [Item("SymbolicExpressionTreeSimplificationOperator", "Simplfies symbolic expression trees encoding a mathematical formula.")]
     31  [StorableClass]
     32  public class SymbolicDataAnalysisExpressionTreeSimplificationOperator : SingleSuccessorOperator, ISymbolicExpressionTreeOperator {
    3133    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    3234
     
    4648
    4749    public SymbolicDataAnalysisExpressionTreeSimplificationOperator() {
    48       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to be simplified."));
     50      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to simplify."));
    4951    }
    5052
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs

    r13219 r13220  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    28   public class SymbolicDataAnalysisModelComplexityAnalyzer {
    29     public static double CalculateComplexity(ISymbolicExpressionTreeNode node) {
     28  public static class SymbolicDataAnalysisModelComplexityCalculator {
     29    public static double CalculateComplexity(ISymbolicExpressionTree tree) {
     30      return CalculateComplexity(tree.Root);
     31    }
     32    public static double CalculateComplexity(ISymbolicExpressionTreeNode treeNode) {
     33      var node = treeNode;
     34      if (node.Symbol is ProgramRootSymbol) node = node.GetSubtree(0);
     35      if (node.Symbol is StartSymbol) node = node.GetSubtree(0);
     36
    3037      switch (OpCodes.MapSymbolToOpCode(node)) {
    3138        case OpCodes.Constant: {
     
    6168            for (int i = 0; i < node.SubtreeCount; i++) {
    6269              var nodeComplexity = CalculateComplexity(node.GetSubtree(i));
    63               complexity *= nodeComplexity +1;
     70              complexity *= nodeComplexity + 1;
    6471            }
    6572            return complexity;
Note: See TracChangeset for help on using the changeset viewer.