ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Mar 2015 10:39:01 +0200How to use DiscreteRandomVariable covariance method?https://ask.sagemath.org/question/26379/how-to-use-discreterandomvariable-covariance-method/I'd like to take advantage of covariance() method of DiscreteRandomVariable class, yet, I can't find any example on the internet how to properly use it.
My understanding is that this should work:
text1 = AlphabeticStrings().encoding("AB")
text2 = AlphabeticStrings().encoding("BA")
text1freq = frequency_distribution(text1)
text2freq = frequency_distribution(text2)
text1freq.covariance(text2freq)
However, I receive unexpected ValueError:
/usr/lib/python2.7/site-packages/sage/probability/random_variable.pyc in covariance(self, other)
187 Omega = self.probability_space()
188 if Omega != other.probability_space():
--> 189 raise ValueError("Argument other (= %s) must be defined on the same probability space." % other)
190 muX = self.expectation()
191 muY = other.expectation()
ValueError: Argument other (= Discrete probability space defined by {A: 0.500000000000000, B: 0.500000000000000}) must be defined on the same probability space.
But... Logically (not technically) both text1freq and text2freq are the same probability space:
sage: text1freq
Discrete probability space defined by {A: 0.500000000000000, B: 0.500000000000000}
sage: text2freq
Discrete probability space defined by {A: 0.500000000000000, B: 0.500000000000000}
Mon, 30 Mar 2015 10:39:01 +0200https://ask.sagemath.org/question/26379/how-to-use-discreterandomvariable-covariance-method/