title: Cosine similarity when one of vectors is all zeros
body: <p>How to express the cosine similarity ( <a href="http://en.wikipedia.org/wiki/Cosine_similarity" rel="noreferrer">http://en.wikipedia.org/wiki/Cosine_similarity</a> ) </p>
  
  <p>when one of the vectors is all zeros?</p>
  
  <p>v1 = [1, 1, 1, 1, 1]</p>
  
  <p>v2 = [0, 0, 0, 0, 0]</p>
  
  <p>When we calculate according to the classic formula we get division by zero:</p>
  
  <pre><code>Let d1 = 0 0 0 0 0 0
  Let d2 = 1 1 1 1 1 1
  Cosine Similarity (d1, d2) =  dot(d1, d2) / ||d1|| ||d2||dot(d1, d2) = (0)*(1) + (0)*(1) + (0)*(1) + (0)*(1) + (0)*(1) + (0)*(1) = 0
  
  ||d1|| = sqrt((0)^2 + (0)^2 + (0)^2 + (0)^2 + (0)^2 + (0)^2) = 0
  
  ||d2|| = sqrt((1)^2 + (1)^2 + (1)^2 + (1)^2 + (1)^2 + (1)^2) = 2.44948974278
  
  Cosine Similarity (d1, d2) = 0 / (0) * (2.44948974278)
                             = 0 / 0
  </code></pre>
  
  <p>I want to use this similarity measure in a clustering application.
  And I often will need to compare such vectors.
  Also [0, 0, 0, 0, 0] vs. [0, 0, 0, 0, 0]</p>
  
  <p>Do you have any experience?
  Since this is a similarity (not a distance) measure should I use special case for</p>
  
  <p>d( [1, 1, 1, 1, 1]; [0, 0, 0, 0, 0] ) = 0</p>
  
  <p>d([0, 0, 0, 0, 0]; [0, 0, 0, 0, 0] ) = 1</p>
  
  <p>what about </p>
  
  <p>d([1, 1, 1, 0, 0]; [0, 0, 0, 0, 0] ) = ? etc.</p>