From 789f39813da5a9bb5fea0a6021090a4bf351e7af Mon Sep 17 00:00:00 2001 From: breandan Date: Fri, 24 May 2024 20:24:48 -0400 Subject: [PATCH] branch on small domains --- .../kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt | 5 ++++- .../ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt index 4273c19a..86982bd0 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/SeqValiant.kt @@ -145,7 +145,10 @@ class PTree(val root: String = ".ε", val branches: List<Π2A> = listOf() } fun sampleStrWithoutReplacement(stride: Int = 1, offset: Int = 0): Sequence = - bigLFSRSequence(totalTrees) + if (totalTrees.bitLength() < 5) sequence { + var i = BigInteger.ZERO + while (i < totalTrees) { yield(newDecoder(i)); i++} + } else bigLFSRSequence(totalTrees) .mapIndexedNotNull { index, i -> if (index % stride == offset) newDecoder(i) else null } fun sampleStrWithPCFG5(pcfgTable: Map): Sequence = diff --git a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt index f3897398..440f2802 100644 --- a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt +++ b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt @@ -147,12 +147,13 @@ class BarHillelTest { val origStr = "T and ! ( F )" val levCFG = arithCFGNoEps.intersectLevFSA(makeLevFSA(origStr, 1)) - val lbhSet = levCFG.toPTree().sampleStrWithoutReplacement().toSet()//.onEach { println(it) } + val lbhSet = levCFG.toPTree().sampleStrWithoutReplacement().toSet() + .onEach { println(levenshteinAlign(it, origStr).paintANSIColors()) } .also { println("Found ${it.size} solutions using Levenshtein/Bar-Hillel") } val efset = arithCFG.solveSeq(List(8) { "_" }).toList() .filter { levenshtein(it, origStr) < 2 }.toSet() -// .onEach { println(it) } + .onEach { println(levenshteinAlign(it, origStr).paintANSIColors()) } .also { println("Found ${it.size} solutions using enumerative filtering") } assertEquals(lbhSet, efset, "Levenshtein/Bar-Hillel and enumerative filtering should return the same solutions")