//True if phi accepts all the strings in testset private static bool CorrectOnPosSet(PDLPred phi, IEnumerable<string> testSet) { foreach (var test in testSet) if (!phi.Eval(test, new Dictionary<string, int>())) { return false; } return true; }
//Return what percentage of testSet phi accepts private static double PercentagePosSet(PDLPred phi, IEnumerable<string> testSet) { double correct =0; double total = 0; foreach (var test in testSet) { total++; if (!phi.Eval(test, new Dictionary<string, int>())) correct++; } return total==0?0:correct/total; }
/// <summary> /// Discards a formula if it has the same result on all test strings. The idea is that this formula is probably too /// easy. /// </summary> /// <param name="candidates"></param> /// <returns></returns> public override bool KeepPredicate(PDLPred candidate) { bool firstResult = candidate.Eval(this.testStrings[0], new Dictionary<string, int>()); for (int testStringIndex = 1; testStringIndex < this.testStrings.Count; ++testStringIndex) { string testString = this.testStrings[testStringIndex]; bool currentResult = candidate.Eval(testString, new Dictionary<string, int>()); if (currentResult != firstResult) { // Since a single differing result is enough, we can return from here return true; } } return false; }