0

enter image description here

Assuming this line is made up of discrete random numbers in pandas. How can I find point A,B,C,D?

A is the highest point between the first point and C

C is the lowest point between A and B

B is the highest point between C and D

Another example could be like this enter image description here

You can use this data to test: [1, 2, 3, 10, 13, 15, 20, 50, 49, 49, 32, 33, 35, 36, 35, 34, 33, 34, 35, 36, 30, 27, 22, 15, 15, 17, 20, 27, 30, 32, 50, 56, 67, 85, 100, 99, 94, 83, 72, 59, 66, 67, 89, 90, 92, 127, 130, 189]

For the data above:

A = 50

B = 100

C = 15

D = 59

NNNNNNN
  • 29
  • 1
  • 7

1 Answers1

0

If you're certain that the line is continuous (it doesn't have to be smooth), you could use a discrete gradient search by using a finite difference.

If you start to the left of A, you could calculate (y[i+1]-y[i]) (I'm omitting division by h because it's irrelevant for this purpose.) Just check if that's positive. And if it is, move forward and calculate it again. Actually, it would be easier to just write it.

def find_a():
    i=toTheLeftOfA
    done=false
    while not done:
        if y[i-1]-y[i]>0:
            i=i+1
        else:
            done=true
    return([i,y[i]])
## retrieve [X,Y(X)=A] as find_a()

I'm sure there are more clever things, like a binary search. But as long as you only have to do it once and not a million times every hour, this should work.

D. Kupra
  • 343
  • 1
  • 9
  • It's not continuous, thank you though – NNNNNNN Sep 09 '21 at 23:55
  • Right of course. I mean no curve stored as vectors is "continuous". But if it's monotonic for long stretches, and those stretches are divided by your points of interest, then this is essentially what a library would call logically. And if the curve isn't monotonic for long stretches, then the points you've described are likely abundant and not very interesting. – D. Kupra Sep 10 '21 at 00:02