Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/05/10 18:53:37 (15 years ago)
Author:
gkronber
Message:

Changed PTC2 initialization operator for symbolic expression tree encoding to select symbols based on the number of tickets. #937 (Data types and operators for symbolic expression tree encoding)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3239 r3270  
    6161    private Symbol SelectRandomSymbol(IRandom random, IEnumerable<Symbol> symbols) {
    6262      var symbolList = symbols.ToList();
    63       return symbolList[random.Next(symbolList.Count)];
     63      var ticketsSum = symbolList.Select(x => x.Tickets.Value).Sum();
     64      var r = random.NextDouble() * ticketsSum;
     65      double aggregatedTickets = 0;
     66      for (int i = 0; i < symbolList.Count; i++) {
     67        aggregatedTickets += symbolList[i].Tickets.Value;
     68        if (aggregatedTickets >= r) {
     69          return symbolList[i];
     70        }
     71      }
     72      // this should never happen
     73      throw new ArgumentException();
    6474    }
    6575
Note: See TracChangeset for help on using the changeset viewer.