limix / glimix-core

Fast inference for Generalised Linear Mixed Models.
MIT License
11 stars 6 forks source link

ImportError: cannot import name 'FunctionReduce' #13

Closed jcr-lyxor closed 5 years ago

jcr-lyxor commented 5 years ago

Hi

I am trying to use the package, I have installed using conda and get the following error:

from optimix import FunctionReduce ImportError: cannot import name 'FunctionReduce

Although I understand how EP works I am still struggling in the implementation. Would you have a simple example using Logistic or Poisson regression with Gaussian priors please?

horta commented 5 years ago

Hi @jcr-lyxor ,

Does it solve if you do conda update glimix-core optimix ?

Have you seen the documentation?

jcr-lyxor commented 5 years ago

No it doesn't. FunctionReduce does not seem to be a part of optimix .

I had a look in the documentation. I just wonder if you could provide such simple example to help understand how it works.

horta commented 5 years ago

what are the versions of the installed glimix-core and optimix packages?

glimix_core.__version__ and optimix.__version__

jcr-lyxor commented 5 years ago

respectively 1.6.0and 3.0.3 under python 3.5.6.

horta commented 5 years ago

The current version of glimix-core is 3.1.7. It supports python 3.6 onwards but you could try it on 3.5 and see if it works: conda update -c conda-forge glimix-core

jcr-lyxor commented 5 years ago

It does't install/update 3.1.7, it is still glimix-core-1.6.0. I am under windows 10.

horta commented 5 years ago

glimix-core is platform independent. It might be because of python 3.5. Try: conda install -c conda-forge "glimix-core==3.1.7" What does it show?

Also, you can install glimix-core via pip. It works the same.

jcr-lyxor commented 5 years ago

I have issues with pip as well. For some reason liknorm is falling at install ERROR: Command "python setup.py egg_info" failed with error code 1

horta commented 5 years ago

I'm skipping py 3.5 build for liknorm python package: https://github.com/limix/liknorm-py/blob/master/.travis.yml#L6 I suggest updating your python: removing conda and installing it again from https://www.anaconda.com/distribution/ It will come with Python 3.7.

jcr-lyxor commented 5 years ago

Ok I try with 3.7 env. Thanks for looking a it.

About EP with for GLM with Gaussian prior would you have a simple example or/and could I solve it with this lib?

horta commented 5 years ago

See if https://glimix-core.readthedocs.io/en/latest/glmm.html helps.

jcr-lyxor commented 5 years ago

All good under py37. Thanks a lot.

I guess with G=0 I have what I want. Still if you have a simple script that helps to understand the steps that would be appreciated.

I

jcr-lyxor commented 5 years ago

Actually I am not sure because you are using Gaussian Processes under the wood for the moment matching?

For instance the following simulation gives me a solution far away:

from glimix_core.glmm import GLMMExpFam
import numpy as np

np.random.seed(115283)
beta_0 = 0.7
beta_1 = -1 
beta_2 = 0.5

N = 500
x = np.random.normal(0, scale=1, size=N)
x2 = np.random.normal(0, scale=1, size=N)

X = np.array([[1]*N, x, x2]).T

beta = np.array([beta_0, beta_1, beta_2])
true_mu = np.exp(X@beta)
n = 1
p = true_mu / (1 + true_mu)
y = np.random.binomial(n=n, p=p, size=N)

glm = GLMMExpFam(y,('Bernoulli' ),X)
glm.fit(verbose=False)
print(glm.beta)
[ 10.62991091 -15.15332283   7.80204789]

while statsmodel gives the right answer:

import statsmodels.api as sm
glm = sm.GLM(y,X,family=sm.families.Binomial())
res = glm.fit()
res.params
[ 0.88751168, -1.27477813,  0.65629759]

Am I missing something?

horta commented 5 years ago

Please, show the output that those lines produce.

Also, pay attention that GLMMExpFam is modelling a more complex model: there is an additional latent iid noise. (i dont know how sm.GLM is, but doesnt seem to include it). Make use of glm.v0 and glm.v1 to understand more the model and have a look at the third equation of https://glimix-core.readthedocs.io/en/latest/glmm.html .

horta commented 5 years ago

Also, note that you can set and keep fixed the variances of GLMM model.

jcr-lyxor commented 5 years ago

I have updated. Indeed GLMMExpFam is far more complex that is was I was asking for a simpler version of GLM+Gaussian prior before using it. I guess that corresponds to glm.v0 = 0 and glm.v1=1 and I do not want the latent so G=0. Stats model is just the normal maximum likelihood logistic regression.