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#ifndef ELEMENTAL_PROFILE_SET_H
2#define ELEMENTAL_PROFILE_SET_H
3
4#include <elemental_profile.h>
5#include <map>
6#include <string>
7#include <vector>
8#include "concentrationset.h"
9#include "interface.h"
11#include "resultitem.h"
12#include <gsl/gsl_vector.h>
13#include <gsl/gsl_matrix.h>
14#include "cmbvector.h"
15
27class Elemental_Profile_Set : public map<string, Elemental_Profile>, public Interface
28{
29public:
30 // ========== Construction and Assignment ==========
31
35
36 // ========== Data Management ==========
37
46 const string& name,
47 const Elemental_Profile& profile = Elemental_Profile(),
48 map<string, element_information>* elementinfo = nullptr
49 );
50
56 void AppendProfiles(
57 const Elemental_Profile_Set& profiles,
58 map<string, element_information>* elementinfo
59 );
60
67
68 // ========== Data Access ==========
69
74 Elemental_Profile* GetProfile(const string& name);
75
80 Elemental_Profile GetProfile(const string& name) const;
81
86 Elemental_Profile* GetProfile(unsigned int index);
87
92 Elemental_Profile GetProfile(unsigned int index) const;
93
97 vector<string> GetSampleNames() const;
98
102 vector<string> GetElementNames() const;
103
107 vector<double> GetAllConcentrationsFor(const string& element_name);
108
112 vector<double> GetConcentrationsForSample(const string& sample_name) const;
113
117 bool ContainsElement(const string& element_name) const;
118
119 // ========== Data Extraction and Filtering ==========
120
124 Elemental_Profile_Set ExtractElements(const vector<string>& element_list) const;
125
132 const map<string, element_information>* elementinfo,
133 bool isotopes
134 ) const;
135
145 bool exclude_samples,
146 bool exclude_elements,
147 bool omnsizecorrect,
148 const vector<double>& om_size,
149 const map<string, element_information>* elementinfo = nullptr
150 ) const;
151
156 bool applyomsizecorrection,
157 const vector<double>& om_size,
158 map<string, element_information>* elementinfo = nullptr
159 );
160
165 vector<string> samples_to_eliminate,
166 map<string, element_information>* elementinfo
167 ) const;
168
169 // ========== Statistical Analysis ==========
170
174 ConcentrationSet* GetElementDistribution(const string& element_name);
175
179 ConcentrationSet GetElementDistribution(const string& element_name) const;
180
184 distribution_type GetAssignedDistribution(const string& element_name) const;
185
189 CVector CalculateElementMeans(const vector<string>& element_order = vector<string>()) const;
190
195
200
205
209 double GetMaximum() const;
210
214 double GetMinimum() const;
215
216 // ========== Estimated Distribution Parameters (for MCMC) ==========
217
221 double GetEstimatedMu(const string& element) const;
222
226 double GetEstimatedSigma(const string& element) const;
227
231 bool SetEstimatedMu(const string& element, const double& value);
232
236 bool SetEstimatedSigma(const string& element, const double& value);
237
241 Distribution* GetEstimatedDistribution(const string& element_name);
242
246 Distribution* GetFittedDistribution(const string& element_name);
247
248 // ========== Regression Models (OM/Size Corrections) ==========
249
254 const string& om,
255 const string& d,
257 const double& p_value_threshold = 0.05
258 );
259
264 const string& element,
265 const string& om,
266 const string& d,
268 const double& p_value_threshold = 0.05
269 );
270
275 const string& om,
276 const string& d,
278 const double& p_value_threshold = 0.05
279 );
280
285
290
295
300 const vector<double>& om_size,
301 map<string, element_information>* elementinfo = nullptr
302 );
303
304 // ========== Box-Cox Transformations ==========
305
310
315
316 // ========== Outlier Detection ==========
317
324 CMBMatrix DetectOutliers(const double& lowerlimit = 0, const double& upperlimit = 0);
325
329 bool OutlierAnalysisDone() const { return outlierdone_; }
330
334 vector<string> CheckForNegativeValues(const vector<string>& element_names) const;
335
336 // ========== Source Contribution (for CMB) ==========
337
341 bool SetContribution(const double& value);
342
346 double GetContribution() const { return contribution_; }
347
351 bool SetContributionSoftmax(const double& value);
352
357
358 // ========== Utility Functions ==========
359
364
368 CMBVector CalculateDotProduct(const CVector& v) const;
369
373 CMBMatrix ToMatrix() const;
374
378 gsl_matrix* CopyToGSLMatrix() const;
379
380 // ========== Serialization ==========
381
382 string ToString() const override;
383 QTableWidget* ToTable() override;
384 bool writetofile(QFile* file) override;
385 QJsonObject toJsonObject() const override;
386 bool ReadFromJsonObject(const QJsonObject& jsonobject) override;
387 bool Read(const QStringList& strlist) override;
388
389private:
390 map<string, ConcentrationSet> element_distributions_;
392 double contribution_ = 0.0;
394 bool outlierdone_ = false;
395};
396
397#endif // ELEMENTAL_PROFILE_SET_H
Matrix class with labeled rows and columns for Chemical Mass Balance analysis.
Definition cmbmatrix.h:19
Vector class with string labels for Chemical Mass Balance analysis.
Definition cmbvector.h:17
Manages a collection of concentration measurements with statistical analysis.
Represents a parametric probability distribution for uncertainty quantification.
Manages a collection of elemental profiles (samples) for source fingerprinting analysis.
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.
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.
Elemental_Profile_Set EliminateSamples(vector< string > samples_to_eliminate, map< string, element_information > *elementinfo) const
Create subset excluding specified samples.
double GetContributionSoftmax() const
Get softmax-transformed contribution.
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.
Abstract base class providing common serialization and visualization interface.
Definition interface.h:65
distribution_type
Enumeration of probability distribution types supported in SedSat3.
Elemental concentration profile for sediment source fingerprinting.