简体   繁体   中英

Octave Functions

I've downloaded the " Data smoothing functions " from Octave forge and I think it was a great help but I need to make sure of something. does this function "rgdtsmcore" does smoothing by taking the backward two-point average ? if not,how do I modify it to make it so?

Code:

function out = rgdtsmcorewrap (log10lambda, x, y, d, mincell, varargin)

  if (nargin < 5)
    print_usage;
  endif

  lambda = 10^(log10lambda);

  if ( length(mincell) == 2 ) # using stdev to find optimal lambda
    stdev = mincell{2};
    yhat  = rgdtsmcore (x, y, d, lambda, varargin{:});

    xhatprov = 0;
    relative = 0;
    for i = 1:length(varargin)
      if strcmp(varargin{i},"relative")
        relative = 1;
      elseif strcmp(varargin{i},"xhat")
        xhatprov = 1;
        xhat = varargin{i+1};
      endif
    endfor

    if (xhatprov)
      idx = interp1(xhat,1:length(xhat),x,"nearest");
      if relative
        stdevd = std((y-yhat(idx))./y);
      else
        stdevd = std(y-yhat(idx));
      endif
    else
      if (relative)
        stdevd = std((y-yhat)./y);
      else
        stdevd = std(y-yhat);
      endif
    endif

    out = (stdevd - stdev)^2;

  else # use gcv to find optimal lambda
    [yhat, out] = rgdtsmcore (x, y, d, lambda, varargin{:});
  endif

endfunction

Thank you in advance...

I assume you mean averaging between the current point and one point before

t=pi*[0:.01:1];
x=sin(t)+rand(size(t))*.1; # data
y=zeros(size(x));
y(2:end)=(x(1:end-1)+x(2:end))/2; # 2 points average

subplot(3,1,1)
plot(t,x)
subplot(3,1,2)
plot(t,y)
subplot(3,1,3)
plot(t,x,t,y)

在此处输入图像描述

Of course there is no average for the first point

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM