python-mle
python-mle copied to clipboard
Composition of random variables and parameters
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)
This is also needed for implementing the cdfs of the Distributions, needed for the statistical tests.
Are you sure you can't do that by accessing the underlying theano variables with .tvar
?
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
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.
i overloaded the basic operators, kolmogorow smirnow tests works for now. We may find a more elegent solution .
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.
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.
I will change that