8#include "StatCumProbDistDynCalc.h"
15#include <QXmlStreamWriter>
16#include <QXmlStreamReader>
22#include "IException.h"
47 readStatistics(xmlReader);
50 void StatCumProbDistDynCalc::readStatistics(QXmlStreamReader *xmlReader) {
51 Q_ASSERT(xmlReader->name() ==
"statCumProbDistDynCalc");
52 while (xmlReader->readNextStartElement()) {
53 if (xmlReader->qualifiedName() ==
"numberCells") {
57 catch (IException &e) {
61 else if (xmlReader->qualifiedName() ==
"numberQuantiles") {
65 catch (IException &e) {
69 else if (xmlReader->qualifiedName() ==
"numberObservations") {
73 catch (IException &e) {
77 else if (xmlReader->qualifiedName() ==
"distributionData") {
83 while (xmlReader->readNextStartElement()) {
84 if (xmlReader->qualifiedName() ==
"quantileInfo") {
85 QStringView quantile = xmlReader->attributes().value(
"quantile");
86 if (!quantile.isEmpty()) {
89 QStringView dataValue = xmlReader->attributes().value(
"dataValue");
90 if (!dataValue.isEmpty()) {
93 QStringView idealNumObsBelowQuantile = xmlReader->attributes().value(
"idealNumObsBelowQuantile");
94 if (!idealNumObsBelowQuantile.isEmpty()) {
97 QStringView actualNumObsBelowQuantile = xmlReader->attributes().value(
"actualNumObsBelowQuantile");
99 if (!actualNumObsBelowQuantile.isEmpty()) {
104 xmlReader->skipCurrentElement();
110 xmlReader->skipCurrentElement();
117 : m_numberCells(other.m_numberCells),
118 m_numberQuantiles(other.m_numberQuantiles),
119 m_numberObservations(other.m_numberObservations),
120 m_quantiles(other.m_quantiles),
121 m_observationValues(other.m_observationValues),
122 m_idealNumObsBelowQuantile(other.m_idealNumObsBelowQuantile),
123 m_numObsBelowQuantile(other.m_numObsBelowQuantile) {
138 if (&other !=
this) {
169 void StatCumProbDistDynCalc::setQuantiles(
unsigned int nodes) {
250 IString msg =
"Invalid cumulative probability [" +
toString(
cumProb) +
"] passed in to "
251 "StatCumProbDistDynCalc::value(double cumProb). Must be on the domain [0, 1].";
252 throw IException(IException::Programmer, msg, _FILEINFO_);
268 unsigned int index = 0;
274 if ( dist < minDistance ) {
315 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
321 double interp = (
cumProb-x[1]) * (
cumProb-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
322 + (
cumProb-x[0]) * (
cumProb-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
323 + (
cumProb-x[0]) * (
cumProb-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
329 for (i = 0; i < 3; i++) {
336 if (y[i] <= interp && y[i+1] >= interp) {
341 return ( (x[i] -
cumProb) * y[i+1] + (x[i+1] -
cumProb) * y[i] ) / (x[i] - x[i+1]);
376 unsigned int index = 0;
379 if ( dist < minDistance) {
420 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
426 double interp = (
value-x[1]) * (
value-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
427 + (
value-x[0]) * (
value-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
428 + (
value-x[0]) * (
value-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
433 for (i = 0; i < 3; i++) {
438 if (y[i] <= interp && y[i+1] >= interp)
442 return ((x[i] -
value) * y[i+1] + (x[i+1] -
value) * y[i]) / (x[i] - x[i+1]);
503 if (fabs(temp)>1 && temp > 0.0) {
506 else if (fabs(temp)>1 && temp < 0.0) {
553 void StatCumProbDistDynCalc::save(QXmlStreamWriter &stream,
const Project *project)
const {
555 stream.writeStartElement(
"statCumProbDistDynCalc");
560 stream.writeStartElement(
"distributionData");
562 stream.writeStartElement(
"quantileInfo");
568 stream.writeAttribute(
"idealNumObsBelowQuantile",
571 stream.writeEndElement();
573 stream.writeEndElement();
574 stream.writeEndElement();
578 QDataStream &StatCumProbDistDynCalc::write(QDataStream &stream)
const {
589 QDataStream &StatCumProbDistDynCalc::read(QDataStream &stream) {
591 qint32 numCells, numQuantiles, numObservations;
609 return scpddc.write(stream);
615 return scpddc.read(stream);
618 void StatCumProbDistDynCalc::validate() {
621 QString msg =
"StatCumProbDistDynCalc will return no data until the quantiles have been set. "
623 throw IException(IException::Programmer, msg, _FILEINFO_);
628 QString msg =
"StatCumProbDistDynCalc will return no data until the number of observations "
631 +
"] (i.e. number of nodes) selected.";
632 throw IException(IException::Programmer, msg, _FILEINFO_);
The main project for ipce.
This class is used to approximate cumulative probibility distributions of a stream of observations wi...
QList< int > m_numObsBelowQuantile
The actual number of observations that are less than or equal to the value of the corresponding quant...
unsigned int m_numberObservations
The number of observations, note this is dynamically changing as observations are added.
double min()
Returns the maximum observation so far included in the dynamic calculation.
QList< double > m_idealNumObsBelowQuantile
The ideal number of observations that should be less than or equal to the value of the corresponding ...
QList< double > m_observationValues
The calculated values of the quantiles, note this is dynamically changing as observations are added.
StatCumProbDistDynCalc(unsigned int nodes=20, QObject *parent=0)
Construtor sets up the class to start recieving data.
void initialize()
Inializer, resets the class to start its dynamic calculation anew.
unsigned int m_numberCells
The number of cells or histogram bins that are being used to model the probility density function.
~StatCumProbDistDynCalc()
Destroys StatCumProbDistDynCalc object.
unsigned int m_numberQuantiles
The number of quantiles being used to model the probility density function.
QList< double > m_quantiles
The target quantiles being modeled, between 0 and 1.
double value(double cumProb)
Provides the value of the variable that has the given cumulative probility (according the current est...
void addObs(double obs)
Values for the estimated quantile positions are update as observations are added.
double cumProb(double value)
Provides the cumulative probility, that is, the proportion of the distribution that is less than or e...
double max()
Returns the maximum observation so far included in the dynamic calculation.
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.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.