python-mle icon indicating copy to clipboard operation
python-mle copied to clipboard

Composition of random variables and parameters

Open ibab opened this issue 10 years ago • 8 comments

Users should be able to pass combinations of random variables and parameters to a model. This would allow them to build more models, e.g. for fitting a function to data. But how would this work?

x = var('x')
y = var('y')
a = par('a')
b = par('b')
sigma = par('sigma')
Normal(y, a * x + b, sigma)

ibab avatar Jan 30 '15 12:01 ibab

This is also needed for implementing the cdfs of the Distributions, needed for the statistical tests.

maxnoe avatar Jan 30 '15 21:01 maxnoe

Are you sure you can't do that by accessing the underlying theano variables with .tvar?

ibab avatar Jan 30 '15 21:01 ibab

Ah, that should help. But we could implement that in the classes themselves, like this:

def __mul__(self, object):
      object * self.tvar
def __rmul__(self, object):
     self.tvar * object

i'll implement this for all basic operations http://stackoverflow.com/questions/6892616/python-multiplication-override

maxnoe avatar Jan 30 '15 21:01 maxnoe

It might be more elegant to return theano expressions directly from var and par. Distribution would then need to be adjusted to work with that, but that would allow models like the one above.

ibab avatar Jan 30 '15 21:01 ibab

i overloaded the basic operators, kolmogorow smirnow tests works for now. We may find a more elegent solution .

maxnoe avatar Jan 30 '15 22:01 maxnoe

Then again, we will need to track extra information like bounds, so I don't see a way around implementing all the operators. But what do you get if you combine a variable and a parameter? Probably a variable if we want variables to be vectors and parameters to be scalars.

ibab avatar Jan 30 '15 22:01 ibab

Why did you memoize the function? It would make much more sense to call it pdf_compiled like the others and return the compiled pdf. You can then call self.pdf_compiled(...) to use it.

ibab avatar Jan 30 '15 22:01 ibab

I will change that

maxnoe avatar Jan 30 '15 22:01 maxnoe