Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling hashes #6

Open
keynmol opened this issue Apr 28, 2013 · 0 comments
Open

Handling hashes #6

keynmol opened this issue Apr 28, 2013 · 0 comments

Comments

@keynmol
Copy link

keynmol commented Apr 28, 2013

I was just wondering, is it possible to add support for Hash in similiarity methods? I've cauht myself re-implementing it without knowing of the existence of this gem. For example for cosine similarity I see something like that included in Hash:

module DistanceMeasures
  def cosine_similarity(other)
        shared_keys=self.keys & other.keys
        if shared_keys.empty?
            return 0.0  
        else
            self_values=self.values_at(*shared_keys) 
            other_values=other.values_at(*shared_keys) 
            dot_product = self_values.dot_product(*other_values)
            normalization = self_values.euclidean_normalize * other_values.euclidean_normalize
            handle_nan(dot_product / normalization)
        end
    end
end

Why metrics for Hash? For example one common case where hashes are compared arises from information retrieval tasks, where vectors have such enormous number of dimensions, that it is considerably better to store them as hashes {"word"=> <..weight..> }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant