Optimize a probability distribution to maximize a sum of coefficients on logprobs
AnsweredHello Gurobi,
I would really appreciate any advice on (1) numerical stability and (2) vectorized code speed.
I'm trying to optimize a huge probability distribution, but my rewards are in logspace. I am maximizing the sum of weighted logprobabilities.
To approach the problem, I made auxiliary variables constrained with addGenConstrExp, and then constrained those auxiliary variables (the exponentiated logprobs) to sum to <=1. Unfortunately, it doesn't seem addGenConstrExp is vectorized, so that has to be very slow python forloop. Is there any way to vectorize it?
When I reward each of three probability categories equally, the result is is [31.5%, 35%,31.5%], which seems regrettably far from 33.33% each.
My code currently functions without throwing an error—my first work in gurobipy—but I hope there are some numerical tricks for both speedup and accuracy.
Here the working code, with just the need to supply a different WLS license:
https://colab.research.google.com/drive/1X4oOYIk4Hv3I74g08yfk8zmOKENZAU5C?usp=sharing

Hi David,
Gurobi matrix variables are not yet compatible with the addGenConstrExp method in Gurobi 11.0.3. You can use the tolist function and add the general constraints over the for loop. For the accuracy of the result, please try using the parameter FuncNonLinear=1. With this setting, the general constraints in your model will be handled inside the branchandbound tree using a dynamic outerapproximation approach instead of the default piecewise linear approximations.Otherwise, you can control the granularity of the piecewise approximations using the parameters such as FuncPieces and FuncPieceError.
Best regards,
Simran0 
Thanks for the quick help!
0
Please sign in to leave a comment.
Comments
2 comments