Changeset 229 for bdm/stat/emix.h

Show
Ignore:
Timestamp:
01/15/09 10:53:54 (15 years ago)
Author:
smidl
Message:

epdf has a new function: variance()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/emix.h

    r224 r229  
    104104                for ( i = 0;i < w.length();i++ ) {mu += w ( i ) * Coms ( i )->mean(); } 
    105105                return mu; 
     106        } 
     107        vec variance() const { 
     108                //non-central moment 
     109                vec mom2 = zeros(rv.count()); 
     110                for ( int i = 0;i < w.length();i++ ) {mom2 += w ( i ) * pow(Coms ( i )->mean(),2); } 
     111                //central moment 
     112                return mom2-pow(mean(),2); 
    106113        } 
    107114        double evallog ( const vec &val ) const { 
     
    243250                return tmp; 
    244251        } 
     252        vec variance() const { 
     253                vec tmp ( rv.count() ); //second moment 
     254                for ( int i=0;i<epdfs.length();i++ ) { 
     255                        vec pom = epdfs ( i )->mean(); 
     256                        dls ( i )->fill_val ( tmp, pow(pom,2) ); 
     257                } 
     258                return tmp-pow(mean(),2); 
     259        } 
    245260        vec sample() const { 
    246261                vec tmp ( rv.count() );