Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poisson GLM #83

Closed
koenvandenberge opened this issue Sep 10, 2020 · 2 comments
Closed

Poisson GLM #83

koenvandenberge opened this issue Sep 10, 2020 · 2 comments

Comments

@koenvandenberge
Copy link

Hi,

Suppose that I'd like to fit a constrained Poisson GLM using CVXR, much like the logistic regression example in the documentation.
The program does not seem to optimize the function using either maximum likelihood formulation

    ## MWE
    library(CVXR)
    y <- rpois(n=100, lambda=50)
    X <- matrix(rnorm(100), ncol=1)
    betaHat <- Variable(1)
    obj <- sum(y* log(exp(X %*% betaHat)) - exp(X %*% betaHat))
    prob <- Problem(Maximize(obj))
    result <- CVXR::solve(prob)

or a Poisson loss formulation

    obj <- mean(exp(X %*% betaHat) - y * log(exp(X %*% betaHat)))
    prob <- Problem(Minimize(obj))
    result <- CVXR::solve(prob)

returning the error Error in construct_intermediate_chain(object, candidate_solvers, gp = gp) : Problem does not follow DCP rules. However, the problem does follow DGP rules. Consider calling this function with gp = TRUE. Setting gp=TRUE gives an opposite error.

Am I overlooking something?

@bnaras
Copy link
Collaborator

bnaras commented Sep 15, 2020

Not sure what you are trying to do with the logs/exp in the objective. See below. Both ways will yield the same result.

> y <- rpois(n=100, lambda=50)
> X <- matrix(rnorm(100), ncol=1)
> betaHat <- Variable(1)
> obj <- sum(y* X %*% betaHat - exp(X %*% betaHat))
> prob <- Problem(Maximize(obj))
> result <- CVXR::solve(prob)
> result$getValue(betaHat)
[1] 1.496695
> obj <- mean(exp(X %*% betaHat) - y * X %*% betaHat)
> prob <- Problem(Minimize(obj))
> result <- CVXR::solve(prob)
> result$getValue(betaHat)
[1] 1.496695

@koenvandenberge
Copy link
Author

I see, that's useful. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants