SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
elemental_profile_set.h
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#ifndef ELEMENTAL_PROFILE_SET_H
5#define ELEMENTAL_PROFILE_SET_H
6
7#include <elemental_profile.h>
8#include <map>
9#include <string>
10#include <vector>
11#include "concentrationset.h"
12#include "interface.h"
14#include "resultitem.h"
15#include <gsl/gsl_vector.h>
16#include <gsl/gsl_matrix.h>
17#include "cmbvector.h"
18
30class Elemental_Profile_Set : public map<string, Elemental_Profile>, public Interface
31{
32public:
33 // ========== Construction and Assignment ==========
34
38
39 // ========== Data Management ==========
40
49 const string& name,
50 const Elemental_Profile& profile = Elemental_Profile(),
51 map<string, element_information>* elementinfo = nullptr
52 );
53
59 void AppendProfiles(
60 const Elemental_Profile_Set& profiles,
61 map<string, element_information>* elementinfo
62 );
63
70
71 // ========== Data Access ==========
72
77 Elemental_Profile* GetProfile(const string& name);
78
83 Elemental_Profile GetProfile(const string& name) const;
84
89 Elemental_Profile* GetProfile(unsigned int index);
90
95 Elemental_Profile GetProfile(unsigned int index) const;
96
100 vector<string> GetSampleNames() const;
101
105 vector<string> GetElementNames() const;
106
110 vector<double> GetAllConcentrationsFor(const string& element_name);
111
115 vector<double> GetConcentrationsForSample(const string& sample_name) const;
116
120 bool ContainsElement(const string& element_name) const;
121
122 // ========== Data Extraction and Filtering ==========
123
127 Elemental_Profile_Set ExtractElements(const vector<string>& element_list) const;
128
135 const map<string, element_information>* elementinfo,
136 bool isotopes
137 ) const;
138
148 bool exclude_samples,
149 bool exclude_elements,
150 bool omnsizecorrect,
151 const vector<double>& om_size,
152 const map<string, element_information>* elementinfo = nullptr
153 ) const;
154
159 bool applyomsizecorrection,
160 const vector<double>& om_size,
161 map<string, element_information>* elementinfo = nullptr
162 );
163
168 const vector<string>& samples_to_eliminate,
169 map<string, element_information>* elementinfo
170 ) const;
171
172 // ========== Statistical Analysis ==========
173
177 ConcentrationSet* GetElementDistribution(const string& element_name);
178
182 ConcentrationSet GetElementDistribution(const string& element_name) const;
183
187 distribution_type GetAssignedDistribution(const string& element_name) const;
188
192 CVector CalculateElementMeans(const vector<string>& element_order = vector<string>()) const;
193
198
203
208
212 double GetMaximum() const;
213
217 double GetMinimum() const;
218
219 // ========== Estimated Distribution Parameters (for MCMC) ==========
220
224 double GetEstimatedMu(const string& element) const;
225
229 double GetEstimatedSigma(const string& element) const;
230
234 bool SetEstimatedMu(const string& element, const double& value);
235
239 bool SetEstimatedSigma(const string& element, const double& value);
240
244 Distribution* GetEstimatedDistribution(const string& element_name);
245
249 Distribution* GetFittedDistribution(const string& element_name);
250
251 // ========== Regression Models (OM/Size Corrections) ==========
252
257 const string& om,
258 const string& d,
260 const double& p_value_threshold = 0.05
261 );
262
267 const string& element,
268 const string& om,
269 const string& d,
271 const double& p_value_threshold = 0.05
272 );
273
278 const string& om,
279 const string& d,
281 const double& p_value_threshold = 0.05
282 );
283
288
293
298
303 const vector<double>& om_size,
304 map<string, element_information>* elementinfo = nullptr
305 );
306
307 // ========== Box-Cox Transformations ==========
308
315
319 vector<string> ElementsNotBoxCoxTransformable() const;
320
325
326 // ========== Outlier Detection ==========
327
334 CMBMatrix DetectOutliers(const double& lowerlimit = 0, const double& upperlimit = 0);
335
339 bool OutlierAnalysisDone() const { return outlierdone_; }
340
344 vector<string> CheckForNegativeValues(const vector<string>& element_names) const;
345
346 // ========== Source Contribution (for CMB) ==========
347
351 bool SetContribution(const double& value);
352
356 double GetContribution() const { return contribution_; }
357
361 bool SetContributionSoftmax(const double& value);
362
367
368 // ========== Utility Functions ==========
369
374
378 CMBVector CalculateDotProduct(const CVector& v) const;
379
383 CMBMatrix ToMatrix() const;
384
388 gsl_matrix* CopyToGSLMatrix() const;
389
390 // ========== Serialization ==========
391
392 string ToString() const override;
393 QTableWidget* ToTable() override;
394 bool writetofile(QFile* file) override;
395 QJsonObject toJsonObject() const override;
396 bool ReadFromJsonObject(const QJsonObject& jsonobject) override;
397
403 bool ReadFromJsonObject(const QJsonObject& jsonobject, QString& error);
404 bool Read(const QStringList& strlist) override;
405
406private:
407 map<string, ConcentrationSet> element_distributions_;
409 double contribution_ = 0.0;
411 bool outlierdone_ = false;
412};
413
414#endif // ELEMENTAL_PROFILE_SET_H
Matrix class with labeled rows and columns for Chemical Mass Balance analysis.
Definition cmbmatrix.h:22
Vector class with string labels for Chemical Mass Balance analysis.
Definition cmbvector.h:20
Manages a collection of concentration measurements with statistical analysis.
Represents a parametric probability distribution for uncertainty quantification.
gsl_matrix * CopyToGSLMatrix() const
Convert to GSL matrix for statistical functions.
double GetEstimatedMu(const string &element) const
Get estimated mu parameter for an element.
CMBMatrix ToMatrix() const
Convert to matrix format (samples × elements).
distribution_type GetAssignedDistribution(const string &element_name) const
Get assigned distribution type for an element.
ConcentrationSet * GetElementDistribution(const string &element_name)
Get distribution for a specific element (mutable).
bool writetofile(QFile *file) override
Write object data to a file.
Elemental_Profile_Set CreateCorrectedSet(bool exclude_samples, bool exclude_elements, bool omnsizecorrect, const vector< double > &om_size, const map< string, element_information > *elementinfo=nullptr) const
Create corrected and filtered subset.
vector< string > GetSampleNames() const
Get all sample names in the set.
Elemental_Profile * AppendProfile(const string &name, const Elemental_Profile &profile=Elemental_Profile(), map< string, element_information > *elementinfo=nullptr)
Add a new sample profile to the set.
Distribution * GetEstimatedDistribution(const string &element_name)
Get estimated distribution for an element (for MCMC optimization).
CMBVector CalculateKolmogorovSmirnovStatistics(distribution_type dist_type)
Calculate Kolmogorov-Smirnov statistics for all elements.
vector< double > GetAllConcentrationsFor(const string &element_name)
Get all concentration values for a specific element across samples.
bool OutlierAnalysisDone() const
Check if outlier analysis has been performed.
ResultItem GetRegressionsAsResult()
Get regressions wrapped in ResultItem for display.
Elemental_Profile SelectTopElementsAggregate(int n) const
Select top N elements across all samples (aggregate minimum).
void UpdateElementDistributions()
Rebuild element distributions from all profiles.
Elemental_Profile_Set & operator=(const Elemental_Profile_Set &other)
vector< string > GetElementNames() const
Get all element names (from first profile).
bool SetContributionSoftmax(const double &value)
Set softmax-transformed contribution.
MultipleLinearRegressionSet * GetRegressionModels()
Get internal regression model set.
double GetMinimum() const
Get minimum concentration across all elements and samples.
vector< double > GetConcentrationsForSample(const string &sample_name) const
Get all element concentrations for a specific sample.
CMBVector CalculateDotProduct(const CVector &v) const
Calculate dot product of each profile with weight vector.
double GetEstimatedSigma(const string &element) const
Get estimated sigma parameter for an element.
Elemental_Profile * GetProfile(const string &name)
Get profile by sample name (mutable).
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserialize object from JSON format.
bool Read(const QStringList &strlist) override
Parse object data from a string list.
MultipleLinearRegression BuildRegressionModel(const string &element, const string &om, const string &d, regression_form form=regression_form::linear, const double &p_value_threshold=0.05)
Build MLR model for single element vs OM and particle size.
bool SetEstimatedMu(const string &element, const double &value)
Set estimated mu parameter for an element.
CMBMatrix CalculateCovarianceMatrix()
Calculate covariance matrix across elements.
bool SetContribution(const double &value)
Set contribution value for this source.
double GetMaximum() const
Get maximum concentration across all elements and samples.
Elemental_Profile_Set ExtractElements(const vector< string > &element_list) const
Create subset with only specified elements.
Elemental_Profile_Set CopyIncludedInAnalysis(bool applyomsizecorrection, const vector< double > &om_size, map< string, element_information > *elementinfo=nullptr)
Copy only samples marked for inclusion in analysis.
bool ContainsElement(const string &element_name) const
Check if an element exists in ALL profiles.
double GetContribution() const
Get contribution value.
MultipleLinearRegressionSet mlr_vs_om_size_
MLR models for OM/size corrections.
QJsonObject toJsonObject() const override
Serialize object to JSON format.
string ToString() const override
Convert object to string representation.
CMBVector CalculateBoxCoxParameters()
Calculate optimal Box-Cox lambda for each element.
double contribution_softmax_
Softmax-transformed contribution.
QTableWidget * ToTable() override
Create a Qt table widget representation of the data.
vector< string > ElementsNotBoxCoxTransformable() const
Elements with a zero or negative value, which Box-Cox leaves untransformed.
CVector CalculateElementMeans(const vector< string > &element_order=vector< string >()) const
Calculate mean concentration for each element.
Distribution * GetFittedDistribution(const string &element_name)
Get fitted distribution for an element (from data, for likelihood).
Elemental_Profile_Set ApplyOrganicMatterAndSizeCorrections(const vector< double > &om_size, map< string, element_information > *elementinfo=nullptr)
Apply OM and particle size corrections to all profiles.
CMBMatrix CalculateCorrelationMatrix()
Calculate correlation matrix across elements.
map< string, ConcentrationSet > element_distributions_
Concentration distributions for each element.
CMBMatrix DetectOutliers(const double &lowerlimit=0, const double &upperlimit=0)
Detect outliers using Box-Cox transformation and standardization.
double GetContributionSoftmax() const
Get softmax-transformed contribution.
Elemental_Profile_Set EliminateSamples(const vector< string > &samples_to_eliminate, map< string, element_information > *elementinfo) const
Create subset excluding specified samples.
MultipleLinearRegressionSet BuildRegressionModels(const string &om, const string &d, regression_form form=regression_form::linear, const double &p_value_threshold=0.05)
Build MLR models for all elements vs OM and particle size.
void SetRegressionModels(const string &om, const string &d, regression_form form=regression_form::linear, const double &p_value_threshold=0.05)
Set regression models (build new).
bool outlierdone_
Flag indicating outlier analysis performed.
double contribution_
Source contribution (for CMB).
Elemental_Profile_Set ApplyBoxCoxTransform(CMBVector *lambda_vals=nullptr)
Apply Box-Cox transformation to all profiles.
vector< string > CheckForNegativeValues(const vector< string > &element_names) const
Check for elements with negative values.
bool SetEstimatedSigma(const string &element, const double &value)
Set estimated sigma parameter for an element.
void AppendProfiles(const Elemental_Profile_Set &profiles, map< string, element_information > *elementinfo)
Add multiple profiles from another set.
Elemental_Profile_Set ExtractChemicalElements(const map< string, element_information > *elementinfo, bool isotopes) const
Create subset with only chemical elements (and optionally isotopes).
Container for elemental concentration data of a single sediment sample.
Interface()
Default constructor.
Definition interface.cpp:6
distribution_type
Enumeration of probability distribution types supported in SedSat3.
Elemental concentration profile for sediment source fingerprinting.