Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/12/15 20:40:11 (10 years ago)
Author:
gkronber
Message:

#2283: added shuffling of terminal symbols to the royal pair problem to make sure that there is no bias from order of terminal symbols.

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs

    r12294 r12391  
    175175    }
    176176
    177     public Sequence CompleteSentenceRandomly(Random random, Sequence phrase, int maxLen) {
     177    public Sequence CompleteSentenceRandomly(System.Random random, Sequence phrase, int maxLen) {
    178178      if (phrase.Length > maxLen) throw new ArgumentException();
    179179      if (MinPhraseLength(phrase) > maxLen) throw new ArgumentException();
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.csproj

    r12290 r12391  
    4646      <HintPath>..\HeuristicLab\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
    4747    </Reference>
     48    <Reference Include="HeuristicLab.Random-3.3">
     49      <HintPath>..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath>
     50    </Reference>
    4851    <Reference Include="System" />
    4952    <Reference Include="System.Core" />
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Interfaces/IGrammar.cs

    r11848 r12391  
    2020    int MinPhraseLength(Sequence phrase);
    2121    int MaxPhraseLength(Sequence phrase);
    22     Sequence CompleteSentenceRandomly(Random random, Sequence phrase, int maxLen);
     22    Sequence CompleteSentenceRandomly(System.Random random, Sequence phrase, int maxLen);
    2323
    2424    bool IsTerminal(char symbol);
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/FindPhrasesProblem.cs

    r12290 r12391  
    2929    private readonly double decoyReward;
    3030    private readonly bool phrasesAsSets;
     31    private readonly int alphabetSize;
     32    private readonly int numOptimalPhrases;
     33    private readonly int numDecoyPhrases;
    3134    private readonly SortedSet<string> optimalPhrases;
    3235    private readonly SortedSet<string> decoyPhrases;
    33     public string Name { get { return "FindPhrases"; } }
     36    public string Name { get { return string.Format("FindPhrases({0},{1},{2},{3},{4},{5},{6},{7})", alphabetSize, numPhrases, phraseLen, numOptimalPhrases, numDecoyPhrases, correctReward, decoyReward, phrasesAsSets); } }
    3437
    35     public FindPhrasesProblem(Random rand, int alphabetSize, int numPhrases, int phraseLen, int numOptimalPhrases, int numDecoyPhrases = 1,
     38    public FindPhrasesProblem(System.Random rand, int alphabetSize, int numPhrases, int phraseLen, int numOptimalPhrases, int numDecoyPhrases = 1,
    3639      double correctReward = 1.0, double decoyReward = 0.0, bool phrasesAsSets = false) {
    3740      if (alphabetSize <= 0 || alphabetSize > 26) throw new ArgumentException();
     
    4750      this.decoyReward = decoyReward;
    4851      this.phrasesAsSets = phrasesAsSets;
     52      this.alphabetSize = alphabetSize;
     53      this.numOptimalPhrases = numOptimalPhrases;
     54      this.numDecoyPhrases = numDecoyPhrases;
    4955
    5056      var sentenceSymbol = 'S';
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/RoyalPairProblem.cs

    r12290 r12391  
    55using System.Text;
    66using System.Text.RegularExpressions;
     7using HeuristicLab.Common;
    78using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     9using HeuristicLab.Random;
    810
    911namespace HeuristicLab.Problems.GrammaticalOptimization {
     
    1315    private readonly IGrammar grammar;
    1416    private readonly int numTerminals;
    15     public string Name { get { return "RoyalPair"; } }
     17    public string Name { get { return string.Format("RoyalPair({0})", numTerminals); } }
    1618
    1719    public RoyalPairProblem(int numTerminals = 2) {
     
    1921
    2022      var sentenceSymbol = 'S';
    21       var terminalSymbols = Enumerable.Range(0, numTerminals).Select(off => (char)((byte)'a' + off)).ToArray();
     23      var terminalSymbols = Enumerable.Range(0, numTerminals).Select(off => (char)((byte)'a' + off)).ToList();
     24      terminalSymbols.ShuffleInPlace(new MersenneTwister(31415));
     25
    2226      var nonTerminalSymbols = new char[] { sentenceSymbol };
    2327
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/RoyalPhraseSequenceProblem.cs

    r12290 r12391  
    3333    private readonly SortedSet<string>[] optimalPhrasesForPos;
    3434    public string Name { get { return "RoyalPhraseSequence"; } }
    35     public RoyalPhraseSequenceProblem(Random rand, int alphabetSize, int sequenceLen, int phraseLen = 1, int numCorrectPhrases = 1, double correctReward = 1.0, double incorrectReward = 0.0, bool phrasesAsSets = false) {
     35    public RoyalPhraseSequenceProblem(System.Random rand, int alphabetSize, int sequenceLen, int phraseLen = 1, int numCorrectPhrases = 1, double correctReward = 1.0, double incorrectReward = 0.0, bool phrasesAsSets = false) {
    3636      if (alphabetSize <= 0 || alphabetSize > 26) throw new ArgumentException();
    3737      if (sequenceLen <= 0) throw new ArgumentException();
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/RoyalSequenceProblem.cs

    r12099 r12391  
    2424    private readonly SortedSet<char>[] optimalSymbolsForPos;
    2525    public string Name { get { return "RoyalSequence"; } }
    26     public RoyalSequenceProblem(Random rand, int alphabetSize, int sequenceLen, int k = 1, double correctReward = 1.0, double incorrectReward = 0.0) {
     26    public RoyalSequenceProblem(System.Random rand, int alphabetSize, int sequenceLen, int k = 1, double correctReward = 1.0, double incorrectReward = 0.0) {
    2727      if (alphabetSize <= 0 || alphabetSize > 26) throw new ArgumentException();
    2828      if (sequenceLen <= 0) throw new ArgumentException();
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/SymbolicRegressionPoly10Problem.cs

    r12298 r12391  
    7373    private void GenerateData() {
    7474      // generate data with fixed seed to make sure that data is always the same
    75       var rand = new Random(31415);
     75      var rand = new System.Random(31415);
    7676      for (int i = 0; i < N; i++) {
    7777        x[i] = new double[10];
Note: See TracChangeset for help on using the changeset viewer.