Finding Minima of Functions (lib601.minima)¶
Procedures for finding values of a function to minimize its output.
-
lib601.minima.bisection(objective, xmin, xmax, threshold=0.0001, h=0.0001)¶ Find the local minimum of a function
objectivebetweenxminandxmaxusing the bisection method.Parameters: - objective – a function from a single numeric parameter to a single numeric output
- xmin – the minimum value of
objective’s parameter that should be considered - xmax – the maximum value of
objective’s parameter that should be considered - threshold – the desired precision of the answer (the “optimum”
parameter returned will be within
thresholdof the theoretical optimum parameter) - h – the “delta” to use when approximating the derivative of
objective
Returns: a tuple
(xBest,fBest), wherexBestis the value ofxfor whichf(x)is smallest (accurate to withinthresholdof the theoretical bestx), andfBestisobjective(xBest)
-
lib601.minima.linear(objective, xmin, xmax, numXsteps)¶ Find the local minimum of a function
objectivebetweenxminandxmaxusing a linear search.Parameters: - objective – A function that takes a single number
xas an argument and returns a numerical value. - xmin – The minimum value of
xto consider, inclusive. - xmax – The maximum value of
xto consider, inclusive. - numXsteps – The number of “steps” to try.
Returns: A tuple
(xBest, fBest).xBestis one of the numeric values achieved by starting atxminand takingnumXstepsequal-sized steps up toxmax. The particular value ofxreturned is the one for whichobjective(x)is minimized.- objective – A function that takes a single number