Commit 81f11b36 by Stefan Philips

[ADD] Mean calculation for WValue

[ADD] Median calculation for WValue
parent 36d32c50
......@@ -272,6 +272,31 @@ public:
return result;
}
/**
* Returns the mean value of all values stored in this WValue.
*/
T mean() const
{
WAssert( !m_components.empty(), "WValue has no entries." );
T sum = 0;
for ( typename std::vector< T >::const_iterator it = m_components.begin(); it != m_components.end(); it++ )
{
sum += ( *it );
}
return ( sum / static_cast< T >( m_components.size() ) );
}
/**
* Returns the median of all values stored in this WValue.
*/
T median() const
{
WAssert( !m_components.empty(), "WValue has no entries. " );
std::vector< T > components( m_components );
std::sort( components.begin(), components.end() );
return components[ components.size() / 2 ];
}
protected:
private:
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment