Julia equivalent to movmean(array,window,dims)?
I am using julia 0.7.0, NCDatasets.jl and Images.jl on a linux box to analize a dataset of around 80GB. I don't load a lot of variables and the first step is to do the equivalent of matlab's
a = moveman(movemean(movemean(array,window,1),window,2),window,4))
where array is a (256,256,80,600) float array. For this, I am trying the line:
filtered = imfilter(array, centered(ones(window_h,window_h,1,window_t)/(window_t*window_h*window_h)),Inner())
However, this results in terabytes of allocations, which ends up using all my memory and taking ages. The matlab line works just fine and use an insignificant amount of time compared to that of my julia line, which suggests I am doing something in a non-optimal way.
Could someone provide any insight?
julia
add a comment |
I am using julia 0.7.0, NCDatasets.jl and Images.jl on a linux box to analize a dataset of around 80GB. I don't load a lot of variables and the first step is to do the equivalent of matlab's
a = moveman(movemean(movemean(array,window,1),window,2),window,4))
where array is a (256,256,80,600) float array. For this, I am trying the line:
filtered = imfilter(array, centered(ones(window_h,window_h,1,window_t)/(window_t*window_h*window_h)),Inner())
However, this results in terabytes of allocations, which ends up using all my memory and taking ages. The matlab line works just fine and use an insignificant amount of time compared to that of my julia line, which suggests I am doing something in a non-optimal way.
Could someone provide any insight?
julia
add a comment |
I am using julia 0.7.0, NCDatasets.jl and Images.jl on a linux box to analize a dataset of around 80GB. I don't load a lot of variables and the first step is to do the equivalent of matlab's
a = moveman(movemean(movemean(array,window,1),window,2),window,4))
where array is a (256,256,80,600) float array. For this, I am trying the line:
filtered = imfilter(array, centered(ones(window_h,window_h,1,window_t)/(window_t*window_h*window_h)),Inner())
However, this results in terabytes of allocations, which ends up using all my memory and taking ages. The matlab line works just fine and use an insignificant amount of time compared to that of my julia line, which suggests I am doing something in a non-optimal way.
Could someone provide any insight?
julia
I am using julia 0.7.0, NCDatasets.jl and Images.jl on a linux box to analize a dataset of around 80GB. I don't load a lot of variables and the first step is to do the equivalent of matlab's
a = moveman(movemean(movemean(array,window,1),window,2),window,4))
where array is a (256,256,80,600) float array. For this, I am trying the line:
filtered = imfilter(array, centered(ones(window_h,window_h,1,window_t)/(window_t*window_h*window_h)),Inner())
However, this results in terabytes of allocations, which ends up using all my memory and taking ages. The matlab line works just fine and use an insignificant amount of time compared to that of my julia line, which suggests I am doing something in a non-optimal way.
Could someone provide any insight?
julia
julia
asked Nov 15 '18 at 8:42
ARamirezARamirez
18119
18119
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
not quite familiar with matlab, guess it's moving average?
then it's linear, and to do movemean(movemean(movemean...
you may calculate an equation instead, like
( 3*array[current] + 3*array[current-1] + 2*array[current-2] )/8
and go through the array
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
add a comment |
To answer my own question, based on the discussion at Julia discourse: I continued using the Images package, in particular ImageFiltering in the following way.
First I define the kernel used to smooth.
This kernel will be used by computing the correlation between it and the array that we are filtering.
The difference by using factores kernels is that the each filter will be applied separately, which changes the number of operations from
window_h x window_h x window_t
to
window_h + window_h + window_t
As explained in the docs.
Note that the kernel uses [1.0] in the third dimension, because my array is a 4-dim array and I am smoothing on the first two and the fourth dimension.
using ImageFiltering
function kernel4d_2(window_h,window_t)
kernel_h = ones(window_h)/window_h
kernel_t = ones(window_t)/window_t
return kernelfactors((kernel_h, kernel_h, [1.0], kernel_t))
end
Then I defined a function to apply this kernel as a filter and return the filtered array.
function filter_array(array,window_x,window_t)
filtered = imfilter(array, kernel4d_2(window_x,window_t))
end
This allows to filter the array as:
filtered = filter_array(unfiltered,window_x,window_t)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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');
);
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%2fstackoverflow.com%2fquestions%2f53315389%2fjulia-equivalent-to-movmeanarray-window-dims%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
not quite familiar with matlab, guess it's moving average?
then it's linear, and to do movemean(movemean(movemean...
you may calculate an equation instead, like
( 3*array[current] + 3*array[current-1] + 2*array[current-2] )/8
and go through the array
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
add a comment |
not quite familiar with matlab, guess it's moving average?
then it's linear, and to do movemean(movemean(movemean...
you may calculate an equation instead, like
( 3*array[current] + 3*array[current-1] + 2*array[current-2] )/8
and go through the array
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
add a comment |
not quite familiar with matlab, guess it's moving average?
then it's linear, and to do movemean(movemean(movemean...
you may calculate an equation instead, like
( 3*array[current] + 3*array[current-1] + 2*array[current-2] )/8
and go through the array
not quite familiar with matlab, guess it's moving average?
then it's linear, and to do movemean(movemean(movemean...
you may calculate an equation instead, like
( 3*array[current] + 3*array[current-1] + 2*array[current-2] )/8
and go through the array
answered Nov 15 '18 at 10:18
Jason DJason D
285
285
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
add a comment |
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
Thanks, this is a good approach but it becomes difficult when you want to take larger windows.
– ARamirez
Nov 28 '18 at 22:27
add a comment |
To answer my own question, based on the discussion at Julia discourse: I continued using the Images package, in particular ImageFiltering in the following way.
First I define the kernel used to smooth.
This kernel will be used by computing the correlation between it and the array that we are filtering.
The difference by using factores kernels is that the each filter will be applied separately, which changes the number of operations from
window_h x window_h x window_t
to
window_h + window_h + window_t
As explained in the docs.
Note that the kernel uses [1.0] in the third dimension, because my array is a 4-dim array and I am smoothing on the first two and the fourth dimension.
using ImageFiltering
function kernel4d_2(window_h,window_t)
kernel_h = ones(window_h)/window_h
kernel_t = ones(window_t)/window_t
return kernelfactors((kernel_h, kernel_h, [1.0], kernel_t))
end
Then I defined a function to apply this kernel as a filter and return the filtered array.
function filter_array(array,window_x,window_t)
filtered = imfilter(array, kernel4d_2(window_x,window_t))
end
This allows to filter the array as:
filtered = filter_array(unfiltered,window_x,window_t)
add a comment |
To answer my own question, based on the discussion at Julia discourse: I continued using the Images package, in particular ImageFiltering in the following way.
First I define the kernel used to smooth.
This kernel will be used by computing the correlation between it and the array that we are filtering.
The difference by using factores kernels is that the each filter will be applied separately, which changes the number of operations from
window_h x window_h x window_t
to
window_h + window_h + window_t
As explained in the docs.
Note that the kernel uses [1.0] in the third dimension, because my array is a 4-dim array and I am smoothing on the first two and the fourth dimension.
using ImageFiltering
function kernel4d_2(window_h,window_t)
kernel_h = ones(window_h)/window_h
kernel_t = ones(window_t)/window_t
return kernelfactors((kernel_h, kernel_h, [1.0], kernel_t))
end
Then I defined a function to apply this kernel as a filter and return the filtered array.
function filter_array(array,window_x,window_t)
filtered = imfilter(array, kernel4d_2(window_x,window_t))
end
This allows to filter the array as:
filtered = filter_array(unfiltered,window_x,window_t)
add a comment |
To answer my own question, based on the discussion at Julia discourse: I continued using the Images package, in particular ImageFiltering in the following way.
First I define the kernel used to smooth.
This kernel will be used by computing the correlation between it and the array that we are filtering.
The difference by using factores kernels is that the each filter will be applied separately, which changes the number of operations from
window_h x window_h x window_t
to
window_h + window_h + window_t
As explained in the docs.
Note that the kernel uses [1.0] in the third dimension, because my array is a 4-dim array and I am smoothing on the first two and the fourth dimension.
using ImageFiltering
function kernel4d_2(window_h,window_t)
kernel_h = ones(window_h)/window_h
kernel_t = ones(window_t)/window_t
return kernelfactors((kernel_h, kernel_h, [1.0], kernel_t))
end
Then I defined a function to apply this kernel as a filter and return the filtered array.
function filter_array(array,window_x,window_t)
filtered = imfilter(array, kernel4d_2(window_x,window_t))
end
This allows to filter the array as:
filtered = filter_array(unfiltered,window_x,window_t)
To answer my own question, based on the discussion at Julia discourse: I continued using the Images package, in particular ImageFiltering in the following way.
First I define the kernel used to smooth.
This kernel will be used by computing the correlation between it and the array that we are filtering.
The difference by using factores kernels is that the each filter will be applied separately, which changes the number of operations from
window_h x window_h x window_t
to
window_h + window_h + window_t
As explained in the docs.
Note that the kernel uses [1.0] in the third dimension, because my array is a 4-dim array and I am smoothing on the first two and the fourth dimension.
using ImageFiltering
function kernel4d_2(window_h,window_t)
kernel_h = ones(window_h)/window_h
kernel_t = ones(window_t)/window_t
return kernelfactors((kernel_h, kernel_h, [1.0], kernel_t))
end
Then I defined a function to apply this kernel as a filter and return the filtered array.
function filter_array(array,window_x,window_t)
filtered = imfilter(array, kernel4d_2(window_x,window_t))
end
This allows to filter the array as:
filtered = filter_array(unfiltered,window_x,window_t)
edited Nov 28 '18 at 22:48
answered Nov 28 '18 at 22:39
ARamirezARamirez
18119
18119
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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%2fstackoverflow.com%2fquestions%2f53315389%2fjulia-equivalent-to-movmeanarray-window-dims%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');
);
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');
);
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');
);
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