23 #include <QDataStream> 27 #include <QXmlStreamWriter> 36 #include "XmlStackedHandlerReader.h" 68 : m_numberCells(other.m_numberCells),
69 m_numberQuantiles(other.m_numberQuantiles),
70 m_numberObservations(other.m_numberObservations),
71 m_quantiles(other.m_quantiles),
72 m_observationValues(other.m_observationValues),
73 m_idealNumObsBelowQuantile(other.m_idealNumObsBelowQuantile),
74 m_numObsBelowQuantile(other.m_numObsBelowQuantile) {
120 void StatCumProbDistDynCalc::setQuantiles(
unsigned int nodes) {
200 if (cumProb < 0.0 || cumProb > 1.0) {
202 "StatCumProbDistDynCalc::value(double cumProb). Must be on the domain [0, 1].";
219 unsigned int index = 0;
225 if ( dist < minDistance ) {
266 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
272 double interp = (
cumProb-x[1]) * (
cumProb-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
273 + (
cumProb-x[0]) * (
cumProb-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
274 + (
cumProb-x[0]) * (
cumProb-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
280 for (i = 0; i < 3; i++) {
287 if (y[i] <= interp && y[i+1] >= interp) {
292 return ( (x[i] -
cumProb) * y[i+1] + (x[i+1] -
cumProb) * y[i] ) / (x[i] - x[i+1]);
327 unsigned int index = 0;
330 if ( dist < minDistance) {
371 if ( x[0] == x[1] || x[0] == x[2] || x[1] == x[2]) {
377 double interp = (
value-x[1]) * (
value-x[2]) / (x[0]-x[1]) / (x[0]-x[2]) * y[0]
378 + (
value-x[0]) * (
value-x[2]) / (x[1]-x[0]) / (x[1]-x[2]) * y[1]
379 + (
value-x[0]) * (
value-x[1]) / (x[2]-x[0]) / (x[2]-x[1]) * y[2];
384 for (i = 0; i < 3; i++) {
389 if (y[i] <= interp && y[i+1] >= interp)
393 return ((x[i] -
value) * y[i+1] + (x[i+1] -
value) * y[i]) / (x[i] - x[i+1]);
454 if (fabs(temp)>1 && temp > 0.0) {
457 else if (fabs(temp)>1 && temp < 0.0) {
504 void StatCumProbDistDynCalc::save(QXmlStreamWriter &stream,
const Project *project)
const {
506 stream.writeStartElement(
"statCumProbDistDynCalc");
511 stream.writeStartElement(
"distributionData");
513 stream.writeStartElement(
"quantileInfo");
517 stream.writeAttribute(
"idealNumObsBelowQuantile",
520 stream.writeEndElement();
522 stream.writeEndElement();
523 stream.writeEndElement();
530 StatCumProbDistDynCalc::XmlHandler::XmlHandler(StatCumProbDistDynCalc *probabilityCalc,
532 m_xmlHandlerCumProbCalc = probabilityCalc;
533 m_xmlHandlerProject = project;
534 m_xmlHandlerCharacters =
"";
539 StatCumProbDistDynCalc::XmlHandler::~XmlHandler() {
542 m_xmlHandlerProject = NULL;
547 bool StatCumProbDistDynCalc::XmlHandler::startElement(
const QString &namespaceURI,
548 const QString &localName,
549 const QString &qName,
550 const QXmlAttributes &atts) {
552 m_xmlHandlerCharacters =
"";
553 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
554 if (qName ==
"quantileInfo") {
556 QString quantile = atts.value(
"quantile");
557 QString obsValue = atts.value(
"dataValue");
558 QString idealObs = atts.value(
"idealNumObsBelowQuantile");
559 QString actualObs = atts.value(
"actualNumObsBelowQuantile");
561 if (!quantile.isEmpty() && !obsValue.isEmpty()
562 && !idealObs.isEmpty() && !actualObs.isEmpty()) {
563 m_xmlHandlerCumProbCalc->m_quantiles.append(
toDouble(quantile));
564 m_xmlHandlerCumProbCalc->m_observationValues.append(
toDouble(obsValue));
565 m_xmlHandlerCumProbCalc->m_idealNumObsBelowQuantile.append(
toDouble(idealObs));
566 m_xmlHandlerCumProbCalc->m_numObsBelowQuantile.append(
toDouble(actualObs));
576 bool StatCumProbDistDynCalc::XmlHandler::characters(
const QString &ch) {
577 m_xmlHandlerCharacters += ch;
578 return XmlStackedHandler::characters(ch);
583 bool StatCumProbDistDynCalc::XmlHandler::endElement(
const QString &namespaceURI,
584 const QString &localName,
585 const QString &qName) {
586 if (!m_xmlHandlerCharacters.isEmpty()) {
587 if (qName ==
"numberCells") {
588 m_xmlHandlerCumProbCalc->m_numberCells =
toInt(m_xmlHandlerCharacters);
590 else if (qName ==
"numberQuantiles") {
591 m_xmlHandlerCumProbCalc->m_numberQuantiles =
toInt(m_xmlHandlerCharacters);
593 else if (qName ==
"numberObservations") {
594 m_xmlHandlerCumProbCalc->m_numberObservations =
toInt(m_xmlHandlerCharacters);
597 m_xmlHandlerCharacters =
"";
599 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
604 QDataStream &StatCumProbDistDynCalc::write(QDataStream &stream)
const {
617 QDataStream &StatCumProbDistDynCalc::read(QDataStream &stream) {
619 qint32 numCells, numQuantiles, numObservations;
637 return scpddc.write(stream);
643 return scpddc.read(stream);
646 void StatCumProbDistDynCalc::validate() {
649 QString msg =
"StatCumProbDistDynCalc will return no data until the quantiles have been set. " 656 QString msg =
"StatCumProbDistDynCalc will return no data until the number of observations " 659 +
"] (i.e. number of nodes) selected.";
double max()
Returns the maximum observation so far included in the dynamic calculation.
The main project for ipce.
StatCumProbDistDynCalc(unsigned int nodes=20, QObject *parent=0)
Construtor sets up the class to start recieving data.
double value(double cumProb)
Provides the value of the variable that has the given cumulative probility (according the current est...
~StatCumProbDistDynCalc()
Destroys StatCumProbDistDynCalc object.
int toInt(const QString &string)
Global function to convert from a string to an integer.
QList< double > m_observationValues
The calculated values of the quantiles, note this is dynamically changing as observations are added...
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
unsigned int m_numberQuantiles
The number of quantiles being used to model the probility density function.
This class is used to approximate cumulative probibility distributions of a stream of observations wi...
unsigned int m_numberCells
The number of cells or histogram bins that are being used to model the probility density function...
#define _FILEINFO_
Macro for the filename and line number.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
QList< double > m_quantiles
The target quantiles being modeled, between 0 and 1.
void initialize()
Inializer, resets the class to start its dynamic calculation anew.
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...
void addObs(double obs)
Values for the estimated quantile positions are update as observations are added. ...
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
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 ...
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
double cumProb(double value)
Provides the cumulative probility, that is, the proportion of the distribution that is less than or e...
Manage a stack of content handlers for reading XML files.