Re: [julia-users] Deducing probability density functions from model equations

2015-07-21 Thread John Myles White
There's tons of WIP-code that implements arithmetic on Distributions. No 
one has the time to finish that code or volunteer to maintain it, so it's 
just sitting in limbo.

OP: What you're asking for sounds like it's largely equivalent to 
probabilistic programming. There are a ton of ways you could implement it, 
but it's almost surely a mistake to implement this sort of thing on your 
own. I would encourage you to learn Stan (which you can call from Julia), 
which is a formal language for specifying joint probability distributions. 
A Stan encoding of your probability model will allow you to draw samples 
from arbitrary conditional distributions by conditioning on observed data.

On Tuesday, July 21, 2015 at 6:43:05 AM UTC-7, Tamas Papp wrote:

 In general, f(x,theta) does not necessarily belong to any 
 frequently used distribution family, even if theta does -- it is 
 easy to come up with examples. 

 Some distribution families are closed under certain operations (eg 
 addition, and multiplication by scalars for the normal), and some 
 distributions arise as transformations of other distributions (eg 
 chi square from normal, etc). AFAIK Distributions.jl does not 
 support arithmetic on distributions, but you can always try 
 programming the relevant generic functions, eg + for (Real, 
 Distributions.Normal) if the results of your transformations are 
 distributions in Distribution.jl. 

 Best, 

 Tamas 

 On Tue, Jul 21 2015, amik...@gmail.com wrote: 

  Dear all, 
  
  I don't know if that's the best place to ask such a question but 
  I'll give  it a try: I need to code stochastic models: 
  
  xnplus1 = f(xn, theta) 
  
  where xn is the state of my system at time n and theta is a set 
  of  parameters for this model, constant through time, and 
  possibly containing  noise. As a matter of example, let's 
  consider the following model: 
  
  function transition(n, xn, theta) 
  e = rand(Normal(theta.mu, theta.sigma)) xnplus1 = xn + e 
  return xnplus1 
  end 
  
  My goal is to write such equations and to deduce automatically 
  the  transition probability density function: 
  
  p(xnplus1 | xn, theta). 
  
  I intended to parse the code of the model and look for the 
  rand keyword,  the name of the law used to generate this 
  random variable and the values  given to it. In the previous 
  case, I could deduce that: 
  
  p(xnplus1 | xn, theta) = normal_pdf(xnplus1, xn + theta.mu, 
  theta.sigma) 
  
  where 
  
  normal_pdf(x, mu, sigma) = 1 / (sigma * sqrt(2 * pi)) * exp( - 1 
  / 2 * (x -  mu) ^ 2 / sigma ^ 2) 
  
  (rather) easily I think by specifying that whenever a constant 
  is added to  a normal variable, the mean of the new variable 
  (left value in the  equation) is normal and of mean increased by 
  this constant and of the same  standard deviation. But that's 
  the simplest case of all and it requires me  to specify some 
  rules about the normal distribution. 
  
  I therefore have the following questions: - is what I'm trying 
  to do understandable?  - is it doable at all? and in Julia?  - 
  is specifying rules for each distribution (normal, uniform, 
  Poisson;  correlated, uncorrelated) the way to go or should I 
  think of something even  more generic?  - do you have any other 
  suggestions to solve this problem? 
  
  Thank you very much, 



[julia-users] Deducing probability density functions from model equations

2015-07-21 Thread amiksvi
Dear all,

I don't know if that's the best place to ask such a question but I'll give 
it a try: I need to code stochastic models:

xnplus1 = f(xn, theta)

where xn is the state of my system at time n and theta is a set of 
parameters for this model, constant through time, and possibly containing 
noise. As a matter of example, let's consider the following model:

function transition(n, xn, theta)
e = rand(Normal(theta.mu, theta.sigma))
xnplus1 = xn + e
return xnplus1
end

My goal is to write such equations and to deduce automatically the 
transition probability density function:

p(xnplus1 | xn, theta).

I intended to parse the code of the model and look for the rand keyword, 
the name of the law used to generate this random variable and the values 
given to it. In the previous case, I could deduce that:

p(xnplus1 | xn, theta) = normal_pdf(xnplus1, xn + theta.mu, theta.sigma)

where

normal_pdf(x, mu, sigma) = 1 / (sigma * sqrt(2 * pi)) * exp( - 1 / 2 * (x - 
mu) ^ 2 / sigma ^ 2)

(rather) easily I think by specifying that whenever a constant is added to 
a normal variable, the mean of the new variable (left value in the 
equation) is normal and of mean increased by this constant and of the same 
standard deviation. But that's the simplest case of all and it requires me 
to specify some rules about the normal distribution.

I therefore have the following questions:
- is what I'm trying to do understandable?
- is it doable at all? and in Julia?
- is specifying rules for each distribution (normal, uniform, Poisson; 
correlated, uncorrelated) the way to go or should I think of something even 
more generic?
- do you have any other suggestions to solve this problem?

Thank you very much,


Re: [julia-users] Deducing probability density functions from model equations

2015-07-21 Thread Tamas Papp
In general, f(x,theta) does not necessarily belong to any 
frequently used distribution family, even if theta does -- it is 
easy to come up with examples.


Some distribution families are closed under certain operations (eg 
addition, and multiplication by scalars for the normal), and some 
distributions arise as transformations of other distributions (eg 
chi square from normal, etc). AFAIK Distributions.jl does not 
support arithmetic on distributions, but you can always try 
programming the relevant generic functions, eg + for (Real, 
Distributions.Normal) if the results of your transformations are 
distributions in Distribution.jl.


Best,

Tamas

On Tue, Jul 21 2015, amik...@gmail.com wrote:


Dear all,

I don't know if that's the best place to ask such a question but 
I'll give  it a try: I need to code stochastic models:


xnplus1 = f(xn, theta)

where xn is the state of my system at time n and theta is a set 
of  parameters for this model, constant through time, and 
possibly containing  noise. As a matter of example, let's 
consider the following model:


function transition(n, xn, theta) 
e = rand(Normal(theta.mu, theta.sigma)) xnplus1 = xn + e 
return xnplus1 
end


My goal is to write such equations and to deduce automatically 
the  transition probability density function:


p(xnplus1 | xn, theta).

I intended to parse the code of the model and look for the 
rand keyword,  the name of the law used to generate this 
random variable and the values  given to it. In the previous 
case, I could deduce that:


p(xnplus1 | xn, theta) = normal_pdf(xnplus1, xn + theta.mu, 
theta.sigma)


where

normal_pdf(x, mu, sigma) = 1 / (sigma * sqrt(2 * pi)) * exp( - 1 
/ 2 * (x -  mu) ^ 2 / sigma ^ 2)


(rather) easily I think by specifying that whenever a constant 
is added to  a normal variable, the mean of the new variable 
(left value in the  equation) is normal and of mean increased by 
this constant and of the same  standard deviation. But that's 
the simplest case of all and it requires me  to specify some 
rules about the normal distribution.


I therefore have the following questions: - is what I'm trying 
to do understandable?  - is it doable at all? and in Julia?  - 
is specifying rules for each distribution (normal, uniform, 
Poisson;  correlated, uncorrelated) the way to go or should I 
think of something even  more generic?  - do you have any other 
suggestions to solve this problem?


Thank you very much,