Comments (5)
That is generally the intent of this package, to serve as a single source of peak finding algorithms. However, I don't think that a straight port/replication of the MATLAB findpeaks
function (which as I understand it, is the implementation of the findpeaks
function in the pracma package) matches the typical Julian API style.
Also, the existing maxima
/minima
and peakprom
functions in Peaks.jl already cover much of the basic functionality*. Is there a particular feature from the MATLAB/R functions that you need that isn't already implemented here?
*Peak width is the only non-trivial functionality currently missing
from peaks.jl.
After a couple of hours playing around I still couldn't replicate the exact pracma findpeaks call with Peaks.jl (nor with FindPeaks.jl), so thats my motivation. I agree that the signature of pracmas findpeaks
is not at all what I would expect from a Julia function, but for the use case of helping R users migrate to Julia I personally would accept the wart.
Here is the code without docs:
function findpeaks(x::AbstractVector{T};
nups::Int=1,
ndowns::Int=nups,
zerostr::Char='0',
peakpat=nothing,
minpeakheight=typemin(T),
minpeakdistance::Int=1,
threshold=zero(T),
npeaks::Int=0,
sortstr=false) where T
zerostr ∉ ('0', '+', '-') && error("zero must be one of `0`, `-` or `+`")
# generate the peak pattern with no of ups and downs or use provided one
peakpat = Regex(peakpat === nothing ? "[+]{$nups,}[-]{$ndowns,}" : peakpat)
# transform x into a "+-+...-+-" character string
xs = String(map(diff(x)) do e
e < 0 && return '-'
e > 0 && return '+'
return zerostr
end)
# find index positions and maximum values
peaks = map(findall(peakpat, xs)) do m
v, i = findmax(@view x[m])
(;value=v, idx=first(m) + i - 1, start=first(m), stop=last(m) + 1)
end
# eliminate peaks that are too low
filter!(peaks) do p
p.value >= minpeakheight && p.value - max(x[p.start], x[p.stop]) >= threshold
end
# sort according to peak height
if sortstr || minpeakdistance > 1
sort!(peaks, by=x -> x.value; rev=true)
end
# find peaks sufficiently distant
if minpeakdistance > 1
removal = falses(length(peaks))
for i in 1:length(peaks)
removal[i] && continue
for j in 1:length(peaks)
removal[j] && continue
dist = abs(peaks[i].idx - peaks[j].idx)
removal[j] = 0 < dist < minpeakdistance
end
end
deleteat!(peaks, removal)
end
# Return only the first 'npeaks' peaks
npeaks > 0 && resize!(peaks, min(length(peaks), npeaks))
return peaks
end
from peaks.jl.
I agree; it doesn't look like our current functionality would be able to replicate that. Out of curiosity, could you share what your typical function call for findpeaks
(and desired output if convenient) would be?
The original author gave his OK
Was that OK also acknowledging the change of license? The Pracma package is GPL3 while Peaks.jl is MIT.
Assuming the change of license was approved, please open a PR! This definitely has some great new/different functionality.
from peaks.jl.
@laborg bravo. This is just what I need to translate phenofit into phenofit.jl (https://github.com/eco-hydro/phenofit/blob/master/R/findpeaks.R).
from peaks.jl.
Related Issues (10)
- Performance HOT 1
- TagBot trigger issue HOT 14
- Bibliography HOT 1
- add 4 to compat? HOT 2
- Functions are not importing HOT 1
- plotpeaks doesn't exist? HOT 2
- Findpeaks.jl
- Unusual behavior of peakprom? HOT 2
- peakprom can't find a peak within the minimum distance `w` of the boundary HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peaks.jl.