Correlation 2D vector fields











up vote
1
down vote

favorite












Having multiple 2D flow maps, ie vector fields how would one find statistical correlation between pairs of these?



The problem:



One should not (?) resize 2 flow maps of shape (x,y,2): flow1, flow2 to 1D vectors and run



np.correlation_coeff(flow1.reshape(1,-1),flow2.reshape(1,-1))



since x,y entries are connected.



Plotting yields, for visualization purposes only:



flow1:
flow1flow2:
flow2



I am thinking about comparing magnitudes and direction.




  • How would one ideally compare those (cosinus-distance, ...)?


  • How would one compare covariance between vector fields?



Edit:



I am aware that np.corrcoef(flow1.reshape(2,-1), flow2.reshape(2,-1)) would return a 4,4 correlation coefficient matrix but find it unintuitive to interpret.










share|improve this question




























    up vote
    1
    down vote

    favorite












    Having multiple 2D flow maps, ie vector fields how would one find statistical correlation between pairs of these?



    The problem:



    One should not (?) resize 2 flow maps of shape (x,y,2): flow1, flow2 to 1D vectors and run



    np.correlation_coeff(flow1.reshape(1,-1),flow2.reshape(1,-1))



    since x,y entries are connected.



    Plotting yields, for visualization purposes only:



    flow1:
    flow1flow2:
    flow2



    I am thinking about comparing magnitudes and direction.




    • How would one ideally compare those (cosinus-distance, ...)?


    • How would one compare covariance between vector fields?



    Edit:



    I am aware that np.corrcoef(flow1.reshape(2,-1), flow2.reshape(2,-1)) would return a 4,4 correlation coefficient matrix but find it unintuitive to interpret.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Having multiple 2D flow maps, ie vector fields how would one find statistical correlation between pairs of these?



      The problem:



      One should not (?) resize 2 flow maps of shape (x,y,2): flow1, flow2 to 1D vectors and run



      np.correlation_coeff(flow1.reshape(1,-1),flow2.reshape(1,-1))



      since x,y entries are connected.



      Plotting yields, for visualization purposes only:



      flow1:
      flow1flow2:
      flow2



      I am thinking about comparing magnitudes and direction.




      • How would one ideally compare those (cosinus-distance, ...)?


      • How would one compare covariance between vector fields?



      Edit:



      I am aware that np.corrcoef(flow1.reshape(2,-1), flow2.reshape(2,-1)) would return a 4,4 correlation coefficient matrix but find it unintuitive to interpret.










      share|improve this question















      Having multiple 2D flow maps, ie vector fields how would one find statistical correlation between pairs of these?



      The problem:



      One should not (?) resize 2 flow maps of shape (x,y,2): flow1, flow2 to 1D vectors and run



      np.correlation_coeff(flow1.reshape(1,-1),flow2.reshape(1,-1))



      since x,y entries are connected.



      Plotting yields, for visualization purposes only:



      flow1:
      flow1flow2:
      flow2



      I am thinking about comparing magnitudes and direction.




      • How would one ideally compare those (cosinus-distance, ...)?


      • How would one compare covariance between vector fields?



      Edit:



      I am aware that np.corrcoef(flow1.reshape(2,-1), flow2.reshape(2,-1)) would return a 4,4 correlation coefficient matrix but find it unintuitive to interpret.







      numpy scikit-learn scipy correlation covariance






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 16:24

























      asked Nov 9 at 16:13









      Benedict K.

      343215




      343215
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          For some measures of similarity it may indeed be desirable to take the spatial structure of the domain into account. But a coefficient of correlation does not do that: it is invariant under any permutations of the domain. For example, the correlation between (0, 1, 2, 3, 4) and (1, 2, 4, 8, 16) is the same as between (1, 4, 2, 0, 3) and (2, 16, 4, 1, 8) where both arrays were reshuffled in the same way.



          So, the coefficient of correlation would be obtained by:




          1. Centering both arrays, i.e., subtracting their mean. Say, we get FC1 and FC2.

          2. Taking the inner product FC1 and FC2 : this is just the sum of the products of matching entries.

          3. Dividing by the square roots of the inner products FC1*FC1 and FC2*FC2.


          Example:



          flow1 = np.random.uniform(size=(10, 10, 2))     # the 3rd dimension is for the components
          flow2 = flow1 + np.random.uniform(size=(10, 10, 2))
          flow1_centered = flow1 - np.mean(flow1, axis=(0, 1))
          flow2_centered = flow2 - np.mean(flow2, axis=(0, 1))
          inner_product = np.sum(flow1_centered*flow2_centered)
          r = inner_product/np.sqrt(np.sum(flow1_centered**2) * np.sum(flow2_centered**2))


          Here the flows have some positive correlation because I included flow2 in flow1. Specifically, it's a number around 1/sqrt(2), subject to random noise.



          If this is not what you want, then you don't want the coefficient of correlation but some other measure of similarity.






          share|improve this answer





















          • Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
            – Benedict K.
            Nov 12 at 13:32






          • 1




            The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
            – user6655984
            Nov 12 at 13:44










          • Interesting, do you happen to have more information (maybe wiki?)
            – Benedict K.
            Nov 12 at 13:56










          • sum of squared norms of vectors F - G, is basically variance but not mean centered?
            – Benedict K.
            Nov 12 at 14:15













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229424%2fcorrelation-2d-vector-fields%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          For some measures of similarity it may indeed be desirable to take the spatial structure of the domain into account. But a coefficient of correlation does not do that: it is invariant under any permutations of the domain. For example, the correlation between (0, 1, 2, 3, 4) and (1, 2, 4, 8, 16) is the same as between (1, 4, 2, 0, 3) and (2, 16, 4, 1, 8) where both arrays were reshuffled in the same way.



          So, the coefficient of correlation would be obtained by:




          1. Centering both arrays, i.e., subtracting their mean. Say, we get FC1 and FC2.

          2. Taking the inner product FC1 and FC2 : this is just the sum of the products of matching entries.

          3. Dividing by the square roots of the inner products FC1*FC1 and FC2*FC2.


          Example:



          flow1 = np.random.uniform(size=(10, 10, 2))     # the 3rd dimension is for the components
          flow2 = flow1 + np.random.uniform(size=(10, 10, 2))
          flow1_centered = flow1 - np.mean(flow1, axis=(0, 1))
          flow2_centered = flow2 - np.mean(flow2, axis=(0, 1))
          inner_product = np.sum(flow1_centered*flow2_centered)
          r = inner_product/np.sqrt(np.sum(flow1_centered**2) * np.sum(flow2_centered**2))


          Here the flows have some positive correlation because I included flow2 in flow1. Specifically, it's a number around 1/sqrt(2), subject to random noise.



          If this is not what you want, then you don't want the coefficient of correlation but some other measure of similarity.






          share|improve this answer





















          • Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
            – Benedict K.
            Nov 12 at 13:32






          • 1




            The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
            – user6655984
            Nov 12 at 13:44










          • Interesting, do you happen to have more information (maybe wiki?)
            – Benedict K.
            Nov 12 at 13:56










          • sum of squared norms of vectors F - G, is basically variance but not mean centered?
            – Benedict K.
            Nov 12 at 14:15

















          up vote
          1
          down vote



          accepted










          For some measures of similarity it may indeed be desirable to take the spatial structure of the domain into account. But a coefficient of correlation does not do that: it is invariant under any permutations of the domain. For example, the correlation between (0, 1, 2, 3, 4) and (1, 2, 4, 8, 16) is the same as between (1, 4, 2, 0, 3) and (2, 16, 4, 1, 8) where both arrays were reshuffled in the same way.



          So, the coefficient of correlation would be obtained by:




          1. Centering both arrays, i.e., subtracting their mean. Say, we get FC1 and FC2.

          2. Taking the inner product FC1 and FC2 : this is just the sum of the products of matching entries.

          3. Dividing by the square roots of the inner products FC1*FC1 and FC2*FC2.


          Example:



          flow1 = np.random.uniform(size=(10, 10, 2))     # the 3rd dimension is for the components
          flow2 = flow1 + np.random.uniform(size=(10, 10, 2))
          flow1_centered = flow1 - np.mean(flow1, axis=(0, 1))
          flow2_centered = flow2 - np.mean(flow2, axis=(0, 1))
          inner_product = np.sum(flow1_centered*flow2_centered)
          r = inner_product/np.sqrt(np.sum(flow1_centered**2) * np.sum(flow2_centered**2))


          Here the flows have some positive correlation because I included flow2 in flow1. Specifically, it's a number around 1/sqrt(2), subject to random noise.



          If this is not what you want, then you don't want the coefficient of correlation but some other measure of similarity.






          share|improve this answer





















          • Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
            – Benedict K.
            Nov 12 at 13:32






          • 1




            The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
            – user6655984
            Nov 12 at 13:44










          • Interesting, do you happen to have more information (maybe wiki?)
            – Benedict K.
            Nov 12 at 13:56










          • sum of squared norms of vectors F - G, is basically variance but not mean centered?
            – Benedict K.
            Nov 12 at 14:15















          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          For some measures of similarity it may indeed be desirable to take the spatial structure of the domain into account. But a coefficient of correlation does not do that: it is invariant under any permutations of the domain. For example, the correlation between (0, 1, 2, 3, 4) and (1, 2, 4, 8, 16) is the same as between (1, 4, 2, 0, 3) and (2, 16, 4, 1, 8) where both arrays were reshuffled in the same way.



          So, the coefficient of correlation would be obtained by:




          1. Centering both arrays, i.e., subtracting their mean. Say, we get FC1 and FC2.

          2. Taking the inner product FC1 and FC2 : this is just the sum of the products of matching entries.

          3. Dividing by the square roots of the inner products FC1*FC1 and FC2*FC2.


          Example:



          flow1 = np.random.uniform(size=(10, 10, 2))     # the 3rd dimension is for the components
          flow2 = flow1 + np.random.uniform(size=(10, 10, 2))
          flow1_centered = flow1 - np.mean(flow1, axis=(0, 1))
          flow2_centered = flow2 - np.mean(flow2, axis=(0, 1))
          inner_product = np.sum(flow1_centered*flow2_centered)
          r = inner_product/np.sqrt(np.sum(flow1_centered**2) * np.sum(flow2_centered**2))


          Here the flows have some positive correlation because I included flow2 in flow1. Specifically, it's a number around 1/sqrt(2), subject to random noise.



          If this is not what you want, then you don't want the coefficient of correlation but some other measure of similarity.






          share|improve this answer












          For some measures of similarity it may indeed be desirable to take the spatial structure of the domain into account. But a coefficient of correlation does not do that: it is invariant under any permutations of the domain. For example, the correlation between (0, 1, 2, 3, 4) and (1, 2, 4, 8, 16) is the same as between (1, 4, 2, 0, 3) and (2, 16, 4, 1, 8) where both arrays were reshuffled in the same way.



          So, the coefficient of correlation would be obtained by:




          1. Centering both arrays, i.e., subtracting their mean. Say, we get FC1 and FC2.

          2. Taking the inner product FC1 and FC2 : this is just the sum of the products of matching entries.

          3. Dividing by the square roots of the inner products FC1*FC1 and FC2*FC2.


          Example:



          flow1 = np.random.uniform(size=(10, 10, 2))     # the 3rd dimension is for the components
          flow2 = flow1 + np.random.uniform(size=(10, 10, 2))
          flow1_centered = flow1 - np.mean(flow1, axis=(0, 1))
          flow2_centered = flow2 - np.mean(flow2, axis=(0, 1))
          inner_product = np.sum(flow1_centered*flow2_centered)
          r = inner_product/np.sqrt(np.sum(flow1_centered**2) * np.sum(flow2_centered**2))


          Here the flows have some positive correlation because I included flow2 in flow1. Specifically, it's a number around 1/sqrt(2), subject to random noise.



          If this is not what you want, then you don't want the coefficient of correlation but some other measure of similarity.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 21:16







          user6655984



















          • Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
            – Benedict K.
            Nov 12 at 13:32






          • 1




            The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
            – user6655984
            Nov 12 at 13:44










          • Interesting, do you happen to have more information (maybe wiki?)
            – Benedict K.
            Nov 12 at 13:56










          • sum of squared norms of vectors F - G, is basically variance but not mean centered?
            – Benedict K.
            Nov 12 at 14:15




















          • Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
            – Benedict K.
            Nov 12 at 13:32






          • 1




            The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
            – user6655984
            Nov 12 at 13:44










          • Interesting, do you happen to have more information (maybe wiki?)
            – Benedict K.
            Nov 12 at 13:56










          • sum of squared norms of vectors F - G, is basically variance but not mean centered?
            – Benedict K.
            Nov 12 at 14:15


















          Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
          – Benedict K.
          Nov 12 at 13:32




          Great thanks a lot! To me this looks like cosine similarity? Does this take into account the magnitude of the vector, since vectors are normalized and centered? What would be a good measure that uses both angle and magnitude, or how would one measure magnitude similarity (prob covariance?)
          – Benedict K.
          Nov 12 at 13:32




          1




          1




          The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
          – user6655984
          Nov 12 at 13:44




          The fields F and 100*F have perfect correlation (1). If this is not desired, you need another measure. Maybe the sum of squared norms of vectors F - G. There are infinitely many formulas one can write out.
          – user6655984
          Nov 12 at 13:44












          Interesting, do you happen to have more information (maybe wiki?)
          – Benedict K.
          Nov 12 at 13:56




          Interesting, do you happen to have more information (maybe wiki?)
          – Benedict K.
          Nov 12 at 13:56












          sum of squared norms of vectors F - G, is basically variance but not mean centered?
          – Benedict K.
          Nov 12 at 14:15






          sum of squared norms of vectors F - G, is basically variance but not mean centered?
          – Benedict K.
          Nov 12 at 14:15




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229424%2fcorrelation-2d-vector-fields%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Landwehr

          Reims

          Schenkenzell