5
$\begingroup$

Context

Straight from the documentation of GaussianFilter, If one generates a time series and smooth it one gets

time series

res = Table[GaussianFilter[ts, r], {r, {10, 50, 100}}]; 
 ListLinePlot[Join[{ts}, res], 
 PlotLegends -> {"data", "r = 10", "r = 50", "r = 100"}]

time series and smoothed version

(if you want to generate random data you could use data = RandomFunction[WienerProcess[], {0, 1, 0.01}])

Problem

But if I extend the smoothing range from the example (admittedly in a rather unrealistic regime but bear with me)

data // Table[
   ListLinePlot[
    GaussianFilter[#, 10^R, Method -> "Gaussian", 
     Padding -> "Periodic"]], {R, 1, 4, 1/4}] &

extension

So you can see something rather odd which is that at larger smoothing radii the curve become less smooth (i.e it shows more local extrema)!

Question

Could you please confirm that this is a bug?

Workaround

FYI, a workaround is to use Fourier Filtering

fftIndgen[size_] := 2. Pi/ size ArrayPad[
   Range[0, Quotient[size, 2]], 
    {0, Quotient[size, 2] - 1}, 
   "ReflectedNegation"];
FourierGaussianFilter[data_, R_] := 
      InverseFourier[Fourier[data]*Exp[-1/2 R^2 
   fftIndgen[Length[data]]^2]] // Re // Chop

Then with

enter image description here

I get

 data//Table[ListLinePlot[FourierGaussianFilter[#, 10^R]],
{R, 1, 4, 1/4}] &

enter image description here

So in terms of diagnostic, one can visually see that GaussianFilter produces a growing number of extrema as a function of smoothing past a given threshold, whereas FourierGaussianFilter does not. IMHO the latter is behaving correctly in that regime, whereas the former does not. Note that this discrepancy can be made quantitative e.g. for Gaussian random fields, since there is a prediction for this number as a function of smoothing scale $R$ (i.e. it should scale like $1/R$).

$\endgroup$
  • $\begingroup$ Looking at the decreasing scale on the vertical axes, it's not clear to me that the curves are becoming less smooth. It does seem to me the series is approaching the mean of the data. Just how is smoothness measured? $\endgroup$ – Michael E2 May 7 '20 at 12:49
  • $\begingroup$ extrema identification $\endgroup$ – chris May 7 '20 at 13:50
  • $\begingroup$ I kinda thought it was supposed to reduce the variation/variance of something or other. But I don't know the formula. $\endgroup$ – Michael E2 May 7 '20 at 14:07
  • 3
    $\begingroup$ As Michael E2 said isn't it just the scale? If you fix the plot range then everything is smooth:data // Table[ ListLinePlot[ GaussianFilter[#, 10^R, Method -> "Gaussian", Padding -> "Periodic"], PlotRange -> {Min[data], Max[data]}], {R, 1, 4, 1/4}] & $\endgroup$ – demm May 7 '20 at 16:32
  • 1
    $\begingroup$ Does using Padding -> "Fixed" get you what you think you should get. Using Padding -> "Periodic" is probably not what you want. $\endgroup$ – JimB May 12 '20 at 22:28
3
$\begingroup$

I think it's that the option Padding -> "Periodic" doesn't get the behavior you want. Using Padding -> "Fixed" is probably what you want.

Here are the results using different scales for each radius:

SeedRandom[12345];
data = RandomFunction[WienerProcess[], {0, 1, 0.001}]
data // Table[ListLinePlot[GaussianFilter[#, 10^R, Method -> "Gaussian", Padding -> "Fixed"],
    PlotLabel -> "R = " <> ToString[10.^R]], {R, 1, 4, 1/4}] &

Separate scales

Now with same scales:

Same scales

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.