Hi guys,

I am running a costly simulation and trying to optimize the output. I'd have a fixed range over which the parameter of interest can vary, and about 100 values it can take in between. We know the result we are looking for and want to find the parameter value that comes closest to this. Instead of iterating the parameter incrementally, from say 0 to 100, I'd like to implement some sort of binary search algorithm. I am sure there is a "best" value on this range, so there's no need to worry about duplicate values.

The algorithm in my head should go something like:

Parameter low bound (p=0): Value known
Parameter high bound (p=100): Value known

Compare=0-50 and 50-100

Choose range at which best estimate is found. For example 0-50 is closest.

Bisect this range again...
0-25 vs. 25-50

Can anyone recommend a module or something that is suited to this type of thing? I know bisect is the module of choice for binary searches, but am having trouble seeing exactly which aspects of it are suitable to my needs.

Thanks.

I would try the root solvers in scipy.optimize first (like scipy.optimize.fsolve or scipy.optimize.bisect, etc...).

Theoretically speaking, this problem depends mainly on the monotonicity properties of the values in your array. Are they increasing or decreasing values, or randomly chosen values (or something else?). These properties should govern your strategy. For example I don't understand

Compare=0-50 and 50-100.

What will you compare ?

I posted simple snippet of basic search for root value in Code Snippets

Ok thanks guys. Let me look at your suggestions, reevaluate my problem, then come back if I still have questions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.