cvxgrp / CVXR

An R modeling language for convex optimization problems.

Home Page:https://cvxr.rbind.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elementwise exponential with different base

homairs opened this issue · comments

There is no atom for programming exponential with a different base (e.g., a^x, where a is a constant and x is a decision variable) as an objective function in CVXR. I get "Error in a^(1 - x): non-numeric argument to binary operator" error when I run the below code.

ibrary(CVXR)
a <- 7
b <- 0.3
M=1000
x_i # is a given vector of 1-D data

x <- Variable(1)
nominator <- (1-x)
denominator <- (1/((a^(1-x))-(b^(1-x))))
obj <- (-xsum(log(x_i)) + Mlog(nominator/denominator)) # change M to the length of X_i later
constr <- list(x>0)
prob <- Problem(Maximize(obj), constr)
result <- solve(prob)
alpha_hat <- result$getValue(x)

Unfortunately, such expressions are not supported in CVXR. You will need to do a log-transform or some other variable transformation.