Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15773


Ignore:
Timestamp:
02/13/18 18:32:20 (7 years ago)
Author:
lkammere
Message:

#2886: Update unit tests to cover problems with exp, log and sine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs

    r15746 r15773  
    5353
    5454
    55     #region test structure search (no constants)
    5655    [TestMethod]
    5756    [TestProperty("Goal", "structure search")]
     
    8786    }
    8887
    89     [TestMethod]
     88    // Too "large" target model for now...
     89    //[TestMethod]
    9090    [TestProperty("Goal", "structure search")]
    9191    public void MctsSymbReg_NoConstants_Nguyen2() {
    9292      // x^4 + x³ + x² + x
    93       alg.MaxTreeSize = 25;
     93      alg.MaxTreeSize = 20;
    9494      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    9595      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));
     
    9797
    9898      alg.Start();
    99 
    100       TerminalSymbol varSymbol = alg.Grammar.Var.VariableTerminalSymbols.First();
    101       TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
    102       TerminalSymbol addSymbol = alg.Grammar.Addition;
    103 
    104       SymbolString targetSolution = new SymbolString(new[] {
    105         varSymbol, varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, mulSymbol,
    106         varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, addSymbol,
    107         varSymbol, varSymbol, mulSymbol, addSymbol,
    108         varSymbol, addSymbol
    109       });
    110 
    111       int targetSolutionHash = alg.Grammar.CalcHashCode(targetSolution);
    112       int actualSolutionHash = alg.Grammar.CalcHashCode(alg.BestTrainingSentence);
    113 
    114       var targetSolutionStr = alg.Grammar.PostfixToInfixParser(targetSolution).ToString();
    115       var foundTargetSolutionStr = alg.Grammar.PostfixToInfixParser(alg.DistinctSentences[targetSolutionHash]).ToString();
    116       var actualSolutionStr = alg.Grammar.PostfixToInfixParser(alg.DistinctSentences[targetSolutionHash]).ToString();
    117 
    118       Assert.IsTrue(alg.DistinctSentences.ContainsKey(targetSolutionHash), "Target solution was not generated!");
    119 
    120       Assert.AreEqual(targetSolutionHash, actualSolutionHash, "Actual solution was not recognized as best one.");
    121 
    122       // Evaluate
    12399      EvaluateGrammarEnumeration();
    124100    }
    125101
    126     [TestMethod]
     102    // Too "large" target model for now...
     103    //[TestMethod]
     104    [TestProperty("Goal", "structure search")]
     105    public void MctsSymbReg_NoConstants_Nguyen3() {
     106      // x^5 + x^4 + x^3 + x^2 + x
     107      alg.MaxTreeSize = 32;
     108      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
     109      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
     110      alg.Problem.ProblemData = regProblem;
     111
     112      alg.Start();
     113
     114      EvaluateGrammarEnumeration();
     115    }
     116
     117    [TestMethod]                             
     118    [TestProperty("Goal", "structure search")]
     119    public void MctsSymbReg_NoConstants_Nguyen6() {
     120      // sin(x) + sin(x + x²)
     121      alg.MaxTreeSize = 15;
     122      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
     123      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
     124      alg.Problem.ProblemData = regProblem;
     125
     126      alg.Start();
     127      EvaluateGrammarEnumeration();
     128    }
     129
     130    [TestMethod]
     131    [TestProperty("Goal", "structure search")]
     132    public void MctsSymbReg_NoConstants_Nguyen9() {
     133      // sin(x) + sin(y²)
     134      alg.MaxTreeSize = 10;
     135      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
     136      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
     137      alg.Problem.ProblemData = regProblem;
     138
     139      alg.Start();
     140      EvaluateGrammarEnumeration();
     141    }
     142
     143    // Too much variables for now...
     144    //[TestMethod]
    127145    [TestProperty("Goal", "structure search")]
    128146    public void MctsSymbReg_NoConstants_Poly10() {
     
    133151
    134152      alg.Start();
    135 
    136       Assert.AreEqual(alg.DistinctSentences.Count(), 110);
    137 
    138       // Evaluate
    139       // EvaluateGrammarEnumeration();
    140     }
     153      EvaluateGrammarEnumeration();
     154    }
     155
     156
     157#if false
    141158
    142159    [TestMethod]
     
    149166
    150167      alg.Start();
    151 
    152       Assert.AreEqual(alg.DistinctSentences.Count(), 16);
    153 
    154       // Evaluate
    155       // EvaluateGrammarEnumeration();
    156     }
    157 
    158     /*  NEXT UP
    159     [TestMethod]
    160     [TestProperty("Goal", "structure search")]
    161     public void MctsSymbReg_NoConstants_Nguyen3() {
    162       // x^5 + x^4 + x³ + x² + x
    163       alg.MaxTreeSize = 25;
    164       var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    165       var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
    166       TestGrammarEnumeration(regProblem);
    167     }
    168     [TestMethod]
    169     [TestProperty("Goal", "structure search")]
    170     public void MctsSymbReg_NoConstants_Nguyen4() {
    171 
    172       // x^6 + x^5 + x^4 + x³ + x² + x
    173       alg.MaxTreeSize = 30;
    174       var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    175       var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));
    176       TestGrammarEnumeration(regProblem);
    177     } */
    178 
    179 
    180     #endregion
    181 
    182     #region TODO
    183 
    184 #if false
     168      EvaluateGrammarEnumeration();
     169    }
     170
     171
    185172    [TestMethod]
    186173    [TestCategory("Algorithms.DataAnalysis")]
     
    480467    }
    481468
    482     #region restricted structure but including numeric constants
    483 
    484469    [TestMethod]
    485470    [TestCategory("Algorithms.DataAnalysis")]
     
    576561    }
    577562
    578     #endregion
    579 
    580     #region keijzer
    581563    [TestMethod]
    582564    [TestCategory("Algorithms.DataAnalysis")]
     
    676658      TestGrammarEnumeration(regProblem);
    677659    }
    678     #endregion
    679 
    680660#endif
    681     #endregion
    682661  }
    683662}
Note: See TracChangeset for help on using the changeset viewer.