Message Boards Message Boards

0
|
6397 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How to speed up list manipulation

Posted 10 years ago

Hi, I have this code:

corrspeckleframessnrbest = Reap[
      workingset = ssnr; 
     frame1 = First[workingset];
     While[Length[workingset] > 1,
      restset = Rest[workingset];
      If[Length[restset] == 1, Break[]];
      maxcorr = 0;
      frame2 = First[restset];
      curcollection = Reap[
         While[Length[restset] > 1,

           corr = Correlation[
             First[Extract[speckleframes, Position[snr, frame1] ] ], 
             First[Extract[speckleframes, 
               Position[snr, frame2] ] ] ];

           If[corr > maxcorr, 
            Sow[{First[First[Position[snr, frame1] ] ], 
              First[First[Position[snr, frame2] ] ], corr}] ; 
            maxcorr = corr;];
           restset = Sort[Complement[restset, {frame2}], Greater];
           frame2 = First[restset];
           ];
         ][[2, 1]];
      Sow[Last[curcollection]];
      workingset = Sort[Complement[workingset, {frame1}], Greater];
      frame1 = 
       workingset[[First[
          First[Position[workingset, 
            snr[[Last[curcollection][[2]] ]] ] ] ] ]];
      workingset = Sort[Complement[workingset, {frame1}], Greater];
      ];

     ][[2, 1]]; // Timing

{7161.449902, Null}

If I put essentially the same code into a ParallelTable and execute 67 times:

In[375]:= corrspeckleframesentbest = ParallelTable[Reap[
       workingset = smespeckleRenyialpha[[i]]; 
      frame1 = First[workingset];
      While[Length[workingset] > 1,
       restset = Rest[workingset];
       If[Length[restset] == 1, Break[]];
       maxcorr = 0;
       frame2 = First[restset];
       curcollection = Reap[
          While[Length[restset] > 1,

            corr = Correlation[
              First[Extract[speckleframes, 
                Position[mespeckleRenyialpha[[i]], frame1] ] ], 
              First[Extract[speckleframes, 
                Position[mespeckleRenyialpha[[i]], frame2] ] ] ];

            If[corr > maxcorr, 
             Sow[{First[
                First[Position[mespeckleRenyialpha[[i]], frame1] ] ], 
               First[First[
                 Position[mespeckleRenyialpha[[i]], frame2] ] ], 
               corr}] ; maxcorr = corr;];
            restset = Sort[Complement[restset, {frame2}], Greater];
            frame2 = First[restset];
            ];
          ][[2, 1]];
       Sow[Last[curcollection]];
       workingset = Sort[Complement[workingset, {frame1}], Greater];
       frame1 = 
        workingset[[First[
           First[Position[workingset, 
             mespeckleRenyialpha[[i]][[Last[
                 curcollection][[2]] ]] ] ] ] ]];
       workingset = Sort[Complement[workingset, {frame1}], Greater];
       ];

      ][[2, 1]], {i, 1, lengthalphaArray}]; // Timing

Out[375]= {2784.794970, Null}

it executes almost one-third of the single run time. That says to me that further optimization of the single executed code is possible. I looked long and far, but I see no obvious ways to do it. Maybe someone on the list has much sharper eyes. Thanks ahead, János

POSTED BY: Janos Lobb
Posted 10 years ago

I think speeding up is a really good idea, but do not forget about the other factors that might affect the program. - Paramount Song

POSTED BY: Sheldon Cooper
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract