Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/11 13:54:57 (13 years ago)
Author:
spimming
Message:

#1680:

  • merged changes from trunk into branch

' removed pre-build event for multiple app.configs

Location:
branches/HeuristicLab.Hive.Azure
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure

  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs

    r5809 r7215  
    4343    private const string MaxTreeLengthParameterName = "Maximal symbolic expression tree length";
    4444    private const string ResultsParameterName = "Results";
     45
     46    public bool EnabledByDefault {
     47      get { return true; }
     48    }
    4549
    4650    #region parameter properties
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs

    r6803 r7215  
    5959    #endregion
    6060    #region properties
     61    public virtual bool EnabledByDefault {
     62      get { return true; }
     63    }
    6164    public BoolValue AggregrateSymbolsWithDifferentSubtreeCount {
    6265      get { return AggregateSymbolsWithDifferentSubtreeCountParameter.Value; }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r6978 r7215  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Analysis;
     
    5251    }
    5352    public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
    54       get {
    55         return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName];
    56       }
     53      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; }
    5754    }
    5855    public ValueLookupParameter<DataTableHistory> SymbolicExpressionTreeLengthsHistoryParameter {
    59       get {
    60         return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName];
    61       }
     56      get { return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; }
    6257    }
    6358    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    7166      get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
    7267    }
    73     public LookupParameter<IntValue> UpdateCounterParameter {
    74       get { return (LookupParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
     68    public ValueParameter<IntValue> UpdateCounterParameter {
     69      get { return (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
    7570    }
    7671    #endregion
     72
     73    #region Properties
     74    public bool EnabledByDefault {
     75      get { return true; }
     76    }
     77    public IntValue UpdateInterval {
     78      get { return UpdateIntervalParameter.Value; }
     79    }
     80    public IntValue UpdateCounter {
     81      get { return UpdateCounterParameter.Value; }
     82    }
     83    public BoolValue StoreHistory {
     84      get { return StoreHistoryParameter.Value; }
     85    }
     86    #endregion
     87
    7788    [StorableConstructor]
    7889    private SymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { }
     
    91102      Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history."));
    92103      Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    93 
    94       #region Add parameters for history
    95104      Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false)));
    96105      Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    97       Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
    98       #endregion
    99 
    100       UpdateCounterParameter.Hidden = true;
     106      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
    101107
    102108      AfterDeserialization();
     
    112118        Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    113119      }
    114       if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
    115         Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
    116       }
     120      if (Parameters.ContainsKey(UpdateCounterParameterName))
     121        Parameters.Remove(UpdateCounterParameterName);
     122      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
     123
     124      SymbolicExpressionTreeLengthsParameter.Hidden = true;
     125      SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true;
     126      ResultsParameter.Hidden = true;
     127      UpdateCounterParameter.Hidden = true;
    117128    }
    118129
    119130    public override IOperation Apply() {
    120       int updateInterval = UpdateIntervalParameter.Value.Value;
    121       IntValue updateCounter = UpdateCounterParameter.ActualValue;
    122       // if the counter doesn't exist yet, we initialize it here with the current update interval
    123       if (updateCounter == null) {
    124         updateCounter = new IntValue(updateInterval);
    125         UpdateCounterParameter.ActualValue = updateCounter;
    126       } else updateCounter.Value++;
    127 
     131      UpdateCounter.Value++;
    128132      // the analyzer runs periodically, every 'updateInterval' times
    129       if (updateCounter.Value == updateInterval) {
    130         updateCounter.Value = 0; // reset counter
     133      if (UpdateCounter.Value == UpdateInterval.Value) {
     134        UpdateCounter.Value = 0; // reset counter
    131135
    132136        // compute all tree lengths and store them in the lengthsTable
     
    136140        // if the table was not created yet, we create it here
    137141        if (treeLengthsTable == null) {
    138           treeLengthsTable = new DataTable("Tree Length Values");
     142          treeLengthsTable = new DataTable("Histogram");
    139143          SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable;
    140144        }
    141145
    142146        // data table which stores tree length values
    143         DataRow dataRow;
    144 
    145         var treeLengths = solutions.Select(s => (double)s.Length);
    146 
    147         if (!treeLengthsTable.Rows.ContainsKey("Tree Lengths")) {
    148           dataRow = new DataRow("Tree Lengths", "", treeLengths);
    149           treeLengthsTable.Rows.Add(dataRow);
     147        DataRow treeLengthsTableRow;
     148
     149        const string treeLengthsTableRowName = "Symbolic expression tree lengths";
     150        const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths";
     151        const string xAxisTitle = "Symbolic expression tree lengths";
     152        const string yAxisTitle = "Frequency / Number of tree individuals";
     153
     154        var treeLengths = solutions.Select(s => (int)s.Length).ToList();
     155
     156        int maxLength = treeLengths.Max(t => t);
     157        int minLength = treeLengths.Min(t => t);
     158
     159        if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) {
     160          treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x));
     161          treeLengthsTable.Rows.Add(treeLengthsTableRow);
    150162        } else {
    151           dataRow = treeLengthsTable.Rows["Tree Lengths"];
    152           dataRow.Values.Replace(treeLengths);
     163          treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName];
     164          treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x));
    153165        }
    154166
    155167        double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value;
    156168
    157         dataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    158         dataRow.VisualProperties.ExactBins = false;
    159 
    160         // the following trick should result in an intervalWidth of 1,2,4,... (an int value)
    161         dataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length);
    162 
    163         int maxLength = solutions.Max(s => s.Length);
    164         if (maxLength <= 25)      // [0,25]
    165           dataRow.VisualProperties.ScaleFactor = 1.0;
    166         else if (maxLength <= 100) // [26,100])
    167           dataRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
    168         else if (maxLength <= 250) // [100,250]
    169           dataRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
     169        treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
     170        treeLengthsTableRow.VisualProperties.ExactBins = false;
     171
     172        int range = maxLength - minLength;
     173        if (range == 0) range = 1;
     174        // the following trick should result in an integer intervalWidth of 1,2,4,...
     175        treeLengthsTableRow.VisualProperties.Bins = range;
     176
     177        if (maxLength <= 25) // [0,25]
     178          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0;
     179        else if (maxLength <= 100) // [26,100]
     180          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
     181        else if (maxLength <= 250) // [101,250]
     182          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
    170183        else if (maxLength <= 500) // [251,500]
    171           dataRow.VisualProperties.ScaleFactor = 1.0 / 10.0;
     184          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0;
    172185        else
    173           dataRow.VisualProperties.ScaleFactor = 1.0 / 20.0;   // [501,inf]
     186          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf]
     187
     188        treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false;
    174189
    175190        // visual properties for the X-axis
     
    178193        treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
    179194        if (maxLength > maximumAllowedTreeLength + 1)
    180           treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = solutions.Max(s => s.Length) + 1; // +1 so the histogram column for the maximum length won't get trimmed
     195          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
    181196        else
    182197          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
    183         // visual properties for the Y-axis
     198        treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle;
     199        //visual properties for the Y-axis
    184200        treeLengthsTable.VisualProperties.YAxisMinimumAuto = false;
    185201        treeLengthsTable.VisualProperties.YAxisMaximumAuto = false;
    186202        treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    187         treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     203        int maxFreq = solutions.GroupBy(s => s.Length).Max(g => g.Count());
     204        if (maxFreq % 5 != 0)
     205          maxFreq += (5 - maxFreq % 5);
     206        double yAxisMaximumFixedValue = maxFreq;
     207
     208        treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
     209        treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle;
    188210
    189211        var results = ResultsParameter.ActualValue;
    190212
    191         if (!results.ContainsKey("Tree Lengths")) {
    192           results.Add(new Result("Tree Lengths", treeLengthsTable));
     213        if (!results.ContainsKey(treeLengthsTableRowName)) {
     214          results.Add(new Result(treeLengthsTableRowName, treeLengthsTable));
    193215        } else {
    194           results["Tree Lengths"].Value = treeLengthsTable;
     216          results[treeLengthsTableRowName].Value = treeLengthsTable;
    195217        }
    196218
    197219        bool storeHistory = StoreHistoryParameter.Value.Value;
     220        const string treeLengthHistoryTableName = "Tree lengths history";
    198221
    199222        if (storeHistory) {
    200223          // store tree lengths for each generation
    201           var historyDataRow = new DataRow("Tree Lengths " + results["Generations"].Value, "", dataRow.Values);
     224          var historyDataRow = new DataRow("Tree lengths", "", treeLengthsTableRow.Values);
    202225          historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    203226          historyDataRow.VisualProperties.ExactBins = false;
    204           historyDataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length);
    205           historyDataRow.VisualProperties.ScaleFactor = dataRow.VisualProperties.ScaleFactor;
    206           var historyTable = new DataTable("Lengths Table " + results["Generations"]);
     227          historyDataRow.VisualProperties.Bins = range;
     228          historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor;
     229          historyDataRow.VisualProperties.IsVisibleInLegend = false;
     230          var historyTable = new DataTable("Tree lengths");
    207231          historyTable.Rows.Add(historyDataRow);
    208232          // visual properties for the X-axis
     
    210234          historyTable.VisualProperties.XAxisMaximumAuto = false;
    211235          historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
    212           if (solutions.Max(s => s.Length) > maximumAllowedTreeLength + 1)
     236          if (maxLength > maximumAllowedTreeLength + 1)
    213237            historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
    214238          else
    215239            historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
     240          historyTable.VisualProperties.XAxisTitle = xAxisTitle;
    216241          // visual properties for the Y-axis
    217242          historyTable.VisualProperties.YAxisMinimumAuto = false;
    218243          historyTable.VisualProperties.YAxisMaximumAuto = false;
    219244          historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    220           historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     245          historyTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
     246          historyTable.VisualProperties.YAxisTitle = yAxisTitle;
    221247
    222248          var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue;
     
    228254          treeLengthsHistory.Add(historyTable);
    229255
    230           if (!results.ContainsKey("Tree Lengths History")) {
    231             results.Add(new Result("Tree Lengths History", treeLengthsHistory));
     256          if (!results.ContainsKey(treeLengthHistoryTableName)) {
     257            results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory));
    232258          } else {
    233             results["Tree Lengths History"].Value = treeLengthsHistory;
     259            results[treeLengthHistoryTableName].Value = treeLengthsHistory;
    234260          }
    235261        }
    236262      }
    237 
    238263      return base.Apply();
    239264    }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs

    r6929 r7215  
    9898      List<ISymbolicExpressionTreeManipulator> list = new List<ISymbolicExpressionTreeManipulator>();
    9999      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicExpressionTreeManipulator))) {
    100         if (!typeof(IMultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type))
    101           list.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type));
     100        if (this.GetType().Assembly != type.Assembly) continue;
     101        if (typeof(IMultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type)) continue;
     102        list.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type));
    102103      }
    103104      CheckedItemList<ISymbolicExpressionTreeManipulator> checkedItemList = new CheckedItemList<ISymbolicExpressionTreeManipulator>();
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r6944 r7215  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32  [NonDiscoverableType]
    3133  [StorableClass]
    3234  [Item("FullTreeCreator", "An operator that creates new symbolic expression trees using the 'Full' method")]
     
    6062    public IntValue MaximumSymbolicExpressionTreeDepth {
    6163      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65
     66    public IntValue MaximumSymbolicExpressionTreeLength {
     67      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    6268    }
    6369
     
    97103
    98104    protected override ISymbolicExpressionTree Create(IRandom random) {
    99       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     105      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     106    }
     107
     108    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     109      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    100110    }
    101111
     
    108118    /// <param name="grammar">Available tree grammar</param>
    109119    /// <param name="maxTreeDepth">Maximum tree depth</param>
     120    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    110121    /// <returns></returns>
    111     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     122    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    112123      var tree = new SymbolicExpressionTree();
    113124      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     
    137148        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");
    138149
     150      var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0).ToList();
     151
    139152      for (var i = 0; i != arity; ++i) {
    140         var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol,i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);
     153        var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList();
    141154        var selectedSymbol = possibleSymbols.SelectRandom(random);
    142155        var tree = selectedSymbol.CreateTreeNode();
     
    147160      // Only iterate over the non-terminal nodes (those which have arity > 0)
    148161      // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode
    149       foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0))
     162      foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0))
    150163        RecursiveGrowFull(random, subTree, 2, maxDepth);
    151164    }
     
    157170        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    158171
     172      var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList(); ;
    159173
    160174      for (var i = 0; i != arity; ++i) {
    161         var possibleSymbols = currentDepth < maxDepth ?
    162           root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0) :
    163           root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0);
     175        var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) &&
     176                                                   root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth &&
     177                                                   root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth).ToList();
     178        if (!possibleSymbols.Any())
     179          throw new InvalidOperationException("No symbols are available for the tree.");
     180
    164181        var selectedSymbol = possibleSymbols.SelectRandom(random);
    165182        var tree = selectedSymbol.CreateTreeNode();
     
    168185      }
    169186
    170       foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0))
     187      foreach (var subTree in root.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0))
    171188        RecursiveGrowFull(random, subTree, currentDepth + 1, maxDepth);
    172189    }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r6944 r7215  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32  [NonDiscoverableType]
    3133  [StorableClass]
    3234  [Item("GrowTreeCreator", "An operator that creates new symbolic expression trees using the 'Grow' method")]
     
    6062    public IntValue MaximumSymbolicExpressionTreeDepth {
    6163      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65
     66    public IntValue MaximumSymbolicExpressionTreeLength {
     67      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    6268    }
    6369
     
    97103
    98104    protected override ISymbolicExpressionTree Create(IRandom random) {
    99       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     105      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     106    }
     107
     108    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     109      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    100110    }
    101111
     
    107117    /// <param name="grammar">Available tree grammar</param>
    108118    /// <param name="maxTreeDepth">Maximum tree depth</param>
     119    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    109120    /// <returns></returns>
    110     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     121    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    111122      var tree = new SymbolicExpressionTree();
    112123      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     
    135146        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");
    136147
     148      var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    137149
    138150      for (var i = 0; i != arity; ++i) {
    139         var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0);
     151        var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList();
    140152        var selectedSymbol = possibleSymbols.SelectRandom(random);
    141153        var tree = selectedSymbol.CreateTreeNode();
     
    146158      // Only iterate over the non-terminal nodes (those which have arity > 0)
    147159      // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode
    148       foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0))
     160      foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0))
    149161        RecursiveGrow(random, subTree, 2, maxDepth);
    150162    }
     
    155167        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    156168
     169      var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    157170
    158171      for (var i = 0; i != arity; ++i) {
    159         var possibleSymbols = currentDepth < maxDepth
    160                                 ? root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0)
    161                                 : root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(
    162                                   s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0);
     172        var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) && root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth).ToList();
     173        if (!possibleSymbols.Any())
     174          throw new InvalidOperationException("No symbols are available for the tree.");
    163175        var selectedSymbol = possibleSymbols.SelectRandom(random);
    164176        var tree = selectedSymbol.CreateTreeNode();
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6911 r7215  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.PluginInfrastructure;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     33  [NonDiscoverableType]
    3234  [StorableClass]
    3335  [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed length")]
     
    101103    }
    102104
    103     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar,
    104       int maxTreeLength, int maxTreeDepth) {
     105    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     106      return Create(random, grammar, maxTreeLength, maxTreeDepth);
     107    }
     108
     109    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    105110      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    106111      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r6887 r7215  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.PluginInfrastructure;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     34  [NonDiscoverableType]
    3335  [StorableClass]
    3436  [Item("RampedHalfAndHalfTreeCreator", "An operator that creates new symbolic expression trees in an alternate way: half the trees are created usign the 'Grow' method while the other half are created using the 'Full' method")]
     
    7274    }
    7375
     76    public IntValue MaximumSymbolicExpressionTreeLength {
     77      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
     78    }
     79
    7480    public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar {
    7581      get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; }
     
    106112
    107113    protected override ISymbolicExpressionTree Create(IRandom random) {
    108       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     114      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     115    }
     116
     117    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     118      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    109119    }
    110120
     
    117127    /// <param name="maxTreeDepth">Maximum tree depth</param>
    118128    /// <returns></returns>
    119     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     129    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    120130      var tree = new SymbolicExpressionTree();
    121131      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r6233 r7215  
    3939    #endregion
    4040
    41     #region Propeties
     41    #region Properties
    4242    public ISymbolicExpressionTree SymbolicExpressionTree {
    4343      get { return SymbolicExpressionTreeParameter.ActualValue; }
     
    6060
    6161    protected abstract ISymbolicExpressionTree Create(IRandom random);
     62    public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    6263  }
    6364}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammarBase.cs

    r6911 r7215  
    4040
    4141    int GetMinimumExpressionDepth(ISymbol start);
     42    int GetMaximumExpressionDepth(ISymbol start);
    4243    int GetMinimumExpressionLength(ISymbol start);
    4344    int GetMaximumExpressionLength(ISymbol start, int maxDepth);
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCreator.cs

    r5809 r7215  
    2929  public interface ISymbolicExpressionTreeCreator : ISymbolicExpressionTreeOperator, ISolutionCreator {
    3030    ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { get; }
     31    ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth);
    3132  }
    3233}
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/MultiSymbolicExpressionTreeManipulator.cs

    r6929 r7215  
    7474      List<ISymbolicExpressionTreeManipulator> list = new List<ISymbolicExpressionTreeManipulator>();
    7575      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicExpressionTreeManipulator))) {
    76         if (!typeof(IMultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type) &&
    77             !typeof(ISymbolicExpressionTreeArchitectureAlteringOperator).IsAssignableFrom(type))
    78           list.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type));
     76        if (this.GetType().Assembly != type.Assembly) continue;
     77        if (typeof(IMultiOperator<ISymbolicExpressionTreeManipulator>).IsAssignableFrom(type)) continue;
     78        if (typeof(ISymbolicExpressionTreeArchitectureAlteringOperator).IsAssignableFrom(type)) continue;
     79        list.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type));
    7980      }
    8081      CheckedItemList<ISymbolicExpressionTreeManipulator> checkedItemList = new CheckedItemList<ISymbolicExpressionTreeManipulator>();
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6911 r7215  
    8282      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    8383      cachedMinExpressionDepth = new Dictionary<string, int>();
     84      cachedMaxExpressionDepth = new Dictionary<string, int>();
    8485
    8586      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    9495      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    9596      cachedMinExpressionDepth = new Dictionary<string, int>();
     97      cachedMaxExpressionDepth = new Dictionary<string, int>();
    9698
    9799      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    117119      cachedMaxExpressionLength = new Dictionary<Tuple<string, int>, int>();
    118120      cachedMinExpressionDepth = new Dictionary<string, int>();
     121      cachedMaxExpressionDepth = new Dictionary<string, int>();
    119122
    120123      cachedIsAllowedChildSymbol = new Dictionary<Tuple<string, string>, bool>();
     
    134137      foreach (var s in symbol.Flatten()) {
    135138        symbols.Add(s.Name, s);
    136         symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, s.MaximumArity));
     139        int maxSubTreeCount = Math.Min(s.MinimumArity + 1, s.MaximumArity);
     140        symbolSubtreeCount.Add(s.Name, Tuple.Create(s.MinimumArity, maxSubTreeCount));
    137141      }
    138142      ClearCaches();
     
    371375      cachedMaxExpressionLength.Clear();
    372376      cachedMinExpressionDepth.Clear();
     377      cachedMaxExpressionDepth.Clear();
    373378
    374379      cachedIsAllowedChildSymbol.Clear();
     
    427432    }
    428433
     434    private readonly Dictionary<string, int> cachedMaxExpressionDepth;
     435    public int GetMaximumExpressionDepth(ISymbol symbol) {
     436      int temp;
     437      if (!cachedMaxExpressionDepth.TryGetValue(symbol.Name, out temp)) {
     438        cachedMaxExpressionDepth[symbol.Name] = int.MaxValue;
     439        long maxDepth = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol))
     440                             let maxForSlot = (long)(from s in GetAllowedChildSymbols(symbol, argIndex)
     441                                                     where s.InitialFrequency > 0.0
     442                                                     select GetMaximumExpressionDepth(s)).DefaultIfEmpty(0).Max()
     443                             select maxForSlot).DefaultIfEmpty(0).Max();
     444        cachedMaxExpressionDepth[symbol.Name] = (int)Math.Min(maxDepth, int.MaxValue);
     445        return cachedMaxExpressionDepth[symbol.Name];
     446      }
     447      return temp;
     448    }
     449
    429450    public event EventHandler Changed;
    430451    protected virtual void OnChanged() {
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs

    r6911 r7215  
    119119      else return base.GetMinimumExpressionDepth(symbol);
    120120    }
     121    int ISymbolicExpressionGrammarBase.GetMaximumExpressionDepth(ISymbol symbol) {
     122      if (symbols.Count == 0) return grammar.GetMaximumExpressionDepth(symbol);
     123      else return base.GetMaximumExpressionDepth(symbol);
     124    }
    121125    int ISymbolicExpressionGrammarBase.GetMinimumExpressionLength(ISymbol symbol) {
    122126      if (symbols.Count == 0) return grammar.GetMinimumExpressionLength(symbol);
     
    127131      else return base.GetMaximumExpressionLength(symbol, maxDepth);
    128132    }
     133
    129134  }
    130135}
Note: See TracChangeset for help on using the changeset viewer.