Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Approaches to debug:
There are 3 functions defined in the code, I checked the functions one
by one, and validated by plugging in trial parameters.
Firstly, I checked the syntax errors.
At the apply_optimizer() function, I deleted the "," following
"function_calls".
Currently, I didn't notice any runtime error. Then I checked the
semantic errors.
In the code of compare_optimizers(optimizers), I noticed that in the
for loop, "for optimizer in OPTIMIZERS:", since the parameter taken is
"optimizers", I changed it to "for optimizer in optimizers:"
After correcting the above error, I noticed that the total calls of
brentq, ridder, bisect algorithms were all 0, only the first
algorithm's number of calls output is around 602000. Actually, I'm
still not quite confident in explaining this. But this could possibly
be because the 2nd to 4th algorithms took the optimizer calculated from
the first algorithm as the initial value, so it reached the desired
value at the 1st iteration. I also tested this assumption by running
the two algorithms consecutively using some test numbers. This won't
compare the efficiency of the 4 algorithms, so I move the code of
creating random arrays random_a and random_b into the loop, so this
will let each algorithm's initial value to be different of the
optimizer.
In addition,I notice that the above code will throw valueError
excepetion when the interval [a,b] does not contain 0.