bayespy / bayespy

Bayesian Python: Bayesian inference tools for Python
bayespy.org
MIT License
686 stars 164 forks source link

About Logistic Function #99

Open zydmayday opened 7 years ago

zydmayday commented 7 years ago

Hi there! Very much thanks for this excellent package!

I got a problem in building Bayesian network.

Z = Categorical(Dirichlet(1e-1 * np.ones(cat_num)))

B = GaussianARD(0, 1e-6, shape=(C_dim,))
C = np.random.rand(C_dim, data_num)
P = Logistic(SumMultiply('i,i', B, C.T))

X = Mixture(Z, Bernoulli, P)

As the codes above, what I want to do is to build a net to get the Bernoulli distribution of X, where X's parent is Z and C, Z is a categorical distribution conditioned by Dirichlet prior distribution. And C is a vector data, with weights(parameters) B, I want to take the inner product of B and C and get a number, then use the logistic function to get the probability. It just looks like this: P = logistic(B^T, C).

I am not sure if the logistic function can be used like this, or there are some other ways to fix this problem.

Hope to get your response soon!

jluttine commented 7 years ago

Hi, thanks for the feedback. Unfortunately, BayesPy doesn't currently support non-conjugate operations. Logistic function is non-conjugate and it requires some extra approximations. I have it on my TODO list here: https://github.com/bayespy/bayespy/issues/54. However, I have no estimate when it might be implemented. So, for the time being, I'd advice you to use a different package (e.g., Stan, PyMC or Edward) for models with non-conjugacies. I'll leave this issue open as the support for logistic regression is missing but on the roadmap.

zydmayday commented 7 years ago

Thanks for your reply! I will try other packages instead. And also looking forward to your implement. Thanks again for the work!