I would like to automate the following operation. To be transparent I shall put my code into separate chunks and explain the process. Suppose I have the following:
ELPr = Map[DeleteDuplicates,
WordList[Language -> "English"] // Characters // ToLowerCase];
which basically makes English words into characters without duplication of letters in each words. I am going to make a polynomial also which measures the length of words by numbers that is,
ELPrPo = Total[x^Map[Length, ELPr]];
The rest of my code would be as follow:
out = Import["path/out.csv"];
l = Replace[out,
s_String :>
If[StringMatchQ[s, "[" ~~ ___ ~~ "]"],
ToExpression["{" <> StringTake[s, {2, -2}] <> "}"], {s}], {2}];
t1 = l[[All, 1, 1]];
t2 = Table[x^-2 Total[x^l[[i, 2]]], {i, Length[l]}];
LPairPo = AssociationThread[t1, t2];
Map[Expand, ELPrPo + x LPairPo - x^2 LPairPo];
Map[Expand,
Table[%[[i]] - 1/(26 + 1) x D[%[[i]], x], {i, Length[l]}]] // N;
LPairQo = AssociationThread[t1, %];
ξ = LPairQo/ELPrPo;
q = TakeLargest[ξ /. x -> 2/(26 + 1) // N, 1];
In my directory I have number of out.csv
files named as out
, out1
, out2
and so on for each I want to import them and find the q
value. Once the q
value is returned I do the following:
g1 = ELPr //. {OrderlessPatternSequence[
Flatten[StringSplit[#, ":"] &@Keys[q]][[1]],
Flatten[StringSplit[#, ":"] &@Keys[q]][[2]], p___]} :> {Keys[q],
p};
ELPrPo1 = Total[x^Map[Length, g1]];
Export["Desktop/LIMS/LIMS13/Language/ELPr1.csv",g1]
which essentially makes a new ELPr
list now calling it g1
and its corresponding polynomial ELPrPo1
as explained in the beginning of this post. I now do the same calculations again:
out = Import["path/out1.csv"];
l = Replace[out,
s_String :>
If[StringMatchQ[s, "[" ~~ ___ ~~ "]"],
ToExpression["{" <> StringTake[s, {2, -2}] <> "}"], {s}], {2}];
t1 = l[[All, 1, 1]];
t2 = Table[x^-2 Total[x^l[[i, 2]]], {i, Length[l]}];
LPairPo = AssociationThread[t1, t2];
Map[Expand, ELPrPo1 + x LPairPo - x^2 LPairPo];
Map[Expand,
Table[%[[i]] - 1/(26 + 2) x D[%[[i]], x], {i, Length[l]}]] // N;
LPairQo = AssociationThread[t1, %];
ξ = LPairQo/ELPrPo;
q = TakeLargest[ξ /. x -> 2/(26 + 2) // N, 1]
But this one by q
value is being calculated based on out1.csv
, ELPrPo1
, and the numerical value which was 2/(26+1)
is now 2/(26+2)
. I wonder how can I make this iterations automated namely to go through out.csv
files, find new value for q
with appropriate numerics (namely changing 2/(26+1)
to 2/(26+2)
and then 2/(26+3)
and so on on each iteration), make a new list g1
,g2
,g3
and their corresponding polynomials?