Created
June 16, 2020 08:46
-
-
Save sguzman/b814f00d8bf271b144e99f561db2b10e to your computer and use it in GitHub Desktop.
Recursive func for producing minimal grammar based on most frequent sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func[{ | |
junk_, | |
c_, | |
cardinalList_, | |
carg_ | |
}] := | |
With[{ | |
cardinal = Association[cardinalList] | |
}, | |
With[{ | |
data = Select[ | |
Table[ | |
With[{ | |
list = Tally@Partition[c, i, 1] | |
}, | |
Splice@ | |
Table[{ | |
First@j, | |
Total@ | |
Map[cardinal, First@j] Last@j, | |
i Last@j, | |
Last@j}, | |
{j, list}]], | |
{i, 1, 100, 1}], | |
And[ | |
Last@# != 1, | |
Length@First@# != 1] | |
&] | |
}, | |
With[{ | |
first = First@ | |
First@ | |
TakeLargestBy[data | |
, #[[2]] &, 1], | |
rankedData = TakeLargestBy[data | |
, #[[2]] &, 10] | |
}, | |
With[{ | |
grid = Grid@ | |
Prepend[ | |
rankedData, | |
{"Pattern", "Strength", "Letters", "Freq"} | |
] | |
}, | |
{ | |
grid, | |
SequenceReplace[c, | |
first :> C[carg]], | |
Prepend[cardinalList, C[carg] -> Length@first], | |
carg + 1 | |
} | |
]]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment