<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Cosine similarity, Pearson correlation, and OLS coefficients</title>
	<atom:link href="https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/feed/" rel="self" type="application/rss+xml" />
	<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/</link>
	<description>cognition, language, social systems; statistics, visualization, computation</description>
	<lastBuildDate>Tue, 25 Nov 2025 13:11:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: 相似性度量 - CSer之声</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-1680694</link>
		<dc:creator>相似性度量 - CSer之声</dc:creator>
		<pubDate>Tue, 01 Jul 2014 07:17:32 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-1680694</guid>
		<description><![CDATA[[...] 直观的解释是：如果 x 高的地方 y 也比较高， x 低的地方 y 也比较低，那么整体的内积是偏大的，也就是说 x 和 y 是相似的。举个例子，在一段长的序列信号 A 中寻找哪一段与短序列信号 a 最匹配，只需要将 a 从 A 信号开头逐个向后平移，每次平移做一次内积，内积最大的相似度最大。信号处理中 DFT 和 DCT 也是基于这种内积运算计算出不同频域内的信号组分（DFT 和 DCT 是正交标准基，也可以看做投影）。向量和信号都是离散值，如果是连续的函数值，比如求区间 [-1, 1] 两个函数之间的相似度，同样也可以得到（系数）组分，这种方法可以应用于多项式逼近连续函数，也可以用到连续函数逼近离散样本点（最小二乘问题， OLS coefficients ）中，扯得有点远了- -!。 [...]]]></description>
		<content:encoded><![CDATA[<p>[...] 直观的解释是：如果 x 高的地方 y 也比较高， x 低的地方 y 也比较低，那么整体的内积是偏大的，也就是说 x 和 y 是相似的。举个例子，在一段长的序列信号 A 中寻找哪一段与短序列信号 a 最匹配，只需要将 a 从 A 信号开头逐个向后平移，每次平移做一次内积，内积最大的相似度最大。信号处理中 DFT 和 DCT 也是基于这种内积运算计算出不同频域内的信号组分（DFT 和 DCT 是正交标准基，也可以看做投影）。向量和信号都是离散值，如果是连续的函数值，比如求区间 [-1, 1] 两个函数之间的相似度，同样也可以得到（系数）组分，这种方法可以应用于多项式逼近连续函数，也可以用到连续函数逼近离散样本点（最小二乘问题， OLS coefficients ）中，扯得有点远了- -!。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Building the connection between cosine similarity and correlation in R &#124; Question and Answer</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-1538995</link>
		<dc:creator>Building the connection between cosine similarity and correlation in R &#124; Question and Answer</dc:creator>
		<pubDate>Thu, 22 May 2014 14:24:16 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-1538995</guid>
		<description><![CDATA[[...] to some articles (e.g. here) correlation is just a centered version of cosine similarity. I use the following code to calculate [...]]]></description>
		<content:encoded><![CDATA[<p>[...] to some articles (e.g. here) correlation is just a centered version of cosine similarity. I use the following code to calculate [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waylon Flinn</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-758397</link>
		<dc:creator>Waylon Flinn</dc:creator>
		<pubDate>Wed, 11 Dec 2013 04:51:37 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-758397</guid>
		<description><![CDATA[Wonderful post. The more I investigate it the more it looks like every relatedness measure around is just a different normalization of the inner product.
Similar analyses reveal that Lift, Jaccard Index and even the standard Euclidean metric can be viewed as different corrections to the dot product. It&#039;s not a viewpoint I&#039;ve seen a lot of. It was this post that started my investigation of this phenomenon. For that, I&#039;m grateful to you.

The fact that the basic dot product can be seen to underlie all these similarity measures  turns out to be convenient. If you stack all the vectors in your space on top of each other to create a matrix, you can produce all the inner products simply by multiplying the matrix by it&#039;s transpose. Furthermore, the extra ingredient in every similarity measure I&#039;ve looked at so far involves the magnitudes (or squared magnitudes) of the individual vectors. These drop out of this matrix multiplication as well. Just extract the diagonal.

Because of it&#039;s exceptional utility, I&#039;ve dubbed the symmetric matrix that results from this product the base similarity matrix. I haven&#039;t been able to find many other references which formulate these metrics in terms of this matrix, or the inner product as you&#039;ve done. Known mathematics is both broad and deep, so it seems likely that I&#039;m stumbling upon something that&#039;s already been investigated.

Do you know of other work that explores this underlying structure of similarity measures? Is the construction of this base similarity matrix a standard technique in the calculation of these measures? Does it have a common name?

Thanks again for sharing your explorations of this topic.

P.S. Here&#039;s the other reference I&#039;ve found that does similar work:
http://arxiv.org/pdf/1308.3740.pdf]]></description>
		<content:encoded><![CDATA[<p>Wonderful post. The more I investigate it the more it looks like every relatedness measure around is just a different normalization of the inner product.<br />
Similar analyses reveal that Lift, Jaccard Index and even the standard Euclidean metric can be viewed as different corrections to the dot product. It&#8217;s not a viewpoint I&#8217;ve seen a lot of. It was this post that started my investigation of this phenomenon. For that, I&#8217;m grateful to you.</p>
<p>The fact that the basic dot product can be seen to underlie all these similarity measures  turns out to be convenient. If you stack all the vectors in your space on top of each other to create a matrix, you can produce all the inner products simply by multiplying the matrix by it&#8217;s transpose. Furthermore, the extra ingredient in every similarity measure I&#8217;ve looked at so far involves the magnitudes (or squared magnitudes) of the individual vectors. These drop out of this matrix multiplication as well. Just extract the diagonal.</p>
<p>Because of it&#8217;s exceptional utility, I&#8217;ve dubbed the symmetric matrix that results from this product the base similarity matrix. I haven&#8217;t been able to find many other references which formulate these metrics in terms of this matrix, or the inner product as you&#8217;ve done. Known mathematics is both broad and deep, so it seems likely that I&#8217;m stumbling upon something that&#8217;s already been investigated.</p>
<p>Do you know of other work that explores this underlying structure of similarity measures? Is the construction of this base similarity matrix a standard technique in the calculation of these measures? Does it have a common name?</p>
<p>Thanks again for sharing your explorations of this topic.</p>
<p>P.S. Here&#8217;s the other reference I&#8217;ve found that does similar work:<br />
<a href="http://arxiv.org/pdf/1308.3740.pdf" rel="nofollow">http://arxiv.org/pdf/1308.3740.pdf</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Machine learning literary genres from 19th century seafaring, horror and western novels &#124; Sub-Subroutine</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-741268</link>
		<dc:creator>Machine learning literary genres from 19th century seafaring, horror and western novels &#124; Sub-Subroutine</dc:creator>
		<pubDate>Sun, 08 Dec 2013 00:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-741268</guid>
		<description><![CDATA[[...] Cosine similarity: Each book is a vector (in the physics sense, not the computer science sense) starting from the origin and with a direction defined by it&#8217;s 30,682 features. The smaller the angle between two vectors = the more similar the texts. (There&#8217;s a clear discussion of the formula here). [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Cosine similarity: Each book is a vector (in the physics sense, not the computer science sense) starting from the origin and with a direction defined by it&#8217;s 30,682 features. The smaller the angle between two vectors = the more similar the texts. (There&#8217;s a clear discussion of the formula here). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Machine learning literary genres from 19th century seafaring, horror and western novels &#124; Sub-Sub Algorithm</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-737770</link>
		<dc:creator>Machine learning literary genres from 19th century seafaring, horror and western novels &#124; Sub-Sub Algorithm</dc:creator>
		<pubDate>Sat, 07 Dec 2013 10:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-737770</guid>
		<description><![CDATA[[...] Cosine similarity: Each book is a vector (in the physics sense, not the computer science sense) starting from the origin and with a direction defined by it&#8217;s 30,682 features. The smaller the angle between two vectors = the more similar the texts. (There&#8217;s a clear discussion of the formula here). [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Cosine similarity: Each book is a vector (in the physics sense, not the computer science sense) starting from the origin and with a direction defined by it&#8217;s 30,682 features. The smaller the angle between two vectors = the more similar the texts. (There&#8217;s a clear discussion of the formula here). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brendan O'Connor</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-314504</link>
		<dc:creator>Brendan O'Connor</dc:creator>
		<pubDate>Mon, 01 Apr 2013 22:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-314504</guid>
		<description><![CDATA[Hi Peter --

By &quot;invariant to shift in input&quot;, I mean, if you *add* to the input.  That is,
f(x, y) = f(x+a, y) for any scalar &#039;a&#039;.

By &quot;scale invariant&quot;, I mean, if you *multiply* the input by something.

For (1-corr), the problem is negative correlations.  I think maximizing the squared correlation is the same thing as minimizing squared error .. that&#039;s why it&#039;s called R^2, the explained variance ratio.

I don&#039;t understand your question about OLSCoef and have not seen the papers you&#039;re talking about.]]></description>
		<content:encoded><![CDATA[<p>Hi Peter &#8211;</p>
<p>By &#8220;invariant to shift in input&#8221;, I mean, if you *add* to the input.  That is,<br />
f(x, y) = f(x+a, y) for any scalar &#8216;a&#8217;.</p>
<p>By &#8220;scale invariant&#8221;, I mean, if you *multiply* the input by something.</p>
<p>For (1-corr), the problem is negative correlations.  I think maximizing the squared correlation is the same thing as minimizing squared error .. that&#8217;s why it&#8217;s called R^2, the explained variance ratio.</p>
<p>I don&#8217;t understand your question about OLSCoef and have not seen the papers you&#8217;re talking about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-312261</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 29 Mar 2013 03:24:12 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-312261</guid>
		<description><![CDATA[Useful info:

I have a few questions (i am pretty new to that field). You say correlation is invariant of shifts. 

i guess you just mean if the x-axis is not 1 2 3 4 but 10 20 30 or 30 20 10.. then it doesn&#039;t change anything.

but you doesn&#039;t mean that if i shift the signal i will get the same correlation right?

ex: [1 2 1 2 1] and [1 2 1 2 1], corr = 1
 but if i cyclically shift [1 2 1 2 1] and [2 1 2 1 2], corr = -1
or if i just shift by padding zeros [1 2 1 2 1 0] and [0 1 2 1 2 1] then corr = -0.0588

Please elaborate on that.

Also could we say that distance correlation (1-correlation) can be considered as norm_1 or norm_2 distance somehow? for example when we want to minimize the squared errors, usually we need to use euclidean distance, but could pearson&#039;s correlation also be used? 

Ans last, OLSCoef(x,y) can be considered as scale invariant? is very correlated to cosine similarity which is not scale invariant (Pearson&#039;s correlation is right?). Look at: &quot;Patterns of Temporal Variation in Online Media&quot; and &quot;Fast time-series searching with scaling and shifting&quot;. That confuses me.. but maybe i am missing something.]]></description>
		<content:encoded><![CDATA[<p>Useful info:</p>
<p>I have a few questions (i am pretty new to that field). You say correlation is invariant of shifts. </p>
<p>i guess you just mean if the x-axis is not 1 2 3 4 but 10 20 30 or 30 20 10.. then it doesn&#8217;t change anything.</p>
<p>but you doesn&#8217;t mean that if i shift the signal i will get the same correlation right?</p>
<p>ex: [1 2 1 2 1] and [1 2 1 2 1], corr = 1<br />
 but if i cyclically shift [1 2 1 2 1] and [2 1 2 1 2], corr = -1<br />
or if i just shift by padding zeros [1 2 1 2 1 0] and [0 1 2 1 2 1] then corr = -0.0588</p>
<p>Please elaborate on that.</p>
<p>Also could we say that distance correlation (1-correlation) can be considered as norm_1 or norm_2 distance somehow? for example when we want to minimize the squared errors, usually we need to use euclidean distance, but could pearson&#8217;s correlation also be used? </p>
<p>Ans last, OLSCoef(x,y) can be considered as scale invariant? is very correlated to cosine similarity which is not scale invariant (Pearson&#8217;s correlation is right?). Look at: &#8220;Patterns of Temporal Variation in Online Media&#8221; and &#8220;Fast time-series searching with scaling and shifting&#8221;. That confuses me.. but maybe i am missing something.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Correlation picture &#124; AI and Social Science &#8211; Brendan O&#039;Connor</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-304948</link>
		<dc:creator>Correlation picture &#124; AI and Social Science &#8211; Brendan O&#039;Connor</dc:creator>
		<pubDate>Mon, 18 Mar 2013 17:31:28 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-304948</guid>
		<description><![CDATA[[...] related to the the post on cosine similarity, correlation and OLS. Anyway, I was just struck by the following diagram. It almost has a pop-art [...]]]></description>
		<content:encoded><![CDATA[<p>[...] related to the the post on cosine similarity, correlation and OLS. Anyway, I was just struck by the following diagram. It almost has a pop-art [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brendano</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-304941</link>
		<dc:creator>brendano</dc:creator>
		<pubDate>Mon, 18 Mar 2013 17:17:49 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-304941</guid>
		<description><![CDATA[Great tip -- I remember seeing that once but totally forgot about it.

Here&#039;s a link, http://data.psych.udel.edu/laurenceau/PSYC861Regression%20Spring%202012/READINGS/rodgers-nicewander-1988-r-13-ways.pdf]]></description>
		<content:encoded><![CDATA[<p>Great tip &#8212; I remember seeing that once but totally forgot about it.</p>
<p>Here&#8217;s a link, <a href="http://data.psych.udel.edu/laurenceau/PSYC861Regression%20Spring%202012/READINGS/rodgers-nicewander-1988-r-13-ways.pdf" rel="nofollow">http://data.psych.udel.edu/laurenceau/PSYC861Regression%20Spring%202012/READINGS/rodgers-nicewander-1988-r-13-ways.pdf</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Moore</title>
		<link>https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/#comment-304935</link>
		<dc:creator>Paul Moore</dc:creator>
		<pubDate>Mon, 18 Mar 2013 17:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://brenocon.com/blog/?p=1199#comment-304935</guid>
		<description><![CDATA[A very helpful discussion - thanks.

Have you seen - &#039;Thirteen Ways to Look at the Correlation Coefficient&#039; by Joseph Lee Rodgers; W. Alan Nicewander, The American Statistician, Vol. 42, No. 1. (Feb., 1988), pp. 59-66.  It covers a related discussion.]]></description>
		<content:encoded><![CDATA[<p>A very helpful discussion &#8211; thanks.</p>
<p>Have you seen &#8211; &#8216;Thirteen Ways to Look at the Correlation Coefficient&#8217; by Joseph Lee Rodgers; W. Alan Nicewander, The American Statistician, Vol. 42, No. 1. (Feb., 1988), pp. 59-66.  It covers a related discussion.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.021 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2026-04-18 17:01:52 -->
