Skip to main content
deleted 30 characters in body
Source Link
Albercoc
  • 1.1k
  • 4
  • 13

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];;

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];

target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)


(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

listScores = list // getScore;
identifyTerms[expr_] := Module[{cand, p},
   cand = Position[listScores, getScore[expr]] // Flatten;
   p = Position[list[[cand]], expr] // Flatten;
   cand[[p]]];

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];

target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)


(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

listScores = list // getScore;
identifyTerms[expr_] := Module[{cand, p},
   cand = Position[listScores, getScore[expr]] // Flatten;
   p = Position[list[[cand]], expr] // Flatten;
   cand[[p]]];

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] ;

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];

target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)


(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

listScores = list // getScore;
identifyTerms[expr_] := Module[{cand, p},
   cand = Position[listScores, getScore[expr]] // Flatten;
   p = Position[list[[cand]], expr] // Flatten;
   cand[[p]]];
deleted 107 characters in body
Source Link
Albercoc
  • 1.1k
  • 4
  • 13

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

identifyTerms[expr_] := 
  Module[{positionsWithSameScore, posInReducedList},
   positionsWithSameScore = 
    Position[listScores, getScore[expr]] // Flatten;
   posInReducedList = 
    Position[list[[positionsWithSameScore]], expr] // Flatten; 
   positionsWithSameScore[[posInReducedList]]
   ];

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];
listScores = list // getScore;


target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)


(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

listScores = list // getScore;
identifyTerms[expr_] := Module[{cand, p},
   cand = Position[listScores, getScore[expr]] // Flatten;
   p = Position[list[[cand]], expr] // Flatten;
   cand[[p]]];

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

identifyTerms[expr_] := 
  Module[{positionsWithSameScore, posInReducedList},
   positionsWithSameScore = 
    Position[listScores, getScore[expr]] // Flatten;
   posInReducedList = 
    Position[list[[positionsWithSameScore]], expr] // Flatten; 
   positionsWithSameScore[[posInReducedList]]
   ];

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];
listScores = list // getScore;


target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];

target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)


(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

listScores = list // getScore;
identifyTerms[expr_] := Module[{cand, p},
   cand = Position[listScores, getScore[expr]] // Flatten;
   p = Position[list[[cand]], expr] // Flatten;
   cand[[p]]];
added 31 characters in body
Source Link
Albercoc
  • 1.1k
  • 4
  • 13

I need to identify the position inside list of the elements in target, and substitute them by termID[position]. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

identifyTerms[expr_] := 
  Module[{reducedListOfPositionspositionsWithSameScore, posInReducedList},
   reducedListOfPositionspositionsWithSameScore = 
    Position[listScores, getScore[expr]] // Flatten;
   posInReducedList = Position[list[[reducedListOfPositions]], expr];
   
   posInReducedList = posInReducedList[[1Position[list[[positionsWithSameScore]], 1]];
expr] // Flatten; termID[reducedListOfPositions[[posInReducedList]]]
   positionsWithSameScore[[posInReducedList]]
   ];

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];
listScores = list // getScore; 


target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)

I need to identify the position inside list of the elements in target, and substitute them by termID[position]. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

identifyTerms[expr_] := 
  Module[{reducedListOfPositions, posInReducedList},
   reducedListOfPositions = 
    Position[listScores, getScore[expr]] // Flatten;
   posInReducedList = Position[list[[reducedListOfPositions]], expr];
   
   posInReducedList = posInReducedList[[1, 1]];
   termID[reducedListOfPositions[[posInReducedList]]]
   
   ];

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];
listScores = list // getScore;
target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

I need to identify the position inside list of the elements in target. Straightforward solution:

Timing[target // Map[Position[list, #] &] // Map[termID[#[[1, 1]]] &  ]];

15s

I needed a faster algorithm for my real case. Here is my try but any completely different solution is also very welcome. I assigned a score to each element, compared scores first, then look for the specific element within the candidates.

Timing[target // Map[identifyTerms];]

2.5s

But this is still not fast enough (in the real case)

Here my dummy example I made for this question:

(*functions*)

getScore[expr_] := 
 expr /. {a -> 1, b -> 2, c -> 3, d -> 4, e -> 5, f -> 6, g -> 7, 
    h -> 8} /. Dot -> Times

identifyTerms[expr_] := 
  Module[{positionsWithSameScore, posInReducedList},
   positionsWithSameScore = 
    Position[listScores, getScore[expr]] // Flatten;
   posInReducedList = 
    Position[list[[positionsWithSameScore]], expr] // Flatten; 
   positionsWithSameScore[[posInReducedList]]
   ];

(*list and target*)

list = {a, b, c, d, e, f, g, h} // Permutations[#, {2, 7}] & // 
    RandomSample // Map[Dot @@ # &];
listScores = list // getScore; 


target = {a, b, c, d, e, f} // Permutations[#, {2, 5}] & // 
   Map[Dot @@ # &];

(*simple target: target={a.b.c}*)
(*simple list: list={a, b.f, a.b.c}*)

Source Link
Albercoc
  • 1.1k
  • 4
  • 13
Loading