Hi.

On Mon, Jun 6, 2011 at 6:30 PM, Matthew Rocklin <[email protected]> wrote:
> Hi everyone,
>
> I'm working on implementing random variables in SymPy. The goal is to have
> them syntactically behave like normal variables but carry around more
> complex information like symbolic probability density functions (PDFs). I
> would like to be able to define X, a random variable and then define Y =
> sin(X), another random variable with transformed PDF.
>
> How should this be implemented? Should sin contain the logic to transform
> the PDF of X? Should it identify that X is_random and then push the work off
> someplace else? I'm hesitant to change anything too deeply in the core for
> the benefit of a relatively unused module.

Yes, I agree that special casing random variables in the functions
would be a bad design.

>
> In an ideal world the operand (in this case the random variable X) would be
> able to take control. This is the case for some functions like abs which
> just call the object’s __abs__ method. I can’t find any evidence that this
> is possible generally in the Python language although I’d be thrilled to
> find that I was incorrect.

I'm not sure what you mean by "in the Python language."  For this to
work, it would have to be implemented in SymPy.  So, for example, you
would have to make sin(x) call x._eval_sin() or something like that.
Quite a few functions in SymPy, like diff(), already do have a design
like this.  You would mainly just have to add it to Function.

>
> To achieve minimal disruption of the core I could always do something like
> X.applyfunc(sin) but this seems unpleasant to write. I think that matrices
> use this solution.  Another thought is to have elementary sympy functions
> check for an applyfunc method of their arguments and, if it exists, to use
> it. This would solve my problem and possibly be useful generally.

Another option would be to create your own sin() class, which would be
a RandomVariable.  I'm not entirely sure what sorts of things f(X)
would do, where f is some SymPy function and X is a RandomVariable, so
I can't really say what the best design is.  For example, does it make
sense to do f(X) for any function f or just certain ones (like sin())?
 Do you need sin(X) to act like sin(x) in any way (for example, should
diff(sin(X), X) work)?  These are the sorts of questions whose answers
will show what the best design for you is.

P.S., I vaguely remember discussing this, or something like this,
already.  Did we discuss this prior to your acceptance into GSoC?

Aaron Meurer

>
> Any thoughts or ideas on solutions? What is the correct way to solve this
> problem?
> Best,
> -Matt
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to