Week 2 Assignment - exercise 8 Model problem


I’m getting the below error after I execute the model. I thank its something with the optimize function but I am not sure. Can you please explain the error and why am I getting it? appreciate your help.

{moderator edit - solution code removed}

It is unnecessary to call propagate directly from model, right? It is called by optimize. Although it should do no harm …

Your other code looks correct. Are you sure that your optimize routine passed all the test cases? My guess about the nature of the problem is that you are somehow running more iterations than you should be. Maybe you hard-coded that down in the optimize logic and are ignoring the parameter value being passed down from model.

Thank you for the reply, actually my optimize function passed all the test and here is the output. Also, output of propagate and predict are below


Also, when I call the optimize function, i feed it the variables given in the arguments of model itself.

Notice that the incorrect value of costs that you got in the model test is exactly the same as the cost value that was returned by the test case for optimize: 0.15900538. That is too much of a coincidence. I think you must be referencing global variables from within your optimize function, but in a way that passes the optimize test case.

Or how about this as a theory: you misspelled the name of the variable that should be getting the return value of costs from the call to optimize in the model function, so it ends up picking up a previous global definition?

1 Like

Thank you so much!
I understood it now and updated the code accordingly, now everything is clear.