8#include "StatCumProbDistDynCalc.h"
14#include <QXmlStreamWriter>
15#include <QXmlStreamReader>
21#include "IException.h"
46 readStatistics(xmlReader);
49 void StatCumProbDistDynCalc::readStatistics(QXmlStreamReader *xmlReader) {
50 Q_ASSERT(xmlReader->name() ==
"statCumProbDistDynCalc");
51 while (xmlReader->readNextStartElement()) {
52 if (xmlReader->qualifiedName() ==
"numberCells") {
56 catch (IException &e) {
60 else if (xmlReader->qualifiedName() ==
"numberQuantiles") {
64 catch (IException &e) {
68 else if (xmlReader->qualifiedName() ==
"numberObservations") {
72 catch (IException &e) {
76 else if (xmlReader->qualifiedName() ==
"distributionData") {
82 while (xmlReader->readNextStartElement()) {
83 if (xmlReader->qualifiedName() ==
"quantileInfo") {
84 QStringRef quantile = xmlReader->attributes().value(
"quantile");
85 if (!quantile.isEmpty()) {
88 QStringRef dataValue = xmlReader->attributes().value(
"dataValue");
89 if (!dataValue.isEmpty()) {
92 QStringRef idealNumObsBelowQuantile = xmlReader->attributes().value(
"idealNumObsBelowQuantile");
93 if (!idealNumObsBelowQuantile.isEmpty()) {
96 QStringRef actualNumObsBelowQuantile = xmlReader->attributes().value(
"actualNumObsBelowQuantile");
98 if (!actualNumObsBelowQuantile.isEmpty()) {
103 xmlReader->skipCurrentElement();
109 xmlReader->skipCurrentElement();
116 : m_numberCells(other.m_numberCells),
117 m_numberQuantiles(other.m_numberQuantiles),
118 m_numberObservations(other.m_numberObservations),
119 m_quantiles(other.m_quantiles),
120 m_observationValues(other.m_observationValues),
121 m_idealNumObsBelowQuantile(other.m_idealNumObsBelowQuantile),
122 m_numObsBelowQuantile(other.m_numObsBelowQuantile) {
137 if (&other !=
this) {
168 void StatCumProbDistDynCalc::setQuantiles(
unsigned int nodes) {
248 if (cumProb < 0.0 || cumProb > 1.0) {
250 "StatCumProbDistDynCalc::value(double cumProb). Must be on the domain [0, 1].";
267 unsigned int index = 0;
273 if ( dist < minDistance ) {
314 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
320 double interp = (
cumProb-x[1]) * (
cumProb-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
321 + (
cumProb-x[0]) * (
cumProb-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
322 + (
cumProb-x[0]) * (
cumProb-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
328 for (i = 0; i < 3; i++) {
335 if (y[i] <= interp && y[i+1] >= interp) {
340 return ( (x[i] -
cumProb) * y[i+1] + (x[i+1] -
cumProb) * y[i] ) / (x[i] - x[i+1]);
375 unsigned int index = 0;
378 if ( dist < minDistance) {
419 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
425 double interp = (
value-x[1]) * (
value-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
426 + (
value-x[0]) * (
value-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
427 + (
value-x[0]) * (
value-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
432 for (i = 0; i < 3; i++) {
437 if (y[i] <= interp && y[i+1] >= interp)
441 return ((x[i] -
value) * y[i+1] + (x[i+1] -
value) * y[i]) / (x[i] - x[i+1]);
502 if (fabs(temp)>1 && temp > 0.0) {
505 else if (fabs(temp)>1 && temp < 0.0) {
552 void StatCumProbDistDynCalc::save(QXmlStreamWriter &stream,
const Project *project)
const {
554 stream.writeStartElement(
"statCumProbDistDynCalc");
559 stream.writeStartElement(
"distributionData");
561 stream.writeStartElement(
"quantileInfo");
565 stream.writeAttribute(
"idealNumObsBelowQuantile",
568 stream.writeEndElement();
570 stream.writeEndElement();
571 stream.writeEndElement();
575 QDataStream &StatCumProbDistDynCalc::write(QDataStream &stream)
const {
586 QDataStream &StatCumProbDistDynCalc::read(QDataStream &stream) {
588 qint32 numCells, numQuantiles, numObservations;
605 QDataStream &
operator<<(QDataStream &stream,
const StatCumProbDistDynCalc &scpddc) {
606 return scpddc.write(stream);
611 QDataStream &
operator>>(QDataStream &stream, StatCumProbDistDynCalc &scpddc) {
612 return scpddc.read(stream);
615 void StatCumProbDistDynCalc::validate() {
618 QString msg =
"StatCumProbDistDynCalc will return no data until the quantiles have been set. "
625 QString msg =
"StatCumProbDistDynCalc will return no data until the number of observations "
628 +
"] (i.e. number of nodes) selected.";
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
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(bool boolToConvert)
Global function to convert a boolean to a string.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
double toDouble(const QString &string)
Global function to convert from a string to a double.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.