简体   繁体   中英

Variable as exponent in CVXPY objective function

I am trying to define a problem in CVXPY where the objective function uses a variable as the exponent. For example, minimise(\sum_i \sum_j (a_ij ^ x_ij)) where a_ij is a matrix of parameters and x_ij is an equivalently sized matrix of variables. I wish to perform the exponent calculation element-wise. I am unable to use numpy.power() as this is not compatible with CVXPY. Is there a function that will allow me to compute this with CVXPY expressions?

Use np.log() and cp.exp() like this.

import numpy as np
import cvxpy as cp

a = np.array([[1, 2], [3, 4]])
x = cp.Variable(a.shape)
objective = cp.Minimize(cp.sum(cp.exp(cp.multiply(np.log(a), x))))
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM