1

I am using CVXR to solve a concave objective function. The decision variable (x) is one-dimensional and the objective function is the summation of 2 logarithmic terms in which the second term is exponential with different bases of “a and b” (e.g., a^x, b^x); “a and b” are constants.

My full objective function is:

(-x*sum(ln(y))) + ln((1-x)/((a^(1-x))-(b^(1-x))))

where y is a given 1-D vector of data.

When I add the second term having (a^x and b^x) to the objective function, I keep getting

Error in a^(1 - x): non-numeric argument to binary operator

Is there any atom function in CVXR that can be used to code constant^x? Here is my code:

library(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)

Please tell me what I am doing wrong. I appreciate your help in advance.

1 Answers1

0

do some math

2=e^log2
2^x=(e^log2)^x=e^(log2*x)

So, you can try

denominator <- 1/(exp(log(a)*(1-x)) - exp(log(b)*(1-x)))
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Jeremy
  • 1