variance and standard deviation

Issue #222 resolved
Bita HashemiNezhad created an issue

I believe blaze has many types of matrix operations. I think it will be more comprehensive having some of the mathematics operations like variance and standard deviation. Do you have a plan to add them? Thanks

Comments (4)

  1. Klaus Iglberger

    Hi Bita!

    Thanks a lot for the suggestion. This indeed sounds like a reasonable addition to Blaze. We will consider it for one of the next releases. Thanks again,

    Best regards,

    Klaus!

  2. Klaus Iglberger

    I believe blaze has many types of matrix operations. I think it will be more comprehensive having some of the mathematics operations like variance and standard deviation. Do you have a plan to add them? Thanks

  3. Klaus Iglberger

    Summary

    The feature has been implemented, tested, optimized, and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.6.

    var()

    The variance of a dense or sparse vector or matrix can be computed via the `var() function. In case of a sparse vector or matrix, both the non-zero and zero elements are taken into account.

    Vector Example

    blaze::DynamicVector<int> v{ 1, 4, 3, 6, 7 };
    
    const double m = var( v );  // Results in 5.7
    

    Matrix Example

    blaze::DynamicMatrix<int> A{ { 1, 3, 2 }
                               , { 2, 6, 4 }
                               , { 9, 6, 3 } };
    
    const double v = var( A );  // Results in 6.5
    
    blaze::DynamicVector<double,blaze::columnVector> rv;
    blaze::DynamicVector<double,blaze::rowVector> cv;
    
    rv = var<rowwise>( A );     // Results in ( 1  4  9 )
    cv = var<columnwise>( A );  // Results in ( 19  3  1 )
    

    stddev()

    The standard deviation of a dense or sparse vector can be computed via the stddev() function. In case of a sparse vector, both the non-zero and zero elements are taken into account.

    Vector Example

    blaze::DynamicVector<int> v{ 1, 4, 3, 6, 7 };
    
    const double m = stddev( v );  // Results in 2.38747
    

    Matrix Example

    blaze::DynamicMatrix<int> A{ { 1, 3, 2 }
                               , { 2, 6, 4 }
                               , { 9, 6, 3 } };
    
    const double s = stddev( A );  // Results in sqrt(6.5)
    
    blaze::DynamicVector<double,blaze::columnVector> rs;
    blaze::DynamicVector<double,blaze::rowVector> cs;
    
    rs = stddev<rowwise>( A );     // Results in ( 1  2  3 )
    cs = stddev<columnwise>( A );  // Results in ( sqrt(19)  sqrt(3)  1 )
    
  4. Log in to comment