=begin rdoc
iCookware distance funktion for vector matrix
currently using the dice coefficient

Author:: Nicola Kaiser (kaiser@cl.uni-heidelberg.de), Ana Kovatcheva (kovatch@cl.uni-heidelberg.de)
Project:: iCookWare
Copyright:: iCookWare Team 2005 (Nicola Kaiser, Ana Kovatcheva, Olga Mordvinova, Stephanie Schuldes)
Embedded Documentation Tool:: rdoc
=end
 
module ICW
  module Dice
    # Computes similarity between two vectors (Dice coefficient)
    # +v2+:: the other vector
    # +w+:: a vector of weights
    def dist v2, w=nil
      w = [1.0]*length unless w
      num, denom = 0.0, 0.0 
      each_with_index { |el,i|
				#all features containig a "x" are irrelevant and are thus ignored
        if el!="x" and v2[i]!="x"   
          num+=(el*v2[i]) 
          denom+=(el**2+v2[i]**2) 
        end
      }
      2*num/denom
    end


   #returns negative squared Eucledian distance - we need another unit test for this since it is not between 0 and 1
=begin    def dist v2
	    d=0.0
			each_with_index {|el,i|
				 #puts el.to_s+' '+v2[i].to_s
		   d -= (el-v2[i])*(el-v2[i])
		  }
	  #puts d
      d
    end
=end
  end
end


