I am using newton to optimize a longish cost function that takes in multiple arguments performs some calculations and compares the original value of a variable 'a' to a new version. However, each time newton iterates through the function I would also like it to update the value of another variable that it is not optimizing which also factors in to the calculation.
Essentially:
def func(a, ap, etc..)
perform calculations
a_1 = function of (a,ap,etc)
ap_1 = function of (a,ap,etc)
return (a - a_1)
and then
root = newton(func, a, args = (ap, etc..))
I would like ap to update to the value of ap_1 in each iteration of newton's Optimization.
Does anyone have any suggestions of how to do this?
I've tried to use a single array X = [a, ap] but I don't want ap to be optimized just a. I have also tried making ap a global variable and updating it inside the function I've defined but that doesn't seem to update within the newton's Optimization function.
We can use a
forloopto passscipy'soptimize.newtonfunction updated values ofb, and we'll make half the valuesNoneso that it is not factored in for those iterations:Outputs:
Whereas if
bis not factored in at all (i.e.b = None):Outputs:
And if
bis not updated:Outputs: