Coder Social home page Coder Social logo

About distances about annoy HOT 6 CLOSED

spotify avatar spotify commented on May 17, 2024
About distances

from annoy.

Comments (6)

erikbern avatar erikbern commented on May 17, 2024 7

cosine_distance = sqrt(2-2*cos_similarity)

so cosine_similarity = 1 - cosine_distance^2/2

from annoy.

erikbern avatar erikbern commented on May 17, 2024

Cosine distance can be between 0 and 2. The distance between x and -x should be exactly 2

http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.spatial.distance.cosine.html

I will add a unit tests though

from annoy.

anhldbk avatar anhldbk commented on May 17, 2024

@erikbern Thank you Erik

from annoy.

harsh157 avatar harsh157 commented on May 17, 2024

Shouldn't the distance range be 0 to 4? as it is computing 2*(1-cos). That is if we have vectors in opposing directions also.

from annoy.

MrChrisJohnson avatar MrChrisJohnson commented on May 17, 2024

Why 2_(1-cos)? Distance should just be 1-cos which is equivalent to 1 - u_v / ||u|| * ||v||. So, distance would range from 0 (angle of 0) to 2 (angle of 180). See the link that @erikbern links to earlier.

from annoy.

Irtza avatar Irtza commented on May 17, 2024

@erikbern @MrChrisJohnson Can we convert to cosine similarity using cos_sim = 1-cos_distance ?

from annoy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.