Global task for general understanding: I need to plot a result of my function f(x). Simple task, but there are two problems:
- For each value of x, f(x) takes much time to compute (tens of minutes or even aroud an hour).
- I don't know the estimated shape of f(x), therefore I don't know, how many x values I need in predefined x limits to represent the function correctly.
I want to update the plot of f(x) each time I get new f(x) value. I don't want to solve f(x) consequentially, I want to kind of increase level of detail, so every time I look on a plot, I see it over all of my (x_min, x_max) range, slowly updating within this range.
Therefore the question is: I need a function, which provides a list of x in proper order.
I came up with the following algorithm, inspired by binary search:
list
a of x values contains only unique values and it is sorted.
def dissort(a)
step = len(a) - 1
picked = [False for x in a]
out = []
while False in picked and step > 0:
for k in range(0, len(a), step):
if not picked[k]:
out.append(a[k])
picked[k] = True
step = step // 2
return out
in = [1, 2, 3, 4, 5, 6, 7, 8, 9]
out = [1, 9, 5, 3, 7, 2, 4, 6, 8]
assert(dissort(in) == out)
I see some flaws here: picked
array may be unnecessary, and picked values are unnecessarily checked every time level of detail increases. For now I'm happy with the performance, but in the future I can use it for much larger lists.
Is there a way to make it more performant? Is there an implementation in some python package already? I couldn't find it.