Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14399


Ignore:
Timestamp:
11/17/16 15:30:11 (8 years ago)
Author:
gkronber
Message:

#2650: merged r14352:14376 from trunk to branch (resolving conflicts in SymbolicDataAnalysisExpressionLatexFormatter

Location:
branches/symbreg-factors-2650
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650

  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis

  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModel.cs

    r14351 r14399  
    202202
    203203    public ISymbolicExpressionTree ExtractTree(int treeIdx) {
     204      var rf = RandomForest;
    204205      // hoping that the internal representation of alglib is stable
    205206
     
    214215      int offset = 0;
    215216      for (int i = 0; i < treeIdx - 1; i++) {
    216         offset = offset + (int)Math.Round(randomForest.innerobj.trees[offset]);
     217        offset = offset + (int)Math.Round(rf.innerobj.trees[offset]);
    217218      }
    218219
     
    220221      var varCondSy = new VariableCondition() { IgnoreSlope = true };
    221222
    222       var node = CreateRegressionTreeRec(randomForest.innerobj.trees, offset, offset + 1, constSy, varCondSy);
     223      var node = CreateRegressionTreeRec(rf.innerobj.trees, offset, offset + 1, constSy, varCondSy);
    223224
    224225      var startNode = new StartSymbol().CreateTreeNode();
  • branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views

  • branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r14277 r14399  
    7575          PreprocessingDataTable pdt = new PreprocessingDataTable(variableName);
    7676          pdt.Rows.Add(row);
    77           // dataTablePerVariable does not contain unchecked variables => reduce insert position by number of uncheckt variables to correct the index
     77          // dataTablePerVariable does not contain unchecked variables => reduce insert position by number of unchecked variables to correct the index
    7878          int uncheckedUntilVariable = checkedItemList.Content.TakeWhile(x => x.Value != variableName).Count(x => !checkedItemList.Content.ItemChecked(x));
    7979          dataTablePerVariable.Insert(item.Index - uncheckedUntilVariable, pdt);
  • branches/symbreg-factors-2650/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/symbreg-factors-2650/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/GrammarUtils.cs

    r14351 r14399  
    2525using System.Collections.Generic;
    2626using System.Linq;
    27 
    2827namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    2928  public static class GrammarUtils {
     29    private static IEnumerable<ISymbol> GetTopmostSymbols(this ISymbolicExpressionGrammarBase grammar) {
     30      // build parents list so we can find out the topmost symbol(s)
     31      var parents = new Dictionary<ISymbol, List<ISymbol>>();
     32      foreach (var symbol in grammar.Symbols.Where(x => grammar.GetMinimumSubtreeCount(x) > 0)) {
     33        var minSubtreeCount = grammar.GetMinimumSubtreeCount(symbol);
     34        for (int argIndex = 0; argIndex < minSubtreeCount; ++argIndex) {
     35          foreach (var childSymbol in grammar.GetAllowedActiveSymbols(symbol, argIndex)) {
     36            if (!parents.ContainsKey(childSymbol))
     37              parents[childSymbol] = new List<ISymbol>();
     38            parents[childSymbol].Add(symbol);
     39          }
     40        }
     41      }
     42      // the topmost symbols have no parents
     43      return parents.Values.SelectMany(x => x).Distinct().Where(x => !parents.ContainsKey(x));
     44    }
     45
     46    private static IReadOnlyCollection<ISymbol> IterateBreadthReverse(this ISymbolicExpressionGrammarBase grammar, ISymbol topSymbol) {
     47      // sort symbols in reverse breadth order (starting from the topSymbol)
     48      // each symbol is visited only once (this avoids infinite recursion)
     49      var symbols = new List<ISymbol> { topSymbol };
     50      var visited = new HashSet<ISymbol> { topSymbol };
     51      int i = 0;
     52      while (i < symbols.Count) {
     53        var symbol = symbols[i];
     54        var minSubtreeCount = grammar.GetMinimumSubtreeCount(symbol);
     55
     56        for (int argIndex = 0; argIndex < minSubtreeCount; ++argIndex) {
     57          foreach (var childSymbol in grammar.GetAllowedActiveSymbols(symbol, argIndex)) {
     58            if (grammar.GetMinimumSubtreeCount(childSymbol) == 0)
     59              continue;
     60
     61            if (visited.Add(childSymbol))
     62              symbols.Add(childSymbol);
     63          }
     64        }
     65        ++i;
     66      }
     67      symbols.Reverse();
     68      return symbols;
     69    }
     70
     71    private static IEnumerable<ISymbol> GetAllowedActiveSymbols(this ISymbolicExpressionGrammarBase grammar, ISymbol symbol, int argIndex) {
     72      return grammar.GetAllowedChildSymbols(symbol, argIndex).Where(s => s.InitialFrequency > 0);
     73    }
    3074
    3175    public static void CalculateMinimumExpressionLengths(ISymbolicExpressionGrammarBase grammar,
    3276      Dictionary<string, int> minimumExpressionLengths) {
    33 
    3477      minimumExpressionLengths.Clear();
    3578      //terminal symbols => minimum expression length = 1
    36       foreach (var s in grammar.Symbols.Where(s => grammar.GetMinimumSubtreeCount(s) == 0))
    37         minimumExpressionLengths[s.Name] = 1;
     79      foreach (var s in grammar.Symbols) {
     80        if (grammar.GetMinimumSubtreeCount(s) == 0)
     81          minimumExpressionLengths[s.Name] = 1;
     82        else
     83          minimumExpressionLengths[s.Name] = int.MaxValue;
     84      }
    3885
    39       var symbolAdded = true;
    40       while (symbolAdded) {
    41         symbolAdded = false;
    42         foreach (var remainingSymbol in grammar.Symbols) {
    43           if (minimumExpressionLengths.ContainsKey(remainingSymbol.Name)) continue;
    44 
    45           var arguments = grammar.GetMinimumSubtreeCount(remainingSymbol);
    46           int minLength = 1;
    47 
    48           foreach (int argumentIndex in Enumerable.Range(0, arguments)) {
    49             var capturedMinimumLengths = minimumExpressionLengths;
    50             var childSymbols = grammar.GetAllowedChildSymbols(remainingSymbol, argumentIndex)
    51               .Where(c => c.InitialFrequency > 0.0 && capturedMinimumLengths.ContainsKey(c.Name));
    52 
    53             if (!childSymbols.Any()) {
    54               minLength = -1;
    55               break;
     86      foreach (var topSymbol in grammar.GetTopmostSymbols()) {
     87        // get all symbols below in reverse breadth order
     88        // this way we ensure lengths are calculated bottom-up
     89        var symbols = grammar.IterateBreadthReverse(topSymbol);
     90        foreach (var symbol in symbols) {
     91          long minLength = 1;
     92          for (int argIndex = 0; argIndex < grammar.GetMinimumSubtreeCount(symbol); ++argIndex) {
     93            long length = grammar.GetAllowedActiveSymbols(symbol, argIndex)
     94              .Where(x => minimumExpressionLengths.ContainsKey(x.Name))
     95              .Select(x => minimumExpressionLengths[x.Name]).DefaultIfEmpty(int.MaxValue).Min();
     96            minLength += length;
     97          }
     98          int oldLength;
     99          if (minimumExpressionLengths.TryGetValue(symbol.Name, out oldLength))
     100            minLength = Math.Min(minLength, oldLength);
     101          minimumExpressionLengths[symbol.Name] = (int)Math.Min(int.MaxValue, minLength);
     102        }
     103        // correction step for cycles
     104        bool changed = true;
     105        while (changed) {
     106          changed = false;
     107          foreach (var symbol in symbols) {
     108            long minLength = Enumerable.Range(0, grammar.GetMinimumSubtreeCount(symbol))
     109              .Sum(x => grammar.GetAllowedActiveSymbols(symbol, x)
     110              .Select(s => (long)minimumExpressionLengths[s.Name]).DefaultIfEmpty(int.MaxValue).Min()) + 1;
     111            if (minLength < minimumExpressionLengths[symbol.Name]) {
     112              minimumExpressionLengths[symbol.Name] = (int)Math.Min(minLength, int.MaxValue);
     113              changed = true;
    56114            }
    57             var minLengthPerArgument = childSymbols.Min(c => capturedMinimumLengths[c.Name]);
    58             minLength += minLengthPerArgument;
    59           }
    60 
    61           if (minLength != -1) {
    62             minimumExpressionLengths[remainingSymbol.Name] = minLength;
    63             symbolAdded = true;
    64115          }
    65116        }
    66117      }
    67 
    68       //set minLength to int.Maxvalue for all symbols that are not reacheable
    69       foreach (var remainingSymbols in grammar.Symbols) {
    70         if (!minimumExpressionLengths.ContainsKey(remainingSymbols.Name))
    71           minimumExpressionLengths[remainingSymbols.Name] = int.MaxValue;
    72       }
    73118    }
    74 
    75119
    76120    public static void CalculateMinimumExpressionDepth(ISymbolicExpressionGrammarBase grammar,
     
    79123      minimumExpressionDepths.Clear();
    80124      //terminal symbols => minimum expression depth = 1
    81       foreach (var s in grammar.Symbols.Where(s => grammar.GetMinimumSubtreeCount(s) == 0))
    82         minimumExpressionDepths[s.Name] = 1;
     125      foreach (var s in grammar.Symbols) {
     126        if (grammar.GetMinimumSubtreeCount(s) == 0)
     127          minimumExpressionDepths[s.Name] = 1;
     128        else
     129          minimumExpressionDepths[s.Name] = int.MaxValue;
     130      }
    83131
    84       var symbolAdded = true;
    85       while (symbolAdded) {
    86         symbolAdded = false;
    87         foreach (var remainingSymbol in grammar.Symbols) {
    88           if (minimumExpressionDepths.ContainsKey(remainingSymbol.Name)) continue;
    89 
    90           var arguments = grammar.GetMinimumSubtreeCount(remainingSymbol);
    91           int minDepth = -1;
    92 
    93           foreach (int argumentIndex in Enumerable.Range(0, arguments)) {
    94             var capturedMinimumDepths = minimumExpressionDepths;
    95             var childSymbols = grammar.GetAllowedChildSymbols(remainingSymbol, argumentIndex)
    96               .Where(c => c.InitialFrequency > 0.0 && capturedMinimumDepths.ContainsKey(c.Name));
    97             if (!childSymbols.Any()) {
    98               minDepth = -1;
    99               break;
     132      foreach (var topSymbol in grammar.GetTopmostSymbols()) {
     133        // get all symbols below in reverse breadth order
     134        // this way we ensure lengths are calculated bottom-up
     135        var symbols = grammar.IterateBreadthReverse(topSymbol);
     136        foreach (var symbol in symbols) {
     137          long minDepth = -1;
     138          for (int argIndex = 0; argIndex < grammar.GetMinimumSubtreeCount(symbol); ++argIndex) {
     139            long depth = grammar.GetAllowedActiveSymbols(symbol, argIndex)
     140              .Where(x => minimumExpressionDepths.ContainsKey(x.Name))
     141              .Select(x => (long)minimumExpressionDepths[x.Name]).DefaultIfEmpty(int.MaxValue).Min() + 1;
     142            minDepth = Math.Max(minDepth, depth);
     143          }
     144          int oldDepth;
     145          if (minimumExpressionDepths.TryGetValue(symbol.Name, out oldDepth))
     146            minDepth = Math.Min(minDepth, oldDepth);
     147          minimumExpressionDepths[symbol.Name] = (int)Math.Min(int.MaxValue, minDepth);
     148        }
     149        // correction step for cycles
     150        bool changed = true;
     151        while (changed) {
     152          changed = false;
     153          foreach (var symbol in symbols) {
     154            long minDepth = Enumerable.Range(0, grammar.GetMinimumSubtreeCount(symbol))
     155              .Max(x => grammar.GetAllowedActiveSymbols(symbol, x)
     156              .Select(s => (long)minimumExpressionDepths[s.Name]).DefaultIfEmpty(int.MaxValue).Min()) + 1;
     157            if (minDepth < minimumExpressionDepths[symbol.Name]) {
     158              minimumExpressionDepths[symbol.Name] = (int)Math.Min(minDepth, int.MaxValue);
     159              changed = true;
    100160            }
    101             var minDepthPerArgument = childSymbols.Min(c => capturedMinimumDepths[c.Name]);
    102             minDepth = Math.Max(minDepth, 1 + minDepthPerArgument);
    103           }
    104 
    105           if (minDepth != -1) {
    106             minimumExpressionDepths[remainingSymbol.Name] = minDepth;
    107             symbolAdded = true;
    108161          }
    109162        }
    110       }
    111 
    112       //set minDepth to int.Maxvalue for all symbols that are not reacheable
    113       foreach (var remainingSymbols in grammar.Symbols) {
    114         if (!minimumExpressionDepths.ContainsKey(remainingSymbols.Name))
    115           minimumExpressionDepths[remainingSymbols.Name] = int.MaxValue;
    116163      }
    117164    }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis

  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4

  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r14351 r14399  
    332332          term = AutoDiff.TermBuilder.Product(w, par);
    333333        } else {
    334           term = par;
     334          term = varNode.Weight * par;
    335335        }
    336336        return true;
     
    362362          term = AutoDiff.TermBuilder.Product(w, par);
    363363        } else {
    364           term = par;
     364          term = varNode.Weight * par;
    365365        }
    366366        return true;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r14277 r14399  
    113113      } else if (node.Symbol is Division) {
    114114        if (node.SubtreeCount == 1) {
    115           strBuilder.Append(@" \cfrac{1");
     115          strBuilder.Append(@" \cfrac{1}{");
    116116        } else {
    117117          strBuilder.Append(@" \cfrac{ ");
     
    182182        var constName = "c_{" + constIndex + "}";
    183183        constIndex++;
    184         strBuilder.Append(constName + " ");
    185184        var constNode = node as ConstantTreeNode;
    186         constants.Add(new KeyValuePair<string, double>(constName, constNode.Value));
     185        if (constNode.Value.IsAlmost(1.0)) {
     186          strBuilder.Append("1 ");
     187        } else {
     188          strBuilder.Append(constName);
     189          constants.Add(new KeyValuePair<string, double>(constName, constNode.Value));
     190        }
     191
    187192      } else if (node.Symbol is FactorVariable) {
    188193        var factorNode = node as FactorVariableTreeNode;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class ClassificationPerformanceMeasuresCalculator : IDeepCloneable {
     27  public class ClassificationPerformanceMeasuresCalculator : DeepCloneable {
    2828
    2929    public ClassificationPerformanceMeasuresCalculator(string positiveClassName, double positiveClassValue) {
     
    3333    }
    3434
    35     protected ClassificationPerformanceMeasuresCalculator(ClassificationPerformanceMeasuresCalculator original, Cloner cloner = null) {
     35    protected ClassificationPerformanceMeasuresCalculator(ClassificationPerformanceMeasuresCalculator original, Cloner cloner) {
    3636      positiveClassName = original.positiveClassName;
    3737      positiveClassValue = original.positiveClassValue;
     
    148148    }
    149149
    150     // IDeepCloneable interface members
    151     public object Clone() {
    152       return new ClassificationPerformanceMeasuresCalculator(this);
    153     }
    154 
    155     public IDeepCloneable Clone(Cloner cloner) {
    156       var clone = cloner.GetClone(this);
    157       if (clone == null) {
    158         clone = new ClassificationPerformanceMeasuresCalculator(this);
    159         cloner.RegisterClonedObject(this, clone);
    160       }
    161       return clone;
     150    public override IDeepCloneable Clone(Cloner cloner) {
     151      return new ClassificationPerformanceMeasuresCalculator(this, cloner);
    162152    }
    163153  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineAccuracyCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineAccuracyCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private int correctlyClassified;
     
    3939    }
    4040
    41     // private constructor used internally by the Clone() method
    42     protected OnlineAccuracyCalculator(OnlineAccuracyCalculator other, Cloner cloner = null) {
    43       correctlyClassified = other.correctlyClassified;
    44       n = other.n;
    45       errorState = other.errorState;
     41    protected OnlineAccuracyCalculator(OnlineAccuracyCalculator original, Cloner cloner)
     42      : base(original, cloner) {
     43      correctlyClassified = original.correctlyClassified;
     44      n = original.n;
     45      errorState = original.errorState;
    4646    }
     47
     48    public override IDeepCloneable Clone(Cloner cloner) {
     49      return new OnlineAccuracyCalculator(this, cloner);
     50    }
     51
    4752
    4853    #region IOnlineCalculator Members
     
    98103    }
    99104
    100     // IDeepCloneable interface members
    101     public object Clone() {
    102       return new OnlineAccuracyCalculator(this);
    103     }
    104 
    105     public IDeepCloneable Clone(Cloner cloner) {
    106       var clone = cloner.GetClone(this);
    107       if (clone == null) {
    108         clone = new OnlineAccuracyCalculator(this);
    109         cloner.RegisterClonedObject(this, clone);
    110       }
    111       return clone;
    112     }
    113105  }
    114106}
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineBoundedMeanSquaredErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineBoundedMeanSquaredErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineBoundedMeanSquaredErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double errorSum;
     
    4545    }
    4646
    47     protected OnlineBoundedMeanSquaredErrorCalculator(OnlineBoundedMeanSquaredErrorCalculator original, Cloner cloner = null) {
     47    protected OnlineBoundedMeanSquaredErrorCalculator(OnlineBoundedMeanSquaredErrorCalculator original, Cloner cloner) {
    4848      LowerBound = original.LowerBound;
    4949      UpperBound = original.UpperBound;
     
    107107
    108108    // IDeepCloneable interface members
    109     public object Clone() {
    110       return new OnlineBoundedMeanSquaredErrorCalculator(this);
    111     }
    112 
    113     public IDeepCloneable Clone(Cloner cloner) {
    114       var clone = cloner.GetClone(this);
    115       if (clone == null) {
    116         clone = new OnlineBoundedMeanSquaredErrorCalculator(this);
    117         cloner.RegisterClonedObject(this, clone);
    118       }
    119       return clone;
     109    public override IDeepCloneable Clone(Cloner cloner) {
     110      return new OnlineBoundedMeanSquaredErrorCalculator(this, cloner);
    120111    }
    121112  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineCovarianceCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineCovarianceCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double xMean, yMean, Cn;
     
    3939    }
    4040
    41     protected OnlineCovarianceCalculator(OnlineCovarianceCalculator other, Cloner cloner = null) {
     41    protected OnlineCovarianceCalculator(OnlineCovarianceCalculator other, Cloner cloner) {
    4242      Cn = other.Cn;
    4343      xMean = other.xMean;
     
    104104    }
    105105
    106     // IDeepCloneable interface members
    107     public object Clone() {
    108       return new OnlineCovarianceCalculator(this);
    109     }
    110 
    111     public IDeepCloneable Clone(Cloner cloner) {
    112       var clone = cloner.GetClone(this);
    113       if (clone == null) {
    114         clone = new OnlineCovarianceCalculator(this);
    115         cloner.RegisterClonedObject(this, clone);
    116       }
    117       return clone;
     106    public override IDeepCloneable Clone(Cloner cloner) {
     107      return new OnlineCovarianceCalculator(this, cloner);
    118108    }
    119109  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs

    r14330 r14399  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis {
    28   public class OnlineDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator, IDeepCloneable {
     28  public class OnlineDirectionalSymmetryCalculator : DeepCloneable, IOnlineTimeSeriesCalculator {
    2929    private int n;
    3030    private int nCorrect;
     
    123123    }
    124124
    125     // IDeepCloneable interface members
    126     public object Clone() {
    127       return new OnlineDirectionalSymmetryCalculator(this);
    128     }
    129 
    130     public IDeepCloneable Clone(Cloner cloner) {
    131       var clone = cloner.GetClone(this);
    132       if (clone == null) {
    133         clone = new OnlineDirectionalSymmetryCalculator(this);
    134         cloner.RegisterClonedObject(this, clone);
    135       }
    136       return clone;
     125    public override IDeepCloneable Clone(Cloner cloner) {
     126      return new OnlineDirectionalSymmetryCalculator(this, cloner);
    137127    }
    138128  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineLinearScalingParameterCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineLinearScalingParameterCalculator : IDeepCloneable {
     27  public class OnlineLinearScalingParameterCalculator : DeepCloneable {
    2828
    2929    /// <summary>
     
    126126    }
    127127
    128     // IDeepCloneable interface members
    129     public object Clone() {
    130       var cloner = new Cloner();
     128    public override IDeepCloneable Clone(Cloner cloner) {
    131129      return new OnlineLinearScalingParameterCalculator(this, cloner);
    132     }
    133 
    134     public IDeepCloneable Clone(Cloner cloner) {
    135       var clone = cloner.GetClone(this);
    136       if (clone == null) {
    137         clone = new OnlineLinearScalingParameterCalculator(this, cloner);
    138         cloner.RegisterClonedObject(this, clone);
    139       }
    140       return clone;
    141130    }
    142131  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMaxAbsoluteErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineMaxAbsoluteErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineMaxAbsoluteErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double mae;
     
    9696    }
    9797
    98     // IDeepCloneable interface members
    99     public object Clone() {
    100       return new OnlineMaxAbsoluteErrorCalculator(this);
    101     }
    102 
    103     public IDeepCloneable Clone(Cloner cloner) {
    104       var clone = cloner.GetClone(this);
    105       if (clone == null) {
    106         clone = new OnlineMaxAbsoluteErrorCalculator(this);
    107         cloner.RegisterClonedObject(this, clone);
    108       }
    109       return clone;
     98    public override IDeepCloneable Clone(Cloner cloner) {
     99      return new OnlineMaxAbsoluteErrorCalculator(this, cloner);
    110100    }
    111101  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineMeanAbsoluteErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineMeanAbsoluteErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double sae;
     
    9595    }
    9696
    97     // IDeepCloneable interface members
    98     public object Clone() {
    99       return new OnlineMeanAbsoluteErrorCalculator(this);
    100     }
    101 
    102     public IDeepCloneable Clone(Cloner cloner) {
    103       var clone = cloner.GetClone(this);
    104       if (clone == null) {
    105         clone = new OnlineMeanAbsoluteErrorCalculator(this);
    106         cloner.RegisterClonedObject(this, clone);
    107       }
    108       return clone;
     97    public override IDeepCloneable Clone(Cloner cloner) {
     98      return new OnlineMeanAbsoluteErrorCalculator(this, cloner);
    10999    }
    110100  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineMeanAbsolutePercentageErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineMeanAbsolutePercentageErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double sre;
     
    9696    }
    9797
    98     // IDeepCloneable interface members
    99     public object Clone() {
    100       return new OnlineMeanAbsolutePercentageErrorCalculator(this);
    101     }
    102 
    103     public IDeepCloneable Clone(Cloner cloner) {
    104       var clone = cloner.GetClone(this);
    105       if (clone == null) {
    106         clone = new OnlineMeanAbsolutePercentageErrorCalculator(this);
    107         cloner.RegisterClonedObject(this, clone);
    108       }
    109       return clone;
     98    public override IDeepCloneable Clone(Cloner cloner) {
     99      return new OnlineMeanAbsolutePercentageErrorCalculator(this, cloner);
    110100    }
    111101  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAndVarianceCalculator.cs

    r14330 r14399  
    2424
    2525namespace HeuristicLab.Problems.DataAnalysis {
    26   public class OnlineMeanAndVarianceCalculator : IDeepCloneable {
     26  public class OnlineMeanAndVarianceCalculator : DeepCloneable {
    2727
    2828    private double m_oldM, m_newM, m_oldS, m_newS;
     
    118118    }
    119119
    120     // IDeepCloneable members
    121     public object Clone() {
    122       return new OnlineMeanAndVarianceCalculator(this);
    123     }
    124 
    125     public IDeepCloneable Clone(Cloner cloner) {
    126       var clone = cloner.GetClone(this);
    127       if (clone == null) {
    128         clone = new OnlineMeanAndVarianceCalculator(this);
    129         cloner.RegisterClonedObject(this, clone);
    130       }
    131       return clone;
     120    public override IDeepCloneable Clone(Cloner cloner) {
     121      return new OnlineMeanAndVarianceCalculator(this, cloner);
    132122    }
    133123  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineMeanErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineMeanErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private readonly OnlineMeanAndVarianceCalculator meanAndVarianceCalculator;
     
    8080    }
    8181
    82     // IDeepCloneable members
    83     public object Clone() {
    84       var cloner = new Cloner();
     82    public override IDeepCloneable Clone(Cloner cloner) {
    8583      return new OnlineMeanErrorCalculator(this, cloner);
    86     }
    87 
    88     public IDeepCloneable Clone(Cloner cloner) {
    89       var clone = cloner.GetClone(this);
    90       if (clone == null) {
    91         clone = new OnlineMeanErrorCalculator(this, cloner);
    92         cloner.RegisterClonedObject(this, clone);
    93       }
    94       return clone;
    9584    }
    9685  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineMeanSquaredErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineMeanSquaredErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828
    2929    private double sse;
     
    9595    }
    9696
    97     // IDeepCloneable members
    98     public object Clone() {
    99       return new OnlineMeanSquaredErrorCalculator(this);
    100     }
    101 
    102     public IDeepCloneable Clone(Cloner cloner) {
    103       var clone = cloner.GetClone(this);
    104       if (clone == null) {
    105         clone = new OnlineMeanSquaredErrorCalculator(this);
    106         cloner.RegisterClonedObject(this, clone);
    107       }
    108       return clone;
     97    public override IDeepCloneable Clone(Cloner cloner) {
     98      return new OnlineMeanSquaredErrorCalculator(this, cloner);
    10999    }
    110100  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineNormalizedMeanSquaredErrorCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlineNormalizedMeanSquaredErrorCalculator : DeepCloneable, IOnlineCalculator {
    2828    private OnlineMeanAndVarianceCalculator meanSquaredErrorCalculator;
    2929    private OnlineMeanAndVarianceCalculator originalVarianceCalculator;
     
    9999    }
    100100
    101     // IDeepCloneable members
    102     public object Clone() {
    103       var cloner = new Cloner();
     101    public override IDeepCloneable Clone(Cloner cloner) {
    104102      return new OnlineNormalizedMeanSquaredErrorCalculator(this, cloner);
    105     }
    106 
    107     public IDeepCloneable Clone(Cloner cloner) {
    108       var clone = cloner.GetClone(this);
    109       if (clone == null) {
    110         clone = new OnlineNormalizedMeanSquaredErrorCalculator(this, cloner);
    111         cloner.RegisterClonedObject(this, clone);
    112       }
    113       return clone;
    114103    }
    115104  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlinePearsonsRCalculator : IOnlineCalculator, IDeepCloneable {
     27  public class OnlinePearsonsRCalculator : DeepCloneable, IOnlineCalculator {
    2828    private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator();
    2929    private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator();
     
    9898    }
    9999
    100     // IDeepCloneable members
    101     public object Clone() {
    102       var cloner = new Cloner();
     100    public override IDeepCloneable Clone(Cloner cloner) {
    103101      return new OnlinePearsonsRCalculator(this, cloner);
    104     }
    105 
    106     public IDeepCloneable Clone(Cloner cloner) {
    107       var clone = cloner.GetClone(this);
    108       if (clone == null) {
    109         clone = new OnlinePearsonsRCalculator(this, cloner);
    110         cloner.RegisterClonedObject(this, clone);
    111       }
    112       return clone;
    113102    }
    114103  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r14330 r14399  
    2626namespace HeuristicLab.Problems.DataAnalysis {
    2727  [Obsolete("Use OnlinePearsonsRCalculator directly")]
    28   public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator, IDeepCloneable {
     28  public class OnlinePearsonsRSquaredCalculator : DeepCloneable, IOnlineCalculator {
    2929    private readonly OnlinePearsonsRCalculator rCalculator = new OnlinePearsonsRCalculator();
    3030
     
    6464    }
    6565
    66     // IDeepCloneable members
    67     public object Clone() {
    68       var cloner = new Cloner();
     66    public override IDeepCloneable Clone(Cloner cloner) {
    6967      return new OnlinePearsonsRSquaredCalculator(this, cloner);
    70     }
    71 
    72     public IDeepCloneable Clone(Cloner cloner) {
    73       var clone = cloner.GetClone(this);
    74       if (clone == null) {
    75         clone = new OnlinePearsonsRSquaredCalculator(this, cloner);
    76         cloner.RegisterClonedObject(this, clone);
    77       }
    78       return clone;
    7968    }
    8069  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs

    r14330 r14399  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineTheilsUStatisticCalculator : IOnlineTimeSeriesCalculator, IDeepCloneable {
     27  public class OnlineTheilsUStatisticCalculator : DeepCloneable, IOnlineTimeSeriesCalculator {
    2828    private OnlineMeanAndVarianceCalculator squaredErrorMeanCalculator;
    2929    private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator;
     
    132132    }
    133133
    134     // IDeepCloneable members
    135     public object Clone() {
    136       var cloner = new Cloner();
     134    public override IDeepCloneable Clone(Cloner cloner) {
    137135      return new OnlineTheilsUStatisticCalculator(this, cloner);
    138     }
    139 
    140     public IDeepCloneable Clone(Cloner cloner) {
    141       var clone = cloner.GetClone(this);
    142       if (clone == null) {
    143         clone = new OnlineTheilsUStatisticCalculator(this, cloner);
    144         cloner.RegisterClonedObject(this, clone);
    145       }
    146       return clone;
    147136    }
    148137  }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs

    r14330 r14399  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis {
    28   public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator, IDeepCloneable {
     28  public class OnlineWeightedDirectionalSymmetryCalculator : DeepCloneable, IOnlineTimeSeriesCalculator {
    2929    private int n;
    3030    private double correctSum;
     
    4242    }
    4343
    44     protected OnlineWeightedDirectionalSymmetryCalculator(OnlineWeightedDirectionalSymmetryCalculator other, Cloner cloner = null) {
     44    protected OnlineWeightedDirectionalSymmetryCalculator(OnlineWeightedDirectionalSymmetryCalculator other, Cloner cloner) {
    4545      n = other.n;
    4646      correctSum = other.correctSum;
     
    126126    }
    127127
    128     // IDeepCloneable members
    129     public object Clone() {
    130       return new OnlineWeightedDirectionalSymmetryCalculator(this);
    131     }
    132 
    133     public IDeepCloneable Clone(Cloner cloner) {
    134       var clone = cloner.GetClone(this);
    135       if (clone == null) {
    136         clone = new OnlineWeightedDirectionalSymmetryCalculator(this);
    137         cloner.RegisterClonedObject(this, clone);
    138       }
    139       return clone;
     128    public override IDeepCloneable Clone(Cloner cloner) {
     129      return new OnlineWeightedDirectionalSymmetryCalculator(this, cloner);
    140130    }
    141131  }
  • branches/symbreg-factors-2650/HeuristicLab.Tests

  • branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/GrammarsTest.cs

    r14351 r14399  
    3030    [TestProperty("Time", "short")]
    3131    public void MinimumExpressionLengthTest() {
    32       var grammar = CreateAbstractGrammar();
    33 
    34       var prs = grammar.ProgramRootSymbol;
    35       var a = grammar.Symbols.First(s => s.Name == "<a>");
    36       var b = grammar.Symbols.First(s => s.Name == "<b>");
    37 
    38       Assert.AreEqual(4, grammar.GetMinimumExpressionLength(prs));
    39       Assert.AreEqual(4, grammar.GetMinimumExpressionLength(a));
    40       Assert.AreEqual(3, grammar.GetMinimumExpressionLength(b));
     32      {
     33        var grammar = CreateTestGrammar1();
     34
     35        var prs = grammar.ProgramRootSymbol;
     36        var ss = grammar.StartSymbol;
     37        var x = grammar.Symbols.First(s => s.Name == "<x>");
     38
     39        Assert.AreEqual(8, grammar.GetMinimumExpressionLength(prs));
     40        Assert.AreEqual(7, grammar.GetMinimumExpressionLength(ss));
     41        Assert.AreEqual(6, grammar.GetMinimumExpressionLength(x));
     42      }
     43
     44      {
     45        var grammar = CreateTestGrammar2();
     46
     47        var prs = grammar.ProgramRootSymbol;
     48        var ss = grammar.StartSymbol;
     49        var x = grammar.Symbols.First(s => s.Name == "<x>");
     50
     51        Assert.AreEqual(13, grammar.GetMinimumExpressionLength(prs));
     52        Assert.AreEqual(12, grammar.GetMinimumExpressionLength(ss));
     53        Assert.AreEqual(11, grammar.GetMinimumExpressionLength(x));
     54      }
     55
     56      {
     57        var grammar = CreateTestGrammar3();
     58        var prs = grammar.ProgramRootSymbol;
     59        var ss = grammar.StartSymbol;
     60        var x = grammar.Symbols.First(s => s.Name == "<x>");
     61        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(prs));
     62        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(ss));
     63        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(x));
     64      }
     65
     66      {
     67        var grammar = CreateTestGrammar4();
     68        var prs = grammar.ProgramRootSymbol;
     69        var ss = grammar.StartSymbol;
     70        var x = grammar.Symbols.First(s => s.Name == "<x>");
     71        var y = grammar.Symbols.First(s => s.Name == "<y>");
     72        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(prs));
     73        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(ss));
     74        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(x));
     75        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionLength(y));
     76      }
     77
     78      {
     79        var grammar = CreateTestGrammar5();
     80        var prs = grammar.ProgramRootSymbol;
     81        var ss = grammar.StartSymbol;
     82        var x = grammar.Symbols.First(s => s.Name == "<x>");
     83        var y = grammar.Symbols.First(s => s.Name == "<y>");
     84        Assert.AreEqual(5, grammar.GetMinimumExpressionLength(prs));
     85        Assert.AreEqual(4, grammar.GetMinimumExpressionLength(ss));
     86        Assert.AreEqual(3, grammar.GetMinimumExpressionLength(x));
     87        Assert.AreEqual(2, grammar.GetMinimumExpressionLength(y));
     88      }
     89
     90      {
     91        var grammar = CreateTestGrammar6();
     92        var prs = grammar.ProgramRootSymbol;
     93        var ss = grammar.StartSymbol;
     94        var x = grammar.Symbols.First(s => s.Name == "<x>");
     95        var s_ = grammar.Symbols.First(s => s.Name == "<s>");
     96        var a = grammar.Symbols.First(s => s.Name == "<a>");
     97        var b = grammar.Symbols.First(s => s.Name == "<b>");
     98        var c = grammar.Symbols.First(s => s.Name == "<c>");
     99        var d = grammar.Symbols.First(s => s.Name == "<d>");
     100        Assert.AreEqual(4, grammar.GetMinimumExpressionLength(prs));
     101        Assert.AreEqual(3, grammar.GetMinimumExpressionLength(ss));
     102        Assert.AreEqual(2, grammar.GetMinimumExpressionLength(x));
     103        Assert.AreEqual(5, grammar.GetMinimumExpressionLength(s_));
     104        Assert.AreEqual(4, grammar.GetMinimumExpressionLength(a));
     105        Assert.AreEqual(3, grammar.GetMinimumExpressionLength(b));
     106        Assert.AreEqual(4, grammar.GetMinimumExpressionLength(c));
     107        Assert.AreEqual(3, grammar.GetMinimumExpressionLength(d));
     108      }
    41109    }
    42110
     
    45113    [TestProperty("Time", "short")]
    46114    public void MinimumExpressionDepthTest() {
    47       var grammar = CreateAbstractGrammar();
    48 
    49       var prs = grammar.ProgramRootSymbol;
    50       var a = grammar.Symbols.First(s => s.Name == "<a>");
    51       var b = grammar.Symbols.First(s => s.Name == "<b>");
    52 
    53       Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(prs));
    54       Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(a));
    55       Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(b));
    56     }
    57 
    58     private static ISymbolicExpressionGrammar CreateAbstractGrammar() {
     115      {
     116        var grammar = CreateTestGrammar1();
     117
     118        var prs = grammar.ProgramRootSymbol;
     119        var ss = grammar.StartSymbol;
     120        var a = grammar.Symbols.First(s => s.Name == "<a>");
     121        var b = grammar.Symbols.First(s => s.Name == "<b>");
     122        var c = grammar.Symbols.First(s => s.Name == "<c>");
     123        var d = grammar.Symbols.First(s => s.Name == "<d>");
     124        var x = grammar.Symbols.First(s => s.Name == "x");
     125        var y = grammar.Symbols.First(s => s.Name == "y");
     126
     127        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(prs));
     128        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(ss));
     129        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(a));
     130        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(b));
     131        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(c));
     132        Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(d));
     133        Assert.AreEqual(1, grammar.GetMinimumExpressionDepth(x));
     134        Assert.AreEqual(1, grammar.GetMinimumExpressionDepth(y));
     135      }
     136
     137      {
     138        var grammar = CreateTestGrammar2();
     139
     140        var prs = grammar.ProgramRootSymbol;
     141        var ss = grammar.StartSymbol;
     142        var a = grammar.Symbols.First(s => s.Name == "<a>");
     143        var b = grammar.Symbols.First(s => s.Name == "<b>");
     144        var c = grammar.Symbols.First(s => s.Name == "<c>");
     145        var d = grammar.Symbols.First(s => s.Name == "<d>");
     146        var x = grammar.Symbols.First(s => s.Name == "x");
     147        var y = grammar.Symbols.First(s => s.Name == "y");
     148
     149        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(prs));
     150        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(ss));
     151        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(a));
     152        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(b));
     153        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(c));
     154        Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(d));
     155        Assert.AreEqual(1, grammar.GetMinimumExpressionDepth(x));
     156        Assert.AreEqual(1, grammar.GetMinimumExpressionDepth(y));
     157      }
     158
     159      {
     160        var grammar = CreateTestGrammar3();
     161        var prs = grammar.ProgramRootSymbol;
     162        var ss = grammar.StartSymbol;
     163        var x = grammar.Symbols.First(s => s.Name == "<x>");
     164        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(prs));
     165        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(ss));
     166        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(x));
     167      }
     168
     169      {
     170        var grammar = CreateTestGrammar4();
     171        var prs = grammar.ProgramRootSymbol;
     172        var ss = grammar.StartSymbol;
     173        var x = grammar.Symbols.First(s => s.Name == "<x>");
     174        var y = grammar.Symbols.First(s => s.Name == "<y>");
     175        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(prs));
     176        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(ss));
     177        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(x));
     178        Assert.AreEqual(int.MaxValue, grammar.GetMinimumExpressionDepth(y));
     179      }
     180
     181      {
     182        var grammar = CreateTestGrammar5();
     183        var prs = grammar.ProgramRootSymbol;
     184        var ss = grammar.StartSymbol;
     185        var x = grammar.Symbols.First(s => s.Name == "<x>");
     186        var y = grammar.Symbols.First(s => s.Name == "<y>");
     187        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(prs));
     188        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(ss));
     189        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(x));
     190        Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(y));
     191      }
     192
     193      {
     194        var grammar = CreateTestGrammar6();
     195        var prs = grammar.ProgramRootSymbol;
     196        var ss = grammar.StartSymbol;
     197        var x = grammar.Symbols.First(s => s.Name == "<x>");
     198        var s_ = grammar.Symbols.First(s => s.Name == "<s>");
     199        var a = grammar.Symbols.First(s => s.Name == "<a>");
     200        var b = grammar.Symbols.First(s => s.Name == "<b>");
     201        var c = grammar.Symbols.First(s => s.Name == "<c>");
     202        var d = grammar.Symbols.First(s => s.Name == "<d>");
     203        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(prs));
     204        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(ss));
     205        Assert.AreEqual(2, grammar.GetMinimumExpressionDepth(x));
     206        Assert.AreEqual(5, grammar.GetMinimumExpressionDepth(s_));
     207        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(a));
     208        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(b));
     209        Assert.AreEqual(4, grammar.GetMinimumExpressionDepth(c));
     210        Assert.AreEqual(3, grammar.GetMinimumExpressionDepth(d));
     211      }
     212    }
     213
     214    private static ISymbolicExpressionGrammar CreateTestGrammar1() {
     215      var grammar = new SimpleSymbolicExpressionGrammar();
     216      var x = new SimpleSymbol("<x>", 1);
     217      var z = new SimpleSymbol("<z>", 6);
     218      var a = new SimpleSymbol("<a>", 1);
     219      var b = new SimpleSymbol("<b>", 1);
     220      var c = new SimpleSymbol("<c>", 1);
     221      var d = new SimpleSymbol("<d>", 1);
     222
     223      var _x = new SimpleSymbol("x", 0);
     224      var _y = new SimpleSymbol("y", 0);
     225
     226      grammar.AddSymbol(x);
     227      grammar.AddSymbol(z);
     228      grammar.AddSymbol(a);
     229      grammar.AddSymbol(b);
     230      grammar.AddSymbol(c);
     231      grammar.AddSymbol(d);
     232      grammar.AddSymbol(_x);
     233      grammar.AddSymbol(_y);
     234
     235      grammar.AddAllowedChildSymbol(grammar.StartSymbol, x);
     236      //uncommenting the line below changes the minimum expression length for the symbol <x>
     237      grammar.AddAllowedChildSymbol(x, z);
     238      grammar.AddAllowedChildSymbol(z, _x);
     239      grammar.AddAllowedChildSymbol(x, a);
     240      grammar.AddAllowedChildSymbol(a, b);
     241      grammar.AddAllowedChildSymbol(b, c);
     242      grammar.AddAllowedChildSymbol(c, d);
     243      grammar.AddAllowedChildSymbol(d, _y);
     244
     245      return grammar;
     246    }
     247
     248    private static ISymbolicExpressionGrammar CreateTestGrammar2() {
     249      var grammar = new SimpleSymbolicExpressionGrammar();
     250      var x = new SimpleSymbol("<x>", 2);
     251      var z = new SimpleSymbol("<z>", 6);
     252      var a = new SimpleSymbol("<a>", 1);
     253      var b = new SimpleSymbol("<b>", 1);
     254      var c = new SimpleSymbol("<c>", 1);
     255      var d = new SimpleSymbol("<d>", 1);
     256
     257      var _x = new SimpleSymbol("x", 0);
     258      var _y = new SimpleSymbol("y", 0);
     259
     260      grammar.AddSymbol(x);
     261      grammar.AddSymbol(z);
     262      grammar.AddSymbol(a);
     263      grammar.AddSymbol(b);
     264      grammar.AddSymbol(c);
     265      grammar.AddSymbol(d);
     266      grammar.AddSymbol(_x);
     267      grammar.AddSymbol(_y);
     268
     269      grammar.AddAllowedChildSymbol(grammar.StartSymbol, x);
     270      //uncommenting the line below changes the minimum expression length for the symbol <x>
     271      grammar.AddAllowedChildSymbol(x, z);
     272      grammar.AddAllowedChildSymbol(z, _x);
     273      grammar.AddAllowedChildSymbol(x, a);
     274      grammar.AddAllowedChildSymbol(a, b);
     275      grammar.AddAllowedChildSymbol(b, c);
     276      grammar.AddAllowedChildSymbol(c, d);
     277      grammar.AddAllowedChildSymbol(d, _y);
     278
     279      return grammar;
     280    }
     281
     282    private static ISymbolicExpressionGrammar CreateTestGrammar3() {
     283      var grammar = new SimpleSymbolicExpressionGrammar();
     284      var x = new SimpleSymbol("<x>", 1);
     285
     286      grammar.AddSymbol(x);
     287
     288      grammar.AddAllowedChildSymbol(grammar.StartSymbol, x);
     289      grammar.AddAllowedChildSymbol(x, x);
     290      return grammar;
     291    }
     292
     293
     294    private static ISymbolicExpressionGrammar CreateTestGrammar4() {
     295      var grammar = new SimpleSymbolicExpressionGrammar();
     296      var x = new SimpleSymbol("<x>", 1);
     297      var y = new SimpleSymbol("<y>", 1);
     298
     299      grammar.AddSymbol(x);
     300      grammar.AddSymbol(y);
     301
     302      grammar.AddAllowedChildSymbol(grammar.StartSymbol, x);
     303      grammar.AddAllowedChildSymbol(x, x);
     304      grammar.AddAllowedChildSymbol(x, y);
     305      grammar.AddAllowedChildSymbol(y, x);
     306      grammar.AddAllowedChildSymbol(y, y);
     307      return grammar;
     308    }
     309
     310    private static ISymbolicExpressionGrammar CreateTestGrammar5() {
     311      var grammar = new SimpleSymbolicExpressionGrammar();
     312      var x = new SimpleSymbol("<x>", 1);
     313      var y = new SimpleSymbol("<y>", 1);
     314      var _x = new SimpleSymbol("x", 0);
     315
     316      grammar.AddSymbol(x);
     317      grammar.AddSymbol(y);
     318      grammar.AddSymbol(_x);
     319
     320      grammar.AddAllowedChildSymbol(grammar.StartSymbol, x);
     321      grammar.AddAllowedChildSymbol(x, x);
     322      grammar.AddAllowedChildSymbol(x, y);
     323      grammar.AddAllowedChildSymbol(y, x);
     324      grammar.AddAllowedChildSymbol(y, y);
     325      grammar.AddAllowedChildSymbol(y, _x);
     326      return grammar;
     327    }
     328
     329    private static ISymbolicExpressionGrammar CreateTestGrammar6() {
    59330      var grammar = new SimpleSymbolicExpressionGrammar();
    60331      var x = new SimpleSymbol("<x>", 1);
  • branches/symbreg-factors-2650/HeuristicLab.Visualization.ChartControlsExtensions/3.3/EnhancedChart.cs

    r14185 r14399  
    2828namespace HeuristicLab.Visualization.ChartControlsExtensions {
    2929  public partial class EnhancedChart : Chart {
     30
    3031    private ImageExportDialog exportDialog;
     32
     33    private ImageExportDialog ExportDialog {
     34      get { return exportDialog ?? (exportDialog = new ImageExportDialog(this)); }
     35    }
    3136
    3237    public EnhancedChart()
    3338      : base() {
    3439      InitializeComponent();
    35       exportDialog = new ImageExportDialog(this);
    3640      EnableDoubleClickResetsZoom = true;
    3741      EnableMiddleClickPanning = true;
     
    166170
    167171    private void exportToolStripMenuItem_Click(object sender, EventArgs e) {
    168       exportDialog.ShowDialog();
     172      ExportDialog.ShowDialog();
    169173    }
    170174
Note: See TracChangeset for help on using the changeset viewer.