Does Mathematica reuse previous computations?Efficient Langevin Equation SolverWhy does NSum fail here?Why does Mathematica evaluate Sin[2.0] but not Sin[2]?Mathematica does not calculate inverse fourier transformation or the convolution of two functionsDoes Mathematica get Pi wrong?Heron's Method of Square Root Calculation Issue with Previous SuggestionBasic 2D convolution with mathematicaConvolve does not excecutePrecision of computations done by PlotNDSolve involves previous time step value
What's causing this power spike in STM32 low power mode
Happy pi day, everyone!
My Graph Theory Students
Can a druid choose the size of its wild shape beast?
Life insurance that covers only simultaneous/dual deaths
How to deal with taxi scam when on vacation?
How to use deus ex machina safely?
What do Xenomorphs eat in the Alien series?
Why do passenger jet manufacturers design their planes with stall prevention systems?
Why is the BSI not using powers of two?
Is it normal that my co-workers at a fitness company criticize my food choices?
It's a yearly task, alright
What options are left, if Britain cannot decide?
What should tie a collection of short-stories together?
How do I hide Chekhov's Gun?
Are all passive ability checks floors for active ability checks?
Does Mathematica reuse previous computations?
Welcoming 2019 Pi day: How to draw the letter π?
Did Ender ever learn that he killed Stilson and/or Bonzo?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
If curse and magic is two sides of the same coin, why the former is forbidden?
What's the meaning of “spike” in the context of “adrenaline spike”?
Can I use USB data pins as power source
How to read the value of this capacitor?
Does Mathematica reuse previous computations?
Efficient Langevin Equation SolverWhy does NSum fail here?Why does Mathematica evaluate Sin[2.0] but not Sin[2]?Mathematica does not calculate inverse fourier transformation or the convolution of two functionsDoes Mathematica get Pi wrong?Heron's Method of Square Root Calculation Issue with Previous SuggestionBasic 2D convolution with mathematicaConvolve does not excecutePrecision of computations done by PlotNDSolve involves previous time step value
$begingroup$
I am doing an analysis of experimental results in which I need to repeat the same GaussianFilter hundred of times on different data. As explained in the documentation, GaussianFilter just convolves the data with a Gaussian kernel. Does it recompute the kernel every time I call the function, or will it somehow preserve and reuse the previous kernel? Would it be more efficient computationally for me to precompute the kernel (which I could do easily by applying GaussianFilter to a KroneckerDelta array), then do hundreds of ListConvolves instead of hundreds of GaussianFilters?
numerics convolution
$endgroup$
|
show 2 more comments
$begingroup$
I am doing an analysis of experimental results in which I need to repeat the same GaussianFilter hundred of times on different data. As explained in the documentation, GaussianFilter just convolves the data with a Gaussian kernel. Does it recompute the kernel every time I call the function, or will it somehow preserve and reuse the previous kernel? Would it be more efficient computationally for me to precompute the kernel (which I could do easily by applying GaussianFilter to a KroneckerDelta array), then do hundreds of ListConvolves instead of hundreds of GaussianFilters?
numerics convolution
$endgroup$
1
$begingroup$
My first guess is thatGaussianFilteremploys FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.
$endgroup$
– Henrik Schumacher
7 hours ago
2
$begingroup$
Best way would be to just try it and compare theRepeatedTimings.
$endgroup$
– Henrik Schumacher
7 hours ago
3
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
1
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
3
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
|
show 2 more comments
$begingroup$
I am doing an analysis of experimental results in which I need to repeat the same GaussianFilter hundred of times on different data. As explained in the documentation, GaussianFilter just convolves the data with a Gaussian kernel. Does it recompute the kernel every time I call the function, or will it somehow preserve and reuse the previous kernel? Would it be more efficient computationally for me to precompute the kernel (which I could do easily by applying GaussianFilter to a KroneckerDelta array), then do hundreds of ListConvolves instead of hundreds of GaussianFilters?
numerics convolution
$endgroup$
I am doing an analysis of experimental results in which I need to repeat the same GaussianFilter hundred of times on different data. As explained in the documentation, GaussianFilter just convolves the data with a Gaussian kernel. Does it recompute the kernel every time I call the function, or will it somehow preserve and reuse the previous kernel? Would it be more efficient computationally for me to precompute the kernel (which I could do easily by applying GaussianFilter to a KroneckerDelta array), then do hundreds of ListConvolves instead of hundreds of GaussianFilters?
numerics convolution
numerics convolution
asked 7 hours ago
Leon AveryLeon Avery
695318
695318
1
$begingroup$
My first guess is thatGaussianFilteremploys FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.
$endgroup$
– Henrik Schumacher
7 hours ago
2
$begingroup$
Best way would be to just try it and compare theRepeatedTimings.
$endgroup$
– Henrik Schumacher
7 hours ago
3
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
1
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
3
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
|
show 2 more comments
1
$begingroup$
My first guess is thatGaussianFilteremploys FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.
$endgroup$
– Henrik Schumacher
7 hours ago
2
$begingroup$
Best way would be to just try it and compare theRepeatedTimings.
$endgroup$
– Henrik Schumacher
7 hours ago
3
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
1
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
3
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
1
1
$begingroup$
My first guess is that
GaussianFilter employs FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.$endgroup$
– Henrik Schumacher
7 hours ago
$begingroup$
My first guess is that
GaussianFilter employs FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.$endgroup$
– Henrik Schumacher
7 hours ago
2
2
$begingroup$
Best way would be to just try it and compare the
RepeatedTimings.$endgroup$
– Henrik Schumacher
7 hours ago
$begingroup$
Best way would be to just try it and compare the
RepeatedTimings.$endgroup$
– Henrik Schumacher
7 hours ago
3
3
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
1
1
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
3
3
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
|
show 2 more comments
2 Answers
2
active
oldest
votes
$begingroup$
Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong.
Prepare the Gaussian kernel
n = 200000;
σ = .1;
t = Subdivide[-1. Pi, 1. Pi, n - 1];
ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2];
ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]];
Generate noisy function
u = Sin[t] + Cos[2 t] + 1.5 Cos[3 t] + .5 RandomReal[-1, 1, Length[t]];
The three methods with their timings:
kerhat = 2 Pi/Sqrt[N@n] Fourier[ker];
vConvolve = (2. Pi/n) ListConvolve[ker, u, -1, -1]; // RepeatedTiming // First
vFFT = Re[Fourier[InverseFourier[u] kerhat]]; // RepeatedTiming // First
vFilter = GaussianFilter[u, 1./(Pi) σ n, Padding -> "Periodic"]; // RepeatedTiming // First
0.0043
0.0057
0.054
ListLinePlot[u, vFFT, vFilter, vConvolve]

From further experiments with different values for n, GaussianFilter seems to be slower by a factor 10-20 over a wide range of n (from n = 1000 to n = 1000000). So it seems that it does use some FFT-based method (because it has the same speed asymptotics) but maybe some crucial part of the algorithm is not compiled (the factor 10 is somewhat an indicator for that) or does not use the fastest FFT implementation possible. A bit weird.
So, to my own surprise, your idea of computing the kernel once does help but for quite unexpected reasons.
$endgroup$
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
add a comment |
$begingroup$
It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance:
n = 5000;
data = RandomReal[-1, 1, n, 10000];
GaussianFilter[#, 100] & /@ data; // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100], i, n] // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100 + RandomInteger[-15, 15]], i, n] // AbsoluteTiming
The second line generates 5000 different sets of data, each 10000 length. The third applies one Gaussian filter to all the data sets. The third line applies a separate GaussianFilter to each set. The final line forces the GaussianFilter to recompute its kernel. The timings are pretty much the same. This suggests that whatever is happening, the time needed to calculate the Gaussian filter parameters is pretty negligeable.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193328%2fdoes-mathematica-reuse-previous-computations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong.
Prepare the Gaussian kernel
n = 200000;
σ = .1;
t = Subdivide[-1. Pi, 1. Pi, n - 1];
ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2];
ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]];
Generate noisy function
u = Sin[t] + Cos[2 t] + 1.5 Cos[3 t] + .5 RandomReal[-1, 1, Length[t]];
The three methods with their timings:
kerhat = 2 Pi/Sqrt[N@n] Fourier[ker];
vConvolve = (2. Pi/n) ListConvolve[ker, u, -1, -1]; // RepeatedTiming // First
vFFT = Re[Fourier[InverseFourier[u] kerhat]]; // RepeatedTiming // First
vFilter = GaussianFilter[u, 1./(Pi) σ n, Padding -> "Periodic"]; // RepeatedTiming // First
0.0043
0.0057
0.054
ListLinePlot[u, vFFT, vFilter, vConvolve]

From further experiments with different values for n, GaussianFilter seems to be slower by a factor 10-20 over a wide range of n (from n = 1000 to n = 1000000). So it seems that it does use some FFT-based method (because it has the same speed asymptotics) but maybe some crucial part of the algorithm is not compiled (the factor 10 is somewhat an indicator for that) or does not use the fastest FFT implementation possible. A bit weird.
So, to my own surprise, your idea of computing the kernel once does help but for quite unexpected reasons.
$endgroup$
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
add a comment |
$begingroup$
Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong.
Prepare the Gaussian kernel
n = 200000;
σ = .1;
t = Subdivide[-1. Pi, 1. Pi, n - 1];
ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2];
ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]];
Generate noisy function
u = Sin[t] + Cos[2 t] + 1.5 Cos[3 t] + .5 RandomReal[-1, 1, Length[t]];
The three methods with their timings:
kerhat = 2 Pi/Sqrt[N@n] Fourier[ker];
vConvolve = (2. Pi/n) ListConvolve[ker, u, -1, -1]; // RepeatedTiming // First
vFFT = Re[Fourier[InverseFourier[u] kerhat]]; // RepeatedTiming // First
vFilter = GaussianFilter[u, 1./(Pi) σ n, Padding -> "Periodic"]; // RepeatedTiming // First
0.0043
0.0057
0.054
ListLinePlot[u, vFFT, vFilter, vConvolve]

From further experiments with different values for n, GaussianFilter seems to be slower by a factor 10-20 over a wide range of n (from n = 1000 to n = 1000000). So it seems that it does use some FFT-based method (because it has the same speed asymptotics) but maybe some crucial part of the algorithm is not compiled (the factor 10 is somewhat an indicator for that) or does not use the fastest FFT implementation possible. A bit weird.
So, to my own surprise, your idea of computing the kernel once does help but for quite unexpected reasons.
$endgroup$
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
add a comment |
$begingroup$
Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong.
Prepare the Gaussian kernel
n = 200000;
σ = .1;
t = Subdivide[-1. Pi, 1. Pi, n - 1];
ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2];
ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]];
Generate noisy function
u = Sin[t] + Cos[2 t] + 1.5 Cos[3 t] + .5 RandomReal[-1, 1, Length[t]];
The three methods with their timings:
kerhat = 2 Pi/Sqrt[N@n] Fourier[ker];
vConvolve = (2. Pi/n) ListConvolve[ker, u, -1, -1]; // RepeatedTiming // First
vFFT = Re[Fourier[InverseFourier[u] kerhat]]; // RepeatedTiming // First
vFilter = GaussianFilter[u, 1./(Pi) σ n, Padding -> "Periodic"]; // RepeatedTiming // First
0.0043
0.0057
0.054
ListLinePlot[u, vFFT, vFilter, vConvolve]

From further experiments with different values for n, GaussianFilter seems to be slower by a factor 10-20 over a wide range of n (from n = 1000 to n = 1000000). So it seems that it does use some FFT-based method (because it has the same speed asymptotics) but maybe some crucial part of the algorithm is not compiled (the factor 10 is somewhat an indicator for that) or does not use the fastest FFT implementation possible. A bit weird.
So, to my own surprise, your idea of computing the kernel once does help but for quite unexpected reasons.
$endgroup$
Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong.
Prepare the Gaussian kernel
n = 200000;
σ = .1;
t = Subdivide[-1. Pi, 1. Pi, n - 1];
ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2];
ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]];
Generate noisy function
u = Sin[t] + Cos[2 t] + 1.5 Cos[3 t] + .5 RandomReal[-1, 1, Length[t]];
The three methods with their timings:
kerhat = 2 Pi/Sqrt[N@n] Fourier[ker];
vConvolve = (2. Pi/n) ListConvolve[ker, u, -1, -1]; // RepeatedTiming // First
vFFT = Re[Fourier[InverseFourier[u] kerhat]]; // RepeatedTiming // First
vFilter = GaussianFilter[u, 1./(Pi) σ n, Padding -> "Periodic"]; // RepeatedTiming // First
0.0043
0.0057
0.054
ListLinePlot[u, vFFT, vFilter, vConvolve]

From further experiments with different values for n, GaussianFilter seems to be slower by a factor 10-20 over a wide range of n (from n = 1000 to n = 1000000). So it seems that it does use some FFT-based method (because it has the same speed asymptotics) but maybe some crucial part of the algorithm is not compiled (the factor 10 is somewhat an indicator for that) or does not use the fastest FFT implementation possible. A bit weird.
So, to my own surprise, your idea of computing the kernel once does help but for quite unexpected reasons.
edited 1 hour ago
answered 6 hours ago
Henrik SchumacherHenrik Schumacher
56.6k577156
56.6k577156
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
add a comment |
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
1
1
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
IIRC, it's using a discrete Gaussian kernel, which involves non-compilable modified Bessel functions, so that might be the reason for the added computational effort you observe.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
$begingroup$
Yes, that is one reason I proposed using GaussianFilter itself to generate the kernel.
$endgroup$
– Leon Avery
6 hours ago
add a comment |
$begingroup$
It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance:
n = 5000;
data = RandomReal[-1, 1, n, 10000];
GaussianFilter[#, 100] & /@ data; // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100], i, n] // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100 + RandomInteger[-15, 15]], i, n] // AbsoluteTiming
The second line generates 5000 different sets of data, each 10000 length. The third applies one Gaussian filter to all the data sets. The third line applies a separate GaussianFilter to each set. The final line forces the GaussianFilter to recompute its kernel. The timings are pretty much the same. This suggests that whatever is happening, the time needed to calculate the Gaussian filter parameters is pretty negligeable.
$endgroup$
add a comment |
$begingroup$
It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance:
n = 5000;
data = RandomReal[-1, 1, n, 10000];
GaussianFilter[#, 100] & /@ data; // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100], i, n] // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100 + RandomInteger[-15, 15]], i, n] // AbsoluteTiming
The second line generates 5000 different sets of data, each 10000 length. The third applies one Gaussian filter to all the data sets. The third line applies a separate GaussianFilter to each set. The final line forces the GaussianFilter to recompute its kernel. The timings are pretty much the same. This suggests that whatever is happening, the time needed to calculate the Gaussian filter parameters is pretty negligeable.
$endgroup$
add a comment |
$begingroup$
It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance:
n = 5000;
data = RandomReal[-1, 1, n, 10000];
GaussianFilter[#, 100] & /@ data; // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100], i, n] // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100 + RandomInteger[-15, 15]], i, n] // AbsoluteTiming
The second line generates 5000 different sets of data, each 10000 length. The third applies one Gaussian filter to all the data sets. The third line applies a separate GaussianFilter to each set. The final line forces the GaussianFilter to recompute its kernel. The timings are pretty much the same. This suggests that whatever is happening, the time needed to calculate the Gaussian filter parameters is pretty negligeable.
$endgroup$
It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance:
n = 5000;
data = RandomReal[-1, 1, n, 10000];
GaussianFilter[#, 100] & /@ data; // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100], i, n] // AbsoluteTiming
Do[GaussianFilter[data[[i]], 100 + RandomInteger[-15, 15]], i, n] // AbsoluteTiming
The second line generates 5000 different sets of data, each 10000 length. The third applies one Gaussian filter to all the data sets. The third line applies a separate GaussianFilter to each set. The final line forces the GaussianFilter to recompute its kernel. The timings are pretty much the same. This suggests that whatever is happening, the time needed to calculate the Gaussian filter parameters is pretty negligeable.
answered 7 hours ago
bill sbill s
54.2k377155
54.2k377155
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193328%2fdoes-mathematica-reuse-previous-computations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
My first guess is that
GaussianFilteremploys FFT (FFT, multiply, inverse FFT). In this case, it would be a very bad idea to replace it by a convolution unless the convolution is also implemented by FFT: The naive way of convolution would require $O(n^2)$ flops for a vector of length $n$ while the FFT method would need only $O(n , log(n))$ flops.$endgroup$
– Henrik Schumacher
7 hours ago
2
$begingroup$
Best way would be to just try it and compare the
RepeatedTimings.$endgroup$
– Henrik Schumacher
7 hours ago
3
$begingroup$
@HenrikSchumacher I'm pretty sure ListConvolve also uses FFT (based on its performance).
$endgroup$
– Szabolcs
7 hours ago
1
$begingroup$
ListConvolve does indeed use FFT.
$endgroup$
– Leon Avery
6 hours ago
3
$begingroup$
Indeed it does.
$endgroup$
– J. M. is slightly pensive♦
6 hours ago