12#include "IException.h"
13#include "MultivariateStatistics.h"
15#include "PvlKeyword.h"
67 const unsigned int count) {
68 for(
unsigned int i = 0; i < count; i++) {
73 if(Isis::IsValidPixel(xVal) && Isis::IsValidPixel(yVal)) {
97 if(IsValidPixel(x) && IsValidPixel(y)) {
101 for (
unsigned int i = 0; i < count; i++) {
125 const unsigned int count) {
126 for(
unsigned int i = 0; i < count; i++) {
129 if(Isis::IsValidPixel(x[i]) && Isis::IsValidPixel(y[i])) {
130 p_x.RemoveData(&x[i], 1);
131 p_y.RemoveData(&y[i], 1);
141 std::string m =
"You are removing non-existant data in [MultivariateStatistics::RemoveData]";
142 throw IException(IException::Programmer, m, _FILEINFO_);
175 double stdX =
p_x.StandardDeviation();
176 double stdY =
p_y.StandardDeviation();
177 if(stdX == 0.0 || stdX == Isis::NULL8)
return Isis::NULL8;
178 if(stdY == 0.0 || stdY == Isis::NULL8)
return Isis::NULL8;
179 if(covar == Isis::NULL8)
return Isis::NULL8;
180 return covar / (stdX * stdY);
226 std::string msg =
"Unable to compute linear regression in Multivariate Statistics";
227 throw IException(IException::Programmer, msg, _FILEINFO_);
279 PvlGroup xStats = inStats.findGroup(
"XStatistics");
281 PvlGroup yStats = inStats.findGroup(
"YStatistics");
294 if (name.isEmpty()) {
295 name =
"MultivariateStatistics";
297 PvlObject mStats(name);
305 PvlKeyword linReg(
"LinearRegression");
311 }
catch (IException &e) {
317 PvlGroup xStats =
X().
toPvl(
"XStatistics");
318 PvlGroup yStats =
Y().
toPvl(
"YStatistics");
319 mStats.addGroup(xStats);
320 mStats.addGroup(yStats);
void LinearRegression(double &a, double &b) const
Fits a line.
void RemoveData(const double *x, const double *y, const unsigned int count)
Remove an array of doubles from the accumulators and counters.
Isis::Statistics p_y
A Statistics object holding y data.
double Correlation() const
Computes and returns the coefficient of correlation (between -1.0 and 1.0) of the two data sets.
Isis::Statistics Y() const
Returns a Stats object for all of the Y data fed through the AddData method.
Isis::Statistics p_x
A Statistics object holding x data.
BigInt p_validPixels
The number of valid (computed) pixels.
double Covariance() const
Computes and returns the covariance between the two data sets If there are no valid data (pixels) the...
MultivariateStatistics()
Constructs a Multivariate Statistics object with accumulators and counters set to zero.
PvlObject toPvl(QString name="MultivariateStatistics") const
Serializes a multivariate statistics object as a PvlObject.
BigInt TotalPixels() const
Returns the total number of pixels processed.
BigInt InvalidPixels() const
Returns the number of invalid pixels encountered.
double SumXY() const
Returns the sum of x*y for all data given through the AddData method.
~MultivariateStatistics()
Destructs a MultivariateStatistics object.
double p_sumxy
The sum of x and y.
BigInt p_invalidPixels
The number of invalid (ignored) pixels.
BigInt ValidPixels() const
Returns the number of valid pixels processed.
Isis::Statistics X() const
Returns a Stats object for all of the X data fed through the AddData method.
void fromPvl(const PvlObject &inStats)
Unserializes a multivariate statistics object from a PvlObject.
void Reset()
Resets all accumulators to zero.
void AddData(const double *x, const double *y, const unsigned int count)
Add two arrays of doubles to the accumulators and counters.
BigInt p_totalPixels
The total number of pixels (invalid and valid).
This class is used to accumulate statistics on double arrays.
PvlGroup toPvl(QString name="Statistics") const
Serialize statistics as a pvl group.
This is free and unencumbered software released into the public domain.
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.