?
Solved

How to Find Cosine Distance in VB.NET

Posted on 2011-05-11
9
Medium Priority
?
790 Views
Last Modified: 2012-05-11
I m trying to find similar web services using Cosine Distance Classifier


Kindly help me find a code script in VB to do so ...


0
Comment
Question by:Puneet Arora
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:Niyas
ID: 35746663
cosine distance?
are you asking about polar coordinates?
0
 
LVL 1

Expert Comment

by:Niyas
ID: 35746785
0
 

Author Comment

by:Puneet Arora
ID: 35748111
I need to find Cosine  Similarity between 2 Strings (Keywords)  
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35749339
It depends on what you are concerned with. Generally you need to map your strings to a vector of some kind. Then run them through the formula above (except do it as a loop).

Since you said 'keyword' I assume you want to get the vector by counting how many times each word or keyword appears in the page. Since you are dealing with whole numbers only, you won't need the abs
So get the dot product of the two vectors and divide it by the root sum of squares as you see above.
0
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 2000 total points
ID: 35749362
Niyas, you should cite sources when you copy information off the internet (and also make sure you are not violating any licensing).
http://reference.wolfram.com/mathematica/ref/CosineDistance.html
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35749376
Note: cosine distance is kind of a misnomer. Cosine similarity is (I think) a better term since a low number means not similar at all and 1 means identical.
0
 

Author Comment

by:Puneet Arora
ID: 35749387
Is it possible in form of VB code .. in the meantime I m trying  to  write the code ...
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 35754679
Well, if you want code, you'll need to give some more detail. Do you have the vectors already? How are you choosing what keywords to use? Is it a static list?
The code for the formula would look something like this:
Function CosineSimilarity(v1, v2)

Dim numer As Integer
Dim denom1 As Double, denom2 As Double
'v1 and v2 are the vectors of the counts of keywords

numer = 0
denom1 = 0
denom2 = 0

For i = 1 To N 'N is the size of the vector
  numer = numer + v1[i]*v2[i]
  denom1 = denom1 + v1[i]*v1[i]
  denom2 = denom2 + v2[i]*v2[i]
Next

CosineSimilarity = 1 - number/(sqrt(denom1)*sqrt(denom2))
End Function

Open in new window

0
 

Author Comment

by:Puneet Arora
ID: 35755540
Yes I have vectors ready also.. and I have implemented the solution , real thanks for the solution in VB code : Which I wanted ...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
Aerodynamic noise is the cause of the majority of the noise produced by helicopters. The inordinate amount of noise helicopters produce is a major problem in the both a military and civilian setting. To remedy this problem the use of an aerogel coat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question