Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7961


Ignore:
Timestamp:
06/05/12 10:02:25 (12 years ago)
Author:
bburlacu
Message:

#1866: Fixed bug where initial frequencies of grammar symbols were not taken into account by the tree creators.

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r7259 r7961  
    161161          .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i))
    162162          .ToList();
    163         var selectedSymbol = possibleSymbols.SelectRandom(random);
     163        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     164        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
    164165        var tree = selectedSymbol.CreateTreeNode();
    165166        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    192193        if (!possibleSymbols.Any())
    193194          throw new InvalidOperationException("No symbols are available for the tree.");
    194 
     195        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
    195196        var selectedSymbol = possibleSymbols.SelectRandom(random);
    196197        var tree = selectedSymbol.CreateTreeNode();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r7259 r7961  
    160160          .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i))
    161161          .ToList();
    162         var selectedSymbol = possibleSymbols.SelectRandom(random);
     162        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     163        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
    163164        var tree = selectedSymbol.CreateTreeNode();
    164165        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    178179        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    179180
    180       var allowedSymbols = root.Grammar.AllowedSymbols
    181         .Where(s => s.InitialFrequency > 0.0)
    182         .ToList();
     181      var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    183182
    184183      for (var i = 0; i < arity; i++) {
     
    187186            root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth)
    188187          .ToList();
     188
    189189        if (!possibleSymbols.Any())
    190190          throw new InvalidOperationException("No symbols are available for the tree.");
    191         var selectedSymbol = possibleSymbols.SelectRandom(random);
     191        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     192        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
    192193        var tree = selectedSymbol.CreateTreeNode();
    193194        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
Note: See TracChangeset for help on using the changeset viewer.