SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
cmbvectorset.cpp
Go to the documentation of this file.
1// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
4#include "cmbvectorset.h"
5#include <QFile>
6#include <gsl/gsl_cdf.h>
7
17{
18 map<string,CMBVector>::operator=(mp);
20 return *this;
21}
22QJsonObject CMBVectorSet::toJsonObject() const
23{
24 QJsonObject out;
25 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
26 {
27 out[QString::fromStdString(it->first)]=it->second.toJsonObject();
28 }
29 return out;
30}
31bool CMBVectorSet::ReadFromJsonObject(const QJsonObject &jsonobject)
32{
33 for(const QString& key: jsonobject.keys() ) {
34 CMBVector column;
35 column.ReadFromJsonObject(jsonobject[key].toObject());
36 operator[](key.toStdString()) = column;
37 }
38 return true;
39}
41{
42 string s;
43 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
44 {
45 s+= "\n";
46 s+=it->first + ":\n";
47 s+=it->second.ToString()+="\n";
48 }
49 return s;
50}
51
52unsigned int CMBVectorSet::MaxSize() const
53{
54 int max_size=0;
55 for (map<string,CMBVector>::const_iterator it = begin(); it!=end();it++)
56 {
57 if (it->second.num>max_size)
58 max_size = it->second.num;
59 }
60 return max_size;
61}
62
63double CMBVectorSet::max() const
64{
65 double out = -1e23;
66 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
67 {
68 out = std::max(out,it->second.max());
69 }
70 return out;
71};
72double CMBVectorSet::min() const
73{
74 double out = 1e23;
75 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
76 {
77 out = std::min(out,it->second.min());
78 }
79 return out;
80}
81
82
83QTableWidget *CMBVectorSet::ToTable()
84{
85 QTableWidget *tablewidget = new QTableWidget();
86 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
87 tablewidget->setColumnCount(size()*2);
88 tablewidget->setRowCount(MaxSize());
89 QStringList rowheaders;
90 QStringList colheaders;
91 int colno = 0;
92 for (map<string,CMBVector>::iterator column=begin(); column!=end(); column++)
93 {
94 colheaders<<QString::fromStdString(column->first)<<QString::fromStdString(column->first)+"-Value";
95 for (int i=0; i<column->second.getsize(); i++)
96 {
97 tablewidget->setItem(i,colno*2,new QTableWidgetItem(QString::fromStdString(column->second.Label(i))));
98 tablewidget->setItem(i,colno*2+1,new QTableWidgetItem(QString::number(column->second[i])));
99 }
100 colno++;
101 }
102
103 tablewidget->setHorizontalHeaderLabels(colheaders);
104 //tablewidget->setVerticalHeaderLabels(rowheaders);
105 return tablewidget;
106}
108{
109 file->write(QString::fromStdString(ToString()).toUtf8());
110 return true;
111}
112
113string CMBVectorSet::Label(const string& column,int j) const
114{
115 if (count(column)!=0)
116 return (at(column).Label(j));
117 else
118 return "";
119}
120double CMBVectorSet::valueAt(const string &columnlabel, int j ) const
121{
122 if (count(columnlabel)!=0)
123 return (at(columnlabel).valueAt(j));
124 else
125 return 0;
126}
127CMBVector &CMBVectorSet::GetColumn(const string& columnlabel)
128{
129 return at(columnlabel);
130}
131void CMBVectorSet::Append(const string &columnlabel,const CMBVector &vector)
132{
133 this->operator[](columnlabel) = vector;
134}
135
137{
138 double SSB = 0;
139 double Overall_Mean = OverallMean();
140 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
141 {
142 SSB += pow(vect->second.mean()-Overall_Mean,2)*vect->second.num;
143 }
144 double MSB = SSB/(size()-1);
145 double SSW=0;
146 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
147 {
148 SSW += pow(vect->second.stdev(),2)*vect->second.num;
149 }
150 double MSW = SSW/(TotalNumberofObservations()-size());
151 double F = MSB/MSW;
152 double p_value = gsl_cdf_fdist_Q (F, size()-1, TotalNumberofObservations());
153 return p_value;
154}
155
157{
158 double sum=0;
159 double count = 0;
160 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
161 {
162 sum+=vect->second.mean()*vect->second.num;
163 count+=vect->second.num;
164 }
165 return sum/count;
166}
167
169{
170 double count = 0;
171 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
172 {
173 count+=vect->second.num;
174 }
175 return count;
176}
QTableWidget * ToTable() override
Creates a QTableWidget for displaying vector set data.
void Append(const string &columnlabel, const CMBVector &vectorset)
Adds or replaces a vector in the set.
double min() const
Finds the minimum value across all vectors.
double OverallMean() const
Computes overall mean across all vectors.
CMBVectorSet()
Default constructor - creates an empty vector set.
string Label(const string &column, int j) const
Gets label at specified position in a column.
QJsonObject toJsonObject() const override
Serializes vector set to JSON format.
int TotalNumberofObservations() const
Counts total number of observations across all vectors.
unsigned int MaxSize() const
Finds the maximum size among all vectors.
CMBVector & GetColumn(const string &columnlabel)
Gets reference to a named column vector.
bool writetofile(QFile *file) override
Writes vector set to file.
double FTest_p_value() const
Computes F-test p-value for ANOVA.
double max() const
Finds the maximum value across all vectors.
CMBVectorSet & operator=(const CMBVectorSet &mp)
Assignment operator.
double valueAt(const string &columnlabel, int j) const
Gets value at specified position in a column.
string ToString() const override
Converts vector set to string representation.
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserializes vector set from JSON format.
Vector class with string labels for Chemical Mass Balance analysis.
Definition cmbvector.h:20
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserializes vector from JSON format.
Definition cmbvector.cpp:85
Interface()
Default constructor.
Definition interface.cpp:6
Interface & operator=(const Interface &intf)
Assignment operator.
STL class.
STL class.