Group Abstract Group Abstract

Message Boards Message Boards

0
|
7K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Compare all sublists of two different lists using PartitionMap?

Posted 7 years ago
POSTED BY: Jamie Dixson
7 Replies
Posted 7 years ago
POSTED BY: Jamie Dixson
Posted 7 years ago

Hi Jamie,

Here is a start. The grouping and header numbers are hardcoded but that is relatively easy to fix.

columnHeader = Table["seq1(" <> ToString[x] <> "-" <> ToString[x + 9] <> ")", {x, 1, 21, 10}];
rowHeader = Table["seq2(" <> ToString[x] <> "-" <> ToString[x + 9] <> ")", {x, 1, 21, 5}];
rowHeader = Join[{""}, rowHeader];
grid = MapThread[Prepend, {Prepend[ArrayReshape[outtable, {5, 3}], columnHeader], rowHeader}];
Grid[grid, ItemStyle -> {{1 -> Bold}, {1 -> Bold}}, Background -> {{LightYellow, None}, {LightYellow, None}}, Frame -> All]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 7 years ago

Thank you both for your help thus far. Below is an example of what I am looking for as far as final output. The code that I have that produces these values albeit in one list is:

seq1 = {52.000, 52.289, 39.000, 
   0.000, -10.121, -19.000, -22.000, -28.203, -18.000, -6.000, -5.615,
    0.000, 0.000, 1.770, 2.000, 4.000, 3.903, 
   2.000, -4.000, -3.729, -3.000, 4.000, 20.378, 20.000, 47.000, 
   74.958, 58.000, 54.000, 68.563, 40.000};
seq2 = {52.000, 52.289, 39.000, -12.000, -1.792, -6.000, 49.000, 
   69.931, 59.000, 24.000, 27.989, 7.000, 7.000, 21.857, 18.000, 
   41.000, 55.666, 41.000, 18.000, 33.127, 18.000, 41.000, 57.813, 
   43.000, 25.000, 28.099, 11.000, 2.000, -2.715, -6.000};
dist1 = Tuples[{Partition[seq1, 10, 10], Partition[seq2, 10, 5]}];
outtable = 
 Table [CanonicalWarpingDistance[dist1[[i, 1]], dist1[[i, 2]], 
   Automatic, {"SlantedBand", 950}, 
   Method -> {"MatchingInterval" -> "Flexible"}, 
   DistanceFunction -> CosineDistance], {i, 1, Length[dist1]}]

The output is currently:

{2936.43, 2010.95, 805.145, 1277.23, 646.763, 40.0572, 11.9107, \
28.5548, 52.7854, 14.1702, 1305.69, 1775.71, 412.422, 773.669, \
726.661}

but I need this: Example Output

POSTED BY: Jamie Dixson
Posted 7 years ago

Hi Jamie,

I'm not sure what you mean by in x, y form perhaps if you were to give an example of how you need to see the output I or some one else might be able to help.

POSTED BY: Paul Cleary
Posted 7 years ago

Jamie,

Not sure what you mean by x, y form. You can Partition by 2 to generate sublists of pairs. If you want a mapping from sublist pairs to distance you can try this.

distances = Table[{dist1[[i, 1]], dist1[[i, 2]]} -> 
  CanonicalWarpingDistance[dist1[[i, 1]], dist1[[i, 2]], 
   Automatic, {"SlantedBand", 950}, 
   Method -> {"MatchingInterval" -> "Flexible"}, 
   DistanceFunction -> EuclideanDistance], {i, 1, Length[dist1]}]

The first few elements of the result

Column[Take[distances, 4]]

{
 {{{52., 52.289, 39., 0., -10.121}, {52., 52.289, 39., 0., -10.121}} -> 0.},
 {{{52., 52.289, 39., 0., -10.121}, {-19., -22., -28.203, -18., -6.}} -> 87.0858},
 {{{52., 52.289, 39., 0., -10.121}, {-5.615, 0., 0., 1.77, 2.}} -> 13.7236},
 {{{52., 52.289, 39., 0., -10.121}, {4., 3.903, 2., -4., -3.729}} -> 0.0414335}
}
POSTED BY: Rohit Namjoshi
Posted 7 years ago

This works great Paul! Thank you. The only other thing that I need to incorporate is that I need the output in x,y form rather than one long list. It looks like I might be able to use "Array" in place of table to make that happen. Do you have any advice for that?

POSTED BY: Jamie Dixson
Posted 7 years ago

I have made a few changes. dist1 are the tuples of your sub list of 5 elements. Have a look and see if this is what you are looking for.

seq = {52.000, 52.289, 39.000, 
   0.000, -10.121, -19.000, -22.000, -28.203, -18.000, -6.000, -5.615,
    0.000, 0.000, 1.770, 2.000, 4.000, 3.903, 
   2.000, -4.000, -3.729, -3.000, 4.000, 20.378, 20.000, 47.000, 
   74.958, 58.000, 54.000, 68.563, 40.000, 17.000, 16.861, 
   2.000, -4.000, -11.492, -11.000, -20.000, -21.798, -14.000, 6.000, 
   7.932, 10.000, -1.000, -4.688, -7.000, -7.000, -10.321, -7.000, \
-7.000, -10.321, -7.000, -7.000, -10.321, -7.000, -7.000, -10.321, \
-7.000, -7.000, -10.321, -7.000};
seq2 = {52.000, 52.289, 39.000, 
  0.000, -10.121, -19.000, -22.000, -28.203, -18.000, -6.000, -5.615, 
  0.000, 0.000, 1.770, 2.000, 4.000, 3.903, 
  2.000, -4.000, -3.729, -3.000, 4.000, 20.378, 20.000, 47.000, 
  74.958, 58.000, 54.000, 68.563, 40.000, 17.000, 16.861, 
  2.000, -4.000, -11.492, -11.000, -20.000, -21.798, -14.000, 6.000, 
  7.932, 10.000, -1.000, -4.688, -7.000, -7.000, -10.321, -7.000, \
-7.000, -10.321, -7.000, -7.000, -10.321, -7.000, -7.000, -10.321, \
-7.000, -7.000, -10.321, -7.000}; dist1 = 
 Tuples[{Partition[seq, 5], Partition[seq2, 5]}];
Table[CanonicalWarpingDistance[dist1[[i, 1]], dist1[[i, 2]], 
  Automatic, {"SlantedBand", 950}, 
  Method -> {"MatchingInterval" -> "Flexible"}, 
  DistanceFunction -> EuclideanDistance], {i, 1, Length[dist1]}]
POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard