twoDimensionalStatistics.cc
Go to the documentation of this file.
/* TwoDimensionalStatistics.cc
*/
#include "osl/stat/twoDimensionalStatistics.h"
#include "osl/stat/average.h"
#include <cmath>
class osl::stat::TwoDimensionalStatistics::Data
{
public:
Average m_x, m_y, m_x2, m_y2, m_xy;
// MANIPULATORS
void add(const double& x, const double& y)
{
m_x.add(x);
m_y.add(y);
m_x2.add(x*x);
m_y2.add(y*y);
m_xy.add(x*y);
}
void merge(const Data& r)
{
m_x.merge(r.m_x);
m_y.merge(r.m_y);
m_x2.merge(r.m_x2);
m_y2.merge(r.m_y2);
m_xy.merge(r.m_xy);
}
void clear()
{
m_x.clear();
m_y.clear();
m_x2.clear();
m_y2.clear();
m_xy.clear();
}
};
// CREATORS
osl::stat::TwoDimensionalStatistics::
TwoDimensionalStatistics() : m_data(new Data())
{
}
osl::stat::TwoDimensionalStatistics::
~TwoDimensionalStatistics()
{
}
// MANIPULATORS
void osl::stat::TwoDimensionalStatistics::
add(const double& x, const double& y)
{
m_data->add(x,y);
}
void osl::stat::TwoDimensionalStatistics::
merge(const TwoDimensionalStatistics& r)
{
m_data->merge(*r.m_data);
}
void osl::stat::TwoDimensionalStatistics::
clear()
{
m_data->clear();
}
// ACCESSORS
size_t osl::stat::TwoDimensionalStatistics::
size() const
{
return m_data->m_x.numElements();
}
double osl::stat::TwoDimensionalStatistics::
averageX() const
{
return m_data->m_x.average();
}
double osl::stat::TwoDimensionalStatistics::
averageY() const
{
return m_data->m_y.average();
}
double osl::stat::TwoDimensionalStatistics::
averageX2() const
{
return m_data->m_x2.average();
}
double osl::stat::TwoDimensionalStatistics::
averageY2() const
{
return m_data->m_y2.average();
}
double osl::stat::TwoDimensionalStatistics::
averageXY() const
{
return m_data->m_xy.average();
}
double osl::stat::TwoDimensionalStatistics::
meanSquaredErrors() const
{
return averageX2() - 2*averageXY() + averageY2();
}
double osl::stat::TwoDimensionalStatistics::
meanSquaredErrorsAdjustConstant() const
{
return averageX2() - averageX()*averageX()
-2*(averageXY() - averageX()*averageY())
+ averageY2() - averageY()*averageY();
}
double osl::stat::TwoDimensionalStatistics::
correlation() const
{
return (averageXY() - averageX()*averageY())
/ sqrt((averageX2() - averageX()*averageX())
* (averageY2() - averageY()*averageY()));
}
void osl::stat::TwoDimensionalStatistics::
fitting(double &a, double &b, double &residual) const
{
double d = averageX2() - averageX()*averageX();
double n = averageXY() - averageX()*averageY();
if (std::abs(d) < 1e-8) {
a = 0.0;
b = averageY();
residual = averageY2() - averageY()*averageY();
return;
}
a = n / d;
b = (averageX2()*averageY() - averageXY()*averageX()) / d;
residual = averageY2()-averageY()*averageY()
- n * n / d;
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
average.h
osl::stat::Average
incrementaly maintain average of data sequence
Definition average.h:14
osl::stat::TwoDimensionalStatistics::Data
Definition twoDimensionalStatistics.cc:8
osl::stat::TwoDimensionalStatistics::Data::m_x2
Average m_x2
Definition twoDimensionalStatistics.cc:10
osl::stat::TwoDimensionalStatistics::Data::m_x
Average m_x
Definition twoDimensionalStatistics.cc:10
osl::stat::TwoDimensionalStatistics::Data::m_y
Average m_y
Definition twoDimensionalStatistics.cc:10
osl::stat::TwoDimensionalStatistics::Data::add
void add(const double &x, const double &y)
Definition twoDimensionalStatistics.cc:13
osl::stat::TwoDimensionalStatistics::Data::m_y2
Average m_y2
Definition twoDimensionalStatistics.cc:10
osl::stat::TwoDimensionalStatistics::Data::clear
void clear()
Definition twoDimensionalStatistics.cc:29
osl::stat::TwoDimensionalStatistics::Data::merge
void merge(const Data &r)
Definition twoDimensionalStatistics.cc:21
osl::stat::TwoDimensionalStatistics::Data::m_xy
Average m_xy
Definition twoDimensionalStatistics.cc:10
osl::stat::TwoDimensionalStatistics::averageXY
double averageXY() const
Definition twoDimensionalStatistics.cc:102
osl::stat::TwoDimensionalStatistics::TwoDimensionalStatistics
TwoDimensionalStatistics()
Definition twoDimensionalStatistics.cc:41
osl::stat::TwoDimensionalStatistics::clear
void clear()
Definition twoDimensionalStatistics.cc:64
osl::stat::TwoDimensionalStatistics::m_data
std::unique_ptr< Data > m_data
Definition twoDimensionalStatistics.h:16
osl::stat::TwoDimensionalStatistics::averageX
double averageX() const
Definition twoDimensionalStatistics.cc:78
osl::stat::TwoDimensionalStatistics::meanSquaredErrors
double meanSquaredErrors() const
Definition twoDimensionalStatistics.cc:108
osl::stat::TwoDimensionalStatistics::averageY
double averageY() const
Definition twoDimensionalStatistics.cc:84
osl::stat::TwoDimensionalStatistics::averageY2
double averageY2() const
Definition twoDimensionalStatistics.cc:96
osl::stat::TwoDimensionalStatistics::size
size_t size() const
Definition twoDimensionalStatistics.cc:72
osl::stat::TwoDimensionalStatistics::averageX2
double averageX2() const
Definition twoDimensionalStatistics.cc:90
osl::stat::TwoDimensionalStatistics::correlation
double correlation() const
Definition twoDimensionalStatistics.cc:122
osl::stat::TwoDimensionalStatistics::fitting
void fitting(double &a, double &b, double &residual) const
ax + b = y
Definition twoDimensionalStatistics.cc:130
osl::stat::TwoDimensionalStatistics::merge
void merge(const TwoDimensionalStatistics &)
Definition twoDimensionalStatistics.cc:58
osl::stat::TwoDimensionalStatistics::meanSquaredErrorsAdjustConstant
double meanSquaredErrorsAdjustConstant() const
Definition twoDimensionalStatistics.cc:114
osl::stat::TwoDimensionalStatistics::~TwoDimensionalStatistics
~TwoDimensionalStatistics()
Definition twoDimensionalStatistics.cc:46
osl::stat::TwoDimensionalStatistics::add
void add(const double &x, const double &y)
Definition twoDimensionalStatistics.cc:52
twoDimensionalStatistics.h