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

budget allocation---nloptr #92

Closed
wenyanyy opened this issue Jun 9, 2021 · 2 comments
Closed

budget allocation---nloptr #92

wenyanyy opened this issue Jun 9, 2021 · 2 comments

Comments

@wenyanyy
Copy link

wenyanyy commented Jun 9, 2021

Hi Robyn team,

Thank you so much for giving me lots of support. I totally understand function code. However, I am looking at Optm code and have few questions want to ask.

  1. build evaluation function : I saw you build evaluation function and use nloptr package to optimize. In evaluation function, eval_f, it return a list including objective, gradient, and objective.channel. In dt_optimOut table, I think we only use "eval_f(nlsMod$solution)[["objective.channel"]]" and didn't use objective and gradient. Could you please explain the reason of put objective and gradient? which step use objective and gradient?

  2. i tried eval_f (x) function and I think x would be spending, is it right? I found there are lots of negative results and what's the meaning for these negative results?

eval_f(4354198)
$objective
[1] -3636.619

$gradient
[1] -1.446742e-07 -5.093368e-06 -1.917148e-13 -5.276625e-07

$objective.channel
[1] -926.9574 -1314.6663 -492.3336 -902.6618

  1. after running nloptr and print result. I don't understand what is "Current value of controls" and how to get it?

###Result
NLopt solver status: 5 ( NLOPT_MAXEVAL_REACHED: Optimization stopped because maxeval (above) was reached.

Number of Iterations....: 100001
Termination conditions: xtol_rel: 1e-10 maxeval: 1e+05
Number of inequality constraints: 0
Number of equality constraints: 1
Current value of objective function: -167.973312354315
Current value of controls: 202304.2 23275.2 29175 57533.26

Sorry for list tons of questions here and really appreciated for explaining.

Best,
Regina

@gufengzhou
Copy link
Contributor

gufengzhou commented Jun 14, 2021

Hi Regina, no worries:) glad that you like it and want to know more.

  1. the nloptr library is gradient-based, meaning it solves the nonlinear function analytically using the gradient of the function, while gradient is just a collection of the partial derivatives of a multivariate function. In the f_eval, "objective" is the total objective function (it's revenue in our simulated data, or -sum(hill(chn1),hill(chn2), hill(chn3)...) as pseudo-code), "gradient" is the "partial derivative collection" and "objective channel" is just the partial objective for each variable in the objective function (in your example above, the sum of objective.channel equals the total objective). You need to specify all of them to run nloptr.
  2. yes, X is spend, or a vector of "variables" for the objective function. The negative value is just because nloptr is only doing minimisation. Our goal is to maximise total response, which is equal to minimising negative total response. That's why it's negative. Does it make sense?
  3. Regarding "controls", tbh I've also not really paid attention to that. Maybe looking into the vignette of the lib helps?

@Leonelsentana
Copy link
Contributor

Hi Regina,

Closing this issue as it has been a long time. Please raise a new one if you have further questions :)

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

3 participants