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#include "cmbvectorset.h"
2#include <QFile>
3#include <gsl/gsl_cdf.h>
4
14{
15 map<string,CMBVector>::operator=(mp);
17 return *this;
18}
19QJsonObject CMBVectorSet::toJsonObject() const
20{
21 QJsonObject out;
22 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
23 {
24 out[QString::fromStdString(it->first)]=it->second.toJsonObject();
25 }
26 return out;
27}
28bool CMBVectorSet::ReadFromJsonObject(const QJsonObject &jsonobject)
29{
30 for(QString key: jsonobject.keys() ) {
31 CMBVector column;
32 column.ReadFromJsonObject(jsonobject[key].toObject());
33 operator[](key.toStdString()) = column;
34 }
35 return true;
36}
38{
39 string s;
40 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
41 {
42 s+= "\n";
43 s+=it->first + ":\n";
44 s+=it->second.ToString()+="\n";
45 }
46 return s;
47}
48
49unsigned int CMBVectorSet::MaxSize() const
50{
51 int max_size=0;
52 for (map<string,CMBVector>::const_iterator it = begin(); it!=end();it++)
53 {
54 if (it->second.num>max_size)
55 max_size = it->second.num;
56 }
57 return max_size;
58}
59
60double CMBVectorSet::max() const
61{
62 double out = -1e23;
63 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
64 {
65 out = std::max(out,it->second.max());
66 }
67 return out;
68};
69double CMBVectorSet::min() const
70{
71 double out = 1e23;
72 for (map<string,CMBVector>::const_iterator it = cbegin(); it!=cend();it++)
73 {
74 out = std::min(out,it->second.min());
75 }
76 return out;
77}
78
79
80QTableWidget *CMBVectorSet::ToTable()
81{
82 QTableWidget *tablewidget = new QTableWidget();
83 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
84 tablewidget->setColumnCount(size()*2);
85 tablewidget->setRowCount(MaxSize());
86 QStringList rowheaders;
87 QStringList colheaders;
88 int colno = 0;
89 for (map<string,CMBVector>::iterator column=begin(); column!=end(); column++)
90 {
91 colheaders<<QString::fromStdString(column->first)<<QString::fromStdString(column->first)+"-Value";
92 for (int i=0; i<column->second.getsize(); i++)
93 {
94 tablewidget->setItem(i,colno*2,new QTableWidgetItem(QString::fromStdString(column->second.Label(i))));
95 tablewidget->setItem(i,colno*2+1,new QTableWidgetItem(QString::number(column->second[i])));
96 }
97 colno++;
98 }
99
100 tablewidget->setHorizontalHeaderLabels(colheaders);
101 //tablewidget->setVerticalHeaderLabels(rowheaders);
102 return tablewidget;
103}
105{
106 file->write(QString::fromStdString(ToString()).toUtf8());
107 return true;
108}
109
110string CMBVectorSet::Label(string column,int j) const
111{
112 if (count(column)!=0)
113 return (at(column).Label(j));
114 else
115 return "";
116}
117double CMBVectorSet::valueAt(const string &columnlabel, int j ) const
118{
119 if (count(columnlabel)!=0)
120 return (at(columnlabel).valueAt(j));
121 else
122 return 0;
123}
124CMBVector &CMBVectorSet::GetColumn(const string columnlabel)
125{
126 return at(columnlabel);
127}
128void CMBVectorSet::Append(const string &columnlabel,const CMBVector &vector)
129{
130 this->operator[](columnlabel) = vector;
131}
132
134{
135 double SSB = 0;
136 double Overall_Mean = OverallMean();
137 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
138 {
139 SSB += pow(vect->second.mean()-Overall_Mean,2)*vect->second.num;
140 }
141 double MSB = SSB/(size()-1);
142 double SSW=0;
143 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
144 {
145 SSW += pow(vect->second.stdev(),2)*vect->second.num;
146 }
147 double MSW = SSW/(TotalNumberofObservations()-size());
148 double F = MSB/MSW;
149 double p_value = gsl_cdf_fdist_Q (F, size()-1, TotalNumberofObservations());
150 return p_value;
151}
152
154{
155 double sum=0;
156 double count = 0;
157 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
158 {
159 sum+=vect->second.mean()*vect->second.num;
160 count+=vect->second.num;
161 }
162 return sum/count;
163}
164
166{
167 double count = 0;
168 for (map<string,CMBVector>::const_iterator vect = cbegin(); vect!=cend(); vect++ )
169 {
170 count+=vect->second.num;
171 }
172 return count;
173}
Collection of named CMBVector objects for multi-variable analysis.
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.
string Label(string column, int j) const
Gets label at specified position in a column.
double OverallMean() const
Computes overall mean across all vectors.
CMBVectorSet()
Default constructor - creates an empty vector set.
QJsonObject toJsonObject() const override
Serializes vector set to JSON format.
CMBVector & GetColumn(const string columnlabel)
Gets reference to a named column vector.
int TotalNumberofObservations() const
Counts total number of observations across all vectors.
unsigned int MaxSize() const
Finds the maximum size among all vectors.
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:17
string ToString() const override
Converts vector to CSV-formatted string.
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserializes vector from JSON format.
Definition cmbvector.cpp:81
Abstract base class providing common serialization and visualization interface.
Definition interface.h:65
Interface & operator=(const Interface &intf)
Assignment operator.
Definition interface.cpp:14