TransWikia.com

What is a good method for detecting local minims and maxims?

Data Science Asked by cristian hantig on July 1, 2021

I’m using kernel density estimation in order to compute
probability density function for item occurrence.

Using this output, i want to find all the local minims and maxims.
I’m interested in different methods for local-min/max extraction.

One Answer

One way to do it is to calculate first derivative (difference in discrete domain) and find where there is a change in the sign. That indicates the existence of a local minimum or maximum. For example:

from numpy import diff, sign, cos, pi, arange
import matplotlib.pyplot as plt
t = arange(0,2,0.01)
x = cos(2*pi*t)
# Find derivative of x
first_derivative = diff(x)

# Calc. sign difference
sign_diff = sign(first_derivative[1:]) - sign(first_derivative[:-1])

# Find local min and max
local_max_index = [i for i,k in enumerate(sign_diff) if k == -2]
local_min_index = [i for i,k in enumerate(sign_diff) if k == 2]

# plot results
plt.figure()
plt.plot(t,x)
plt.plot(t[local_max_index],x[local_max_index], 'ro')
plt.plot(t[local_min_index],x[local_min_index], 'ro')

enter image description here

Hope it helps!

Answered by Giannis Krilis on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP