octave-patch-tracker
[Top][All Lists]
Advanced

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

[Octave-patch-tracker] [patch #10103] Add weighted standard deviation fe


From: anonymous
Subject: [Octave-patch-tracker] [patch #10103] Add weighted standard deviation feature to 'std'
Date: Sun, 31 Oct 2021 08:43:06 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36

Follow-up Comment #9, patch #10103 (project octave):

So I made two patches for "var", the first one allows to compute weighted
variance, the second one allows to compute variance over an array splice (that
is on multiple dimensions) or on "all" dimensions. When using multiple
dimensions, including "all", weighted variance is not available, as it is for
the commercial counterpart of Octave.


octave:1> help var

 -- var (X)
 -- var (X, W)
 -- var (X, W, DIM)
 -- var (X, W, "ALL")
     Compute the variance of the elements of the vector X.

     The variance is defined as

          var (X) = 1/(N-1) SUM_i (X(i) - mean(X))^2

     where N is the length of the X vector.

     If X is a matrix, compute the variance for each column and return
     them in a row vector.

     The argument W determines the weighting scheme to use.  Valid
     values are

     0:
          normalize with N-1, provides the square root of the best
          unbiased estimator of the variance [default]

     1:
          normalize with N, this provides the square root of the second
          moment around the mean

     a vector:
          compute the weighted variance with nonnegative scalar weights,
          the length of W must be equal to the size of X along dimension
          DIM

     If N is equal to 1 the value of OPT is ignored and normalization by
     N is used.

     The optional variable DIM can be used to force 'var' to operate
     over the specified dimension.  DIM can either be a scalar dimension
     or a vector of non-repeating dimensions over which to operate.
     Dimensions are positive integers.  When DIM is a vector, W must be
     either 0 or 1, and the variance is calculated over the array slice
     defined by DIM.

     Specifying dimension "ALL" will force 'var' to operate on all
     elements of X, when W is either 0 or 1, and is equivalent to 'var
     (X(:))'.

     See also: cov, std, skewness, kurtosis, moment.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.


Usage of "all" and multiple dimensions:

octave:2> A = reshape ([1:8], 2, 2, 2);
octave:3> var(A, 0, [1 2])
ans =

ans(:,:,1) = 1.6667
ans(:,:,2) = 1.6667

octave:4> var(A, 0, [1 3])
ans =

   5.6667   5.6667

octave:5> var(A, 0 , 'all')
ans = 6
octave:6> var(A, 0, [1 2 3])
ans = 6



(file #52175, file #52176)
    _______________________________________________________

Additional Item Attachment:

File name: var.diff                       Size:5 KB
    <https://file.savannah.gnu.org/file/var.diff?file_id=52175>

File name: var_dims.diff                  Size:5 KB
    <https://file.savannah.gnu.org/file/var_dims.diff?file_id=52176>



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/patch/?10103>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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