octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: movfun


From: Juan Pablo Carbajal
Subject: Re: movfun
Date: Wed, 12 Dec 2018 13:19:30 +0100

On Wed, Dec 12, 2018 at 5:11 AM Rik <address@hidden> wrote:
>
> On 12/11/2018 06:41 PM, Juan Pablo Carbajal wrote:
> >> I think movfun.m should be transferred in to Mercurial in to 
> >> scripts/statistics/private as it is a helper function for the visible 
> >> functions above.
> >>
> >> --Rik
> >>
> > Hi Rik,
> > Thanks for the list, I can write the wrappers.
> >
> > I strongly disagree about movfun (and movslice) as private functions.
> > For me the the actually valuable contributions to octave are movfuin
> > and movslice. Also those are the functions I use in my work (the ones
> > form matlab are just simple calls to movfun).
> > If the community decision  is to make movfun private, then I will not
> > make anymore the effort to comply with the sometimes tedious octave
> > coding style and keep development outside octave. That is, the burden
> > of maintenance will 100% to the ones who decided to make it private,
> > and we will have diverging movfun in the environment.
>
> I assumed it should be private because it was only being used by the movXXX
> functions.
>
> What is an example use case where some other functions would want to call
> movfun or movslice?
>
> --Rik
>
>

Hi Rik,

Many are in the demo section of movfun. But in general any function
that is not in the ones provided by matlab, e.g. user functions. Lets
say you want a quantile on a moving window of size 9, there is no
mov*.m for that in matlab's repertoire, with movfun it is just q =
movfun (@(x)quantile(x, 0.15), X, 9)

I have just pushed the latest changes which allow to use functions
with multidimensional output here the code of the demo

%!demo
%! N    = 1e3;
%! wlen = 99;
%! x  = linspace (-1, 1, N).';
%! pp = [-2 0 1 0];
%! y  = polyval (pp, x);
%! yn = y + 0.1 * (abs (y) + 0.5) .* exp (randn (N, 1));
%!
%! st = movfun (@(y)statistics(y).', yn, wlen);
%! figure (), clf
%!    h = plot (x, y, '-',
%!              x, yn, '.',
%!              x, st(:,[3 6]), '-',
%!              x, st(:,6) + [-1 1].*st(:,7), '-',
%!              x, st(:,[1 2 4 5]), '-');
%!    set (h([1 3:4]), 'linewidth', 3); % mean
%!    set (h(5:end), 'color', 'k');
%!    axis tight
%!    xlabel ('x')
%!    ylabel ('y')
%!    legend (h, {'noiseless', 'noisy', 'mean', 'median'})
%! #####
%! # Moving window statistics. The plot highlights mean and median. black lines
%! # show minimum, first quartile, third quartile, and maximum.
%! # This illustrates the use of functions with multidimensional output.

This can be achieved in many other ways (some mentioned in the
docstring), but it might come handy to generate simpler and shorter
scripts.

movfun is not yet handling functions with multiple input arguments, I
haven't thought yet if this can be smoothly integrated or needs a
different function or branch inside movfun, so I do not know if movfun
will offer this in the future. To handle this situation I provide the
slicer function movslice. This way the user can implement their own
movfun that works with multiple input arguments. Also they can
implement their own unsafe movfun if they want to avoid some calling
overhead (mainly due to checks), or if they want to parallelize or
execute in batches some parts of the algorithm (for speed or due to
memory constraints).
The function movslice and reshapemod (as repelem, upsamplefill
(signal), and many others in OF packages) can be consider as basic
tools in a vectorizing toolbox.

I know the risk of implementing beyond matlab's functionalities, in
this case I deem it worth it.

Regards,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]