14 Aug 21:39
Finding local minima of greater than a given depth
From: Zane Selvans <zane <at> ideotrope.org>
Subject: Finding local minima of greater than a given depth
Newsgroups: gmane.comp.python.scientific.user
Date: 2008-08-14 19:40:18 GMT
Subject: Finding local minima of greater than a given depth
Newsgroups: gmane.comp.python.scientific.user
Date: 2008-08-14 19:40:18 GMT
Is there a function within scipy somewhere which will, given an array
representing values of a function, find all the local minima having a
depth greater than some specified minimum? The following works great
for smooth functions, but when the data has noise in it, it also
returns all of the (very) local minima, which I don't want. The
functions I'm working with are periodic (hence the modulo in the
indices for endpoint cases). Or, if there isn't such a built in
functionality, what's the right way to measure the depth of a local
minimum?
def local_minima(fitlist):
minima = []
for i in range(len(fitlist)):
if fitlist[i] < fitlist[mod(i+1,len(fitlist))] and fitlist[i]
< fitlist[mod(i-1,len(fitlist))]:
minima.append(fitlist[i])
minima.sort()
good_indices = [ fitlist.index(fit) for fit in minima ]
good_fits = [ fit for fit in minima ]
return(good_indices, good_fits)
--
Zane Selvans
Amateur Earthling
http://zaneselvans.org
zane <at> ideotrope.org
303/815-6866
PGP Key: 55E0815F
RSS Feed