Coder Social home page Coder Social logo

Comments (7)

vh-d avatar vh-d commented on July 17, 2024 1

this link may help

from rportfoliosimilarity.

dalekube avatar dalekube commented on July 17, 2024

After testing a couple alternatives, I figured out that the weighted cosine similarity function is using the following formula (matching this example):

sum(x*y*w)/(sqrt(sum(x^2*w))*sqrt(sum(y^2*w)))

This includes the weights in the denominator, multiplying each vector value, raised to the second power, by the corresponding weight.

from rportfoliosimilarity.

dalekube avatar dalekube commented on July 17, 2024

It would be great if the formulas are explicitly listed in the docs!

from rportfoliosimilarity.

vh-d avatar vh-d commented on July 17, 2024

After testing a couple alternatives, I figured out that the weighted cosine similarity function is using the following formula (matching this example):

sum(x*y*w)/(sqrt(sum(x^2*w))*sqrt(sum(y^2*w)))

This includes the weights in the denominator, multiplying each vector value, raised to the second power, by the corresponding weight.

Yep, thanks, a look in the source code confirms that:

double wtVCosSimilarity(NumericVector a, NumericVector b, NumericVector w) {
  double sA, sB, sI;

  sA = sum(w*a*a);
  sB = sum(w*b*b);
  sI = sum(w*a*b);
  return (sI/sqrt(sA * sB));
}

I will put in the docs.

from rportfoliosimilarity.

dalekube avatar dalekube commented on July 17, 2024

Great, thanks for confirming the formula. Do you have a link to an external source that helps to confirm this formula? It makes sense as I experiment with it, but a general online search does not return any robust use cases or studies that help with validation.

from rportfoliosimilarity.

vh-d avatar vh-d commented on July 17, 2024

Closed in 8a4094d

from rportfoliosimilarity.

vh-d avatar vh-d commented on July 17, 2024

I am not aware of any solid reference right now. It has been some time since I wrote this part of my dissertation. But I think this was the only formula that behaved well (a.k.a. met some basic requirements on edge cases, equal weights etc...).

from rportfoliosimilarity.

Related Issues (1)

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.