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.Wed, 16 Dec 2015 20:18:00 +0100How to use the DiscreteRandomVariable class?https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/The [reference manual](http://doc.sagemath.org/html/en/reference/probability/sage/probability/random_variable.html#sage.probability.random_variable.DiscreteRandomVariable ) talks about DiscreteRandomVariable class. But, I do not understand how it should be initialized? There are variables "X" and "f" but the docs do not explain what they are, nor there is any example...
Additionally: is it possible to calculate functions on DiscreteRandomVariables? E.g, if X and Y are random variables, can I write "Z = X * Y" and have a new random variable Z?
Sun, 29 Nov 2015 16:52:11 +0100https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/Comment by vdelecroix for <p>The <a href="http://doc.sagemath.org/html/en/reference/probability/sage/probability/random_variable.html#sage.probability.random_variable.DiscreteRandomVariable ">reference manual</a> talks about DiscreteRandomVariable class. But, I do not understand how it should be initialized? There are variables "X" and "f" but the docs do not explain what they are, nor there is any example...</p>
<p>Additionally: is it possible to calculate functions on DiscreteRandomVariables? E.g, if X and Y are random variables, can I write "Z = X * Y" and have a new random variable Z?</p>
https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31296#post-id-31296This class seems to be in pretty bad shape. I guess that we would better get rid of it. Moreover, for defining two random variables you need a common probability space. And the law of X*Y highly depends on the correlations between X and Y. Were you thinking about the independent case?Thu, 03 Dec 2015 21:38:39 +0100https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31296#post-id-31296Comment by Erel Segal-Halevi for <p>The <a href="http://doc.sagemath.org/html/en/reference/probability/sage/probability/random_variable.html#sage.probability.random_variable.DiscreteRandomVariable ">reference manual</a> talks about DiscreteRandomVariable class. But, I do not understand how it should be initialized? There are variables "X" and "f" but the docs do not explain what they are, nor there is any example...</p>
<p>Additionally: is it possible to calculate functions on DiscreteRandomVariables? E.g, if X and Y are random variables, can I write "Z = X * Y" and have a new random variable Z?</p>
https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31578#post-id-31578@vdelecroix Yes, I was thinking about the independent case, For example, suppose X is a discrete random variable with the following distribution: {10: 0.3, 20: 0.7} and Y is discrete random variable with the following distribution: {30: 0.4, 40: 0.6}. Then, Z=X*Y is a discrete random variable with the following distribution: {300: 0.12, 600: 0.28, 400: 0.18, 800: 0.42}. It seems quite straightforward to implement.Tue, 15 Dec 2015 13:18:09 +0100https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31578#post-id-31578Comment by vdelecroix for <p>The <a href="http://doc.sagemath.org/html/en/reference/probability/sage/probability/random_variable.html#sage.probability.random_variable.DiscreteRandomVariable ">reference manual</a> talks about DiscreteRandomVariable class. But, I do not understand how it should be initialized? There are variables "X" and "f" but the docs do not explain what they are, nor there is any example...</p>
<p>Additionally: is it possible to calculate functions on DiscreteRandomVariables? E.g, if X and Y are random variables, can I write "Z = X * Y" and have a new random variable Z?</p>
https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31609#post-id-31609Sure you can do
sage: X = {10: 0.3, 20: 0.7}
sage: Y = {30: 0.4, 40: 0.6}
sage: Z = defaultdict(lambda:0.0)
sage: for x,px in X.iteritems():
....: for y,py in Y.iteritems():
....: Z[x*y] += px*py
sage: Z
defaultdict(<function <lambda> at 0x7f3deebbb140>,
{400: 0.180000000000000,
800: 0.420000000000000,
300: 0.120000000000000,
600: 0.280000000000000})Wed, 16 Dec 2015 20:18:00 +0100https://ask.sagemath.org/question/31182/how-to-use-the-discreterandomvariable-class/?comment=31609#post-id-31609