You get this result if you add and subtract the vectors component-wise (i.e., ) and .
Hi everyone,
I am new here. I stumbled upon this forum while trying to figure out an algorithm that involves vector and normalised difference between the vector. The equation is given as
Sr = 1 - ( || r1 - r2|| / || r1 + r2|| )
A given example gives r1 and r2 as shown below.
r1 = {1 2 3 4 5 6 0 3 3 0 0 0 1 1}
r2 = {4 0 3 0 0 0 1 2 3 5 6 7 8 9}
Sr = 0.2023
It would be really great if anyone can explain or show me how to get the answer Sr = 0.2023. Thank you very much!
Thanks for the quick reply. I understand the first part that I should add and subtract the vector as give below.
r_{1} - r_{2} = (x_{1} - y_{1}, . . . , x_{n} - y_{n})
r_{1} + r_{2} = (x_{1} + y_{1}, . . . , x_{n} + y_{n})
But, I am not sure understand the second part though. Is the equation below correct?
||r_{1} - r_{2}|| = || sqrt{(x_{1}^{2} - y_{1}^{2})+ . . . + (x_{n}^{2} - y_{n}^{2})} ||
||r_{1} + r_{2}|| = || sqrt{(x_{1}^{2} + y_{1}^{2})+ . . . + (x_{n}^{2} + y_{n})} ||
If that is correct, then I still cannot get the answer as 0.2023.
Hi emakarov,
I've tried that as well and the answers are still different from the given answer of 0.2023. It's difficult to explain the equation without being able to insert the proper symbols or insert images. But, basically I am trying to find
1 - ( ||r_{1} - r_{2}|| divide by ||r_{1} + r_{2}|| ) for r_{1 }and r_{2}.
It's actually an algorithm proposed to check for semantic similarity for sentences. If it would help explain my case, I posted a link to the paper. It's equation 8 on page 6.
Link to paper: http://ants.iis.sinica.edu.tw/3BkMJ9...statistics.pdf
Any help would really be great at this point.
First, I made a small correction to post #4.
I'll post the output of the program that computes Sr.
r₁
r₂Code:[1.; 2.; 3.; 4.; 5.; 6.; 0.; 3.; 3.; 0.; 0.; 0.; 1.; 1.]
r₁ + r₂Code:[4.; 0.; 3.; 0.; 0.; 0.; 1.; 2.; 3.; 5.; 6.; 7.; 8.; 9.]
r₁ - r₂Code:[5.; 2.; 6.; 4.; 5.; 6.; 1.; 5.; 6.; 5.; 6.; 7.; 9.; 10.]
Squares of elements of r₁ + r₂Code:[-3.; 2.; 0.; 4.; 5.; 6.; -1.; 1.; 0.; -5.; -6.; -7.; -7.; -8.]
Squares of elements of r₁ - r₂Code:[25.; 4.; 36.; 16.; 25.; 36.; 1.; 25.; 36.; 25.; 36.; 49.; 81.; 100.]
Sum of squares of elements of r₁ + r₂ is 495Code:[9.; 4.; 0.; 16.; 25.; 36.; 1.; 1.; 0.; 25.; 36.; 49.; 49.; 64.]
Sum of squares of elements of r₁ - r₂ is 315
||r₁ + r₂|| = sqrt(495) = 22.248595461286989
||r₁ - r₂|| = sqrt(315) = 17.7482393492988493
||r₁ - r₂|| / ||r₁ + r₂|| = 0.79772403521746571
1 - ||r₁ - r₂|| / ||r₁ + r₂|| = 0.20227596478253429
first we need to find r_{1} - r_{2} and r_{1} + r_{2}.
in your example, these are:
r_{1} - r_{2} = (-3,2,0,4,5,6,-1,1,0,-5,-6,-7,-7,-8)
r_{1} + r_{2} = (5,2,6,4,5,6,1,5,6,5,6,7,9,10)
to find the norm, we dot these vectors with themselves (sum of squares) and then take the square root:
(r_{1} - r_{2}).(r_{1} - r_{2}) = 9+4+0+16+25+36+1+1+0+25+36+49+49 = 315
(r_{1} + r_{2}).(r_{1} + r_{2}) = 25+4+36+16+25+36+1+25+36+25+36+49+81+100 = 495
√(315/495) ~ 0.79772403521746564185512620976512
1 - √(315/495) ~ 0.20227596478253435814487379023488 to 4 decimal places this is 0.2023
where you went wrong on ||r_{1} - r_{2}|| is its not √(Σ_{i}(x_{i}^{2} - y_{i}^{2}) but rather √(Σ_{i}(x_{i}-y_{i})^{2})
that is a sum of the squares of the differences, not a sum of the differences of the squares, and similarly for ||r_{1} + r_{2}||
(and darn it, yvgeny, no fair using a program when i have to do this stuff by hand!)
Wow thanks a lot to the both of you. I was never good with Math but I never thought that there's still someone out there that would help me out here.
Oh by the way, do you mind telling me what program did you use for this? Can the program be used to calculate other algorithms as well?
I used OCaml programming language. The expression that computes Sr is
where r1 and r2 are lists of floats.Code:1. -. sqrt (fold_right (+.) (map sqr (map2 (-.) r1 r2)) 0.) /. sqrt (fold_right (+.) (map sqr (map2 (+.) r1 r2)) 0.);;
But this can be easily written in any decent programming language. It is also possible to use computational software like MATLAB and Octave, but I personally don't know them.