SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
sourcesinkdata.h
Go to the documentation of this file.
1#ifndef SOURCESINKDATA_H
2#define SOURCESINKDATA_H
3
5#include "vector"
6#include "parameter.h"
7#include "observation.h"
8#include "contribution.h"
9#include "results.h"
10#include "ProgressWindow.h"
11#include "fstream"
12#include "qjsonobject.h"
13#include "cmbvector.h"
14#include "cmbvectorset.h"
15#include "cmbvectorsetset.h"
16#include "MCMC.h"
17
19
21{
22 vector<string> element_names;
23 vector<string> sample_names;
24 vector<vector<double>> values;
25};
26
28{
29 string group_name;
30 vector<string> sample_names;
31 vector<double> values;
32};
33
35{
36 vector<string> group_names;
37 vector<string> sample_names;
38 vector<vector<double>> values;
39};
40
50
52{
53 double F = 0;
54 double SST = 0;
55 double SSB = 0;
56 double SSW = 0;
57 double MSB = 0;
58 double MSW = 0;
59 double p_value = 0;
60};
61
63
65
66class SourceSinkData : public map<string, Elemental_Profile_Set>
67{
68public:
69 // ========== Construction and Assignment ==========
70
78
88 SourceSinkData(const SourceSinkData& other);
89
100
101 // ========== Data Loading and Management ==========
102
115 void Clear();
116
129 const string& name,
131 );
132
143 vector<string> SourceGroupNames() const;
144
156 bool SetSelectedTargetSample(const string& sample_name);
157
168
178 bool SetTargetGroup(const string& targroup);
179
185 string GetTargetGroup() const;
186
187 // ========== Dataset Creation and Filtering ==========
188
207 const string& target,
208 bool omnsizecorrect,
209 map<string, element_information>* elementinfo
210 );
211
232 bool exclude_samples,
233 bool exclude_elements,
234 bool omnsizecorrect,
235 const string& target = ""
236 ) const;
237
248 SourceSinkData ExtractChemicalElements(bool isotopes) const;
249
273 SourceSinkData BoxCoxTransformed(bool calculate_optimal_lambda = false);
274
275 // ========== Element Information Management ==========
276
285 map<string, element_information>* GetElementInformation();
286
300 void IncludeExcludeElementsBasedOn(const vector<string>& elements);
301
312 Distribution* GetFittedDistribution(const string& element_name);
313
314 // ========== OM/Size Corrections ==========
315
341 const string& om,
342 const string& particle_size,
343 regression_form form,
344 const double& p_value_threshold = 0.05
345 );
346
355 vector<string> OMandSizeConstituents();
356
370 vector<ResultItem> GetMLRResults();
371
382 string FirstOMConstituent();
383
393 string FirstSizeConstituent();
394
401 void SetOMandSizeConstituents(const string& _omconstituent, const string& _sizeconsituent);
402
408 void SetOMandSizeConstituents(const vector<string>& _omsizeconstituents);
409
410 // ========== Outlier Analysis ==========
411
431 void OutlierAnalysisForAll(const double& lower_threshold = -3, const double& upper_threshold = 3);
432
433 // ========== Validation Tests ==========
434
448 vector<string> NegativeValueCheck();
449
471 CMBVector BracketTest(const string& target_sample, bool correct_based_on_om_n_size);
472
494 CMBMatrix BracketTest(bool correct_based_on_om_n_size, bool exclude_elements, bool exclude_samples);
495
496 // ========== Statistical Analysis - Discriminant Function Analysis ==========
497
520
535 DFA_result DiscriminantFunctionAnalysis(const string& source1, const string& source2);
536
549 DFA_result DiscriminantFunctionAnalysis(const string& source1);
550
569 vector<CMBVector> StepwiseDiscriminantFunctionAnalysis(
570 const string& source1,
571 const string& source2
572 );
573
587 vector<CMBVector> StepwiseDiscriminantFunctionAnalysis();
588
601 vector<CMBVector> StepwiseDiscriminantFunctionAnalysis(const string& source1);
602
603 // ========== Statistical Analysis - Differentiation Power ==========
604
624 Elemental_Profile_Set DifferentiationPower(bool use_log, bool include_target);
625
640
654
680 Elemental_Profile DifferentiationPower_Percentage(const string& source1, const string& source2);
681
708 Elemental_Profile DifferentiationPower(const string& source1, const string& source2, bool use_log);
709
732 Elemental_Profile t_TestPValue(const string& source1, const string& source2, bool use_log);
733
734 // ========== Statistical Analysis - ANOVA ==========
735
752 CMBVector ANOVA(bool use_log);
753
771 ANOVA_info ANOVA(const string& element, bool use_log);
772
773 // ========== Parameter and Observation Setup ==========
774
785 string GetParameterName(int index) const;
786
805 const string& targetsamplename,
807 );
808
820
844 bool SetParameterValue(size_t index, double value);
845
855
856
857
858 // ========== Optimization - Levenberg-Marquardt ==========
859
882
900 transformation transform,
901 bool apply_om_size_correction,
902 map<string, vector<string>>& negative_elements
903 );
904
913 CVector GetPredictedValues();
914
933
934 // ========== MCMC Analysis ==========
935
956 const string& target_sample,
957 map<string, string> arguments,
959 ProgressWindow* progress_window,
960 const string& working_folder
961 );
962
985 map<string, string> arguments,
987 ProgressWindow* progress_window,
988 const string& working_folder
989 );
990
991 // --- Likelihood and Objective Functions ---
992
1003
1015
1016
1017 // ========== Bootstrap and Validation ==========
1018
1036 const double& percentage,
1037 unsigned int num_iterations,
1038 string target_sample,
1039 bool use_softmax
1040 );
1041
1062 bool BootStrap(
1063 Results* results,
1064 const double& percentage,
1065 unsigned int num_iterations,
1066 string target_sample,
1067 bool use_softmax
1068 );
1069
1089 const string& source_group,
1090 bool use_softmax,
1091 bool apply_om_size_correction
1092 );
1093
1094 // ========== Results Retrieval ==========
1095
1107
1119
1132
1147 );
1148
1164 );
1165
1181 );
1182
1198 );
1199
1212
1224
1236
1248
1260
1272
1283 vector<ResultItem> GetSourceProfiles();
1284
1285 // ========== Utility ==========
1286
1295 void AddtoToolsUsed(const string& tool);
1296
1297 // ========== Accessors (inline for performance) ==========
1298
1303 vector<Parameter>& Parameters();
1304
1309 size_t ParametersCount();
1310
1315 size_t ObservationsCount();
1316
1322 Parameter* parameter(size_t i);
1323
1329 const Parameter* parameter(size_t i) const;
1330
1336 Observation* observation(size_t i);
1337
1343
1349 ConcentrationSet* GetElementDistribution(const string& element_name);
1350
1357 ConcentrationSet* GetElementDistribution(const string& element_name, const string& sample_group);
1358
1365 element_information* GetElementInformation(const string& element_name);
1366
1367 // --- Distribution Management ---
1368
1380
1393 void PopulateElementInformation(const map<string, element_information>* ElementInfo = nullptr);
1394
1410
1411 // --- Data Extraction and Management ---
1412
1423 int CountElements(bool exclude_elements) const;
1424
1434 vector<string> GetSampleNames(const string& group_name) const;
1435
1444 vector<string> GetGroupNames() const;
1445
1455 vector<string> GetElementNames() const;
1456
1466 void IncludeExcludeAllElements(bool include_in_analysis);
1467
1481 Elemental_Profile Sample(const string& sample_name) const;
1482
1493 profiles_data ExtractConcentrationData(const vector<vector<string>>& indicators) const;
1494
1505 Elemental_Profile_Set ExtractSamplesAsProfileSet(const vector<vector<string>>& indicators) const;
1506
1518 element_data ExtractElementConcentrations(const string& element, const string& group) const;
1519
1530 map<string, vector<double>> ExtractElementDataByGroup(const string& element) const;
1531
1542 SourceSinkData ExtractSpecificElements(const vector<string>& element_list) const;
1543
1557 map<string, ConcentrationSet> ExtractConcentrationSet();
1558
1559 // --- Element Ordering ---
1560
1571 vector<string> ElementsToBeUsedInCMB();
1572
1584 vector<string> IsotopesToBeUsedInCMB();
1585
1602
1608 string SelectedTargetSample() const;
1609
1610 // --- Tools Tracking ---
1611
1621 bool ToolsUsed(const string& tool_name);
1622
1623 // --- File I/O ---
1624
1633 string GetOutputPath() const;
1634
1641 QMap<QString, double>* GetOptions();
1642
1652 bool SetOutputPath(const string& output_path);
1653
1662 QJsonObject ElementInformationToJsonObject() const;
1663
1672 QJsonArray ToolsUsedToJsonObject() const;
1673
1682 QJsonObject OptionsToJsonObject() const;
1683
1690 bool ReadToolsUsedFromJsonObject(const QJsonArray& jsonarray);
1691
1703 bool ReadElementInformationfromJsonObject(const QJsonObject& jsonobject);
1704
1716 bool ReadElementDatafromJsonObject(const QJsonObject& jsonobject);
1717
1726 bool ReadOptionsfromJsonObject(const QJsonObject& jsonobject);
1727
1735 QJsonObject ElementDataToJsonObject() const;
1736
1748 bool WriteDataToFile(QFile* file);
1749
1758 bool WriteToFile(QFile* file);
1759
1772 bool ReadFromFile(QFile* fil);
1773private:
1774 // ========== Private Data Members ==========
1775
1776 // Element Metadata and Distributions
1777 map<string, element_information> element_information_;
1778 map<string, ConcentrationSet> element_distributions_;
1779
1780 // Counters
1784
1785 // MCMC/Optimization Data
1786 vector<Observation> observations_;
1787 vector<Parameter> parameters_;
1788
1789 // File Paths
1791
1792 // Group and Sample Identifiers
1795
1796 // Ordering Vectors
1797 vector<string> samplesetsorder_;
1798 vector<string> constituent_order_;
1799 vector<string> element_order_;
1800 vector<string> isotope_order_;
1801 vector<string> size_om_order_;
1802
1803 // Analysis Settings
1811 double epsilon_;
1812
1813 // UI and Tracking
1815 list<string> tools_used_;
1816 QMap<QString, double> options_;
1817
1818 // ========== Private Helper Methods ==========
1819
1820
1834 Elemental_Profile* GetElementalProfile(const string& sample_name);
1835
1836 // --- Element Role Conversion ---
1837
1856 QString Role(const element_information::role& role) const;
1857
1876 element_information::role Role(const QString& role_string) const;
1877
1878 // --- Parameter Management ---
1879
1888 double GetParameterValue(size_t index) const;
1889
1901 bool SetParameterValue(const CVector& values);
1902
1911 CVector GetParameterValue() const;
1912
1913 // --- Contribution Initialization ---
1914
1925
1939
1940 // --- Contribution Accessors ---
1941
1953 CVector GetSourceContributions();
1954
1969 CVector GetContributionVector(bool include_all = true);
1970
1982
1994 void SetContribution(size_t source_index, double contribution_value);
1995
2007 void SetContributionSoftmax(size_t source_index, double softmax_value);
2008
2019 void SetContribution(const CVector& contributions);
2020
2031 void SetContributionSoftmax(const CVector& softmax_params);
2032
2033 // --- Distribution Parameter Accessors ---
2034
2047 Parameter* GetElementDistributionMuParameter(size_t element_index, size_t source_index);
2048
2061 Parameter* GetElementDistributionSigmaParameter(size_t element_index, size_t source_index);
2062
2070 double GetElementDistributionMuValue(size_t element_index, size_t source_index);
2071
2079 double GetElementDistributionSigmaValue(size_t element_index, size_t source_index);
2080
2081 // --- Observation Data ---
2082
2092 CVector ObservedDataforSelectedSample(const string& SelectedTargetSample = "");
2093
2105
2116
2117 // --- Prediction Methods ---
2118
2130
2141
2152
2166
2182
2183 // --- Likelihood and Prior Calculations ---
2192 double LogPriorContributions();
2193
2203
2217
2231
2232 // --- Optimization Helper Methods ---
2233
2250 CVector Gradient(const CVector& parameters, estimation_mode est_mode);
2251
2265 CVector ResidualVector();
2266
2275 CVector_arma ResidualVector_arma();
2276
2290 CMatrix_arma ResidualJacobian_arma();
2291
2302 CMatrix ResidualJacobian();
2303
2315 CMatrix ResidualJacobian_softmax();
2316
2331 CVector OneStepLevenberg_Marquardt(double lambda);
2332
2343 CVector OneStepLevenberg_Marquardt_softmax(double lambda);
2344
2350 vector<string> GetSourceOrder() const;
2351
2357 vector<string> SamplesetsOrder();
2358
2364 vector<string> ConstituentOrder();
2365
2371 vector<string> ElementOrder();
2372
2378 vector<string> IsotopeOrder();
2379
2385 vector<string> SizeOMOrder();
2386
2387 // --- Statistical Methods ---
2388
2398 int TotalNumberofSourceSamples() const;
2399
2414 double GrandMean(const string& element, bool use_log);
2415
2426
2427 // --- Box-Cox Transformation ---
2428
2449
2450 // --- Bootstrap Helpers ---
2451
2464 SourceSinkData RandomlyEliminateSourceSamples(const double& percentage);
2465
2476 vector<string> AllSourceSampleNames() const;
2477
2490 vector<string> RandomlypickSamples(const double& percentage) const;
2491
2503 SourceSinkData ReplaceSourceAsTarget(const string& source_sample_name) const;
2504
2505 // --- DFA Helper Methods ---
2506
2521
2535
2550 CMatrix TotalScatterMatrix();
2551
2568 double WilksLambda();
2569
2583 double DFA_P_Value();
2584
2594
2604 CMBVectorSet DFA_Projected(const string& source1, const string& source2);
2605
2618 CMBVectorSet DFA_Projected(const string& source1, SourceSinkData* original);
2619
2632
2645 CMBVector DFA_weight_vector(const string& source1, const string& source2);
2646
2659 CMBVector DFATransformed(const CMBVector& eigenvector, const string& source_group);
2660
2672 Elemental_Profile_Set TheRest(const string& excluded_source);
2673
2674 // --- Mean Calculation ---
2675
2687 CMBVector MeanElementalContent(const string& group_name);
2688
2703
2704
2705};
2706
2707#endif // SOURCESINKDATA_H
Matrix class with labeled rows and columns for Chemical Mass Balance analysis.
Definition cmbmatrix.h:19
Collection of time series with labels and observed values.
Collection of named CMBVectorSet objects for hierarchical data organization.
Collection of named CMBVector objects for multi-variable analysis.
Vector class with string labels for Chemical Mass Balance analysis.
Definition cmbvector.h:17
Markov Chain Monte Carlo sampler for Bayesian parameter estimation.
Definition MCMC.h:326
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.
Container for elemental concentration data of a single sediment sample.
Represents a model parameter with prior distribution and constraints.
Definition parameter.h:73
Elemental_Profile * GetElementalProfile(const string &sample_name)
Finds and retrieves an elemental profile by sample name.
CMatrix BetweenGroupCovarianceMatrix()
Computes between-group covariance matrix.
vector< string > IsotopesToBeUsedInCMB()
Identifies isotopes to be used in CMB analysis.
profiles_data ExtractConcentrationData(const vector< vector< string > > &indicators) const
Extract concentration data for specified samples.
Parameter * GetElementDistributionSigmaParameter(size_t element_index, size_t source_index)
Retrieves pointer to the σ (std dev) parameter for an element distribution.
void AssignAllDistributions()
Assign distributions to all elements at both dataset and group levels.
vector< string > element_order_
string GetOutputPath() const
Get the output directory path.
bool InitializeParametersAndObservations(const string &targetsamplename, estimation_mode est_mode=estimation_mode::elemental_profile_and_contribution)
Initialize parameters and observations for MCMC optimization.
Elemental_Profile Sample(const string &sample_name) const
Retrieves an elemental profile by sample name.
QMap< QString, double > * GetOptions()
Retrieves pointer to the options map.
void SetProgressWindow(ProgressWindow *_rtw)
Sets the progress window for displaying optimization progress.
size_t ParametersCount()
Returns the number of parameters.
bool PerformRegressionVsOMAndSize(const string &om, const string &particle_size, regression_form form, const double &p_value_threshold=0.05)
Performs multiple linear regression of elements vs OM and particle size.
vector< string > size_om_order_
bool ReadFromFile(QFile *fil)
Loads complete dataset from a JSON file.
vector< Parameter > & Parameters()
Retrieves reference to the parameters vector.
ResultItem GetCalculatedElementMu()
Computes μ parameters from fitted log-normal distributions for source elements.
ResultItem GetObservedElementalProfile()
Retrieves the observed elemental concentrations for the selected target sample.
bool ReadElementInformationfromJsonObject(const QJsonObject &jsonobject)
Deserializes element information metadata from a JSON object.
map< string, vector< double > > ExtractElementDataByGroup(const string &element) const
Extract concentration data for a specific element from all groups.
Elemental_Profile_Set DifferentiationPower_Percentage(bool include_target)
Computes rank-based differentiation percentage for all source pairs.
CVector GetContributionVector(bool include_all=true)
Retrieves the current source contribution fractions.
CMBTimeSeriesSet BootStrap(const double &percentage, unsigned int num_iterations, string target_sample, bool use_softmax)
Performs bootstrap uncertainty analysis on source contributions.
double GetElementDistributionMuValue(size_t element_index, size_t source_index)
Retrieves the current value of the μ parameter for an element distribution.
vector< string > GetElementNames() const
Get all element names in the dataset.
SourceSinkData ExtractChemicalElements(bool isotopes) const
Extract only chemical elements (and optionally isotopes)
Observation * observation(size_t i)
Retrieves pointer to an observation by index.
SourceSinkData & operator=(const SourceSinkData &other)
Assignment operator.
Elemental_Profile_Set TheRest(const string &excluded_source)
Collects all source samples except those from a specified source group.
CMBVector ANOVA(bool use_log)
Performs one-way ANOVA for all elements across source groups.
CMBVector OptimalBoxCoxParameters()
Computes optimal Box-Cox transformation parameters for all elements.
CVector PredictTarget_Isotope(parameter_mode param_mode=parameter_mode::direct)
Predicts target sample isotopic compositions based on source contributions.
void OutlierAnalysisForAll(const double &lower_threshold=-3, const double &upper_threshold=3)
Performs outlier detection on all source groups.
bool SolveLevenberg_Marquardt(transformation trans=transformation::linear)
Solves for optimal source contributions using the Levenberg-Marquardt algorithm.
CMatrix_arma ResidualJacobian_arma()
Calculates the Jacobian matrix of residuals with respect to contributions (Armadillo)
CMBVectorSet DFA_Projected()
Projects all groups onto the discriminant function axis.
ConcentrationSet * GetElementDistribution(const string &element_name)
Retrieves pointer to element distribution at dataset level.
SourceSinkData BoxCoxTransformed(bool calculate_optimal_lambda=false)
Applies Box-Cox transformation to all source groups for normalization.
CVector OneStepLevenberg_Marquardt(double lambda)
Performs one iteration of the Levenberg-Marquardt optimization algorithm.
CMatrix ResidualJacobian_softmax()
Calculates the Jacobian using softmax parameterization of contributions.
void SetParameterEstimationMode(estimation_mode est_mode)
Sets the estimation mode for parameter optimization.
CMBVector DFA_weight_vector(const string &source1, const string &source2)
Computes discriminant weight vector for two-group comparison.
Elemental_Profile_Set * GetSampleSet(const string &name)
Get a sample set (source or target group) by name.
Elemental_Profile_Set * AppendSampleSet(const string &name, const Elemental_Profile_Set &elemental_profile_set=Elemental_Profile_Set())
Add a new sample set (source or target group) to the dataset.
void Clear()
Clear all data from the object.
double regression_p_value_threshold_
CMBMatrix MCMC_Batch(map< string, string > arguments, CMCMC< SourceSinkData > *mcmc, ProgressWindow *progress_window, const string &working_folder)
Performs batch MCMC analysis on all target samples.
CMatrix WithinGroupCovarianceMatrix()
Computes pooled within-group covariance matrix.
double LogLikelihoodModelvsMeasured(estimation_mode est_mode=estimation_mode::elemental_profile_and_contribution)
Calculates the log-likelihood of the model prediction versus measured data.
CVector ObservedDataforSelectedSample_Isotope_delta(const string &SelectedTargetSample="")
Retrieves the observed isotopic data in delta notation.
Elemental_Profile t_TestPValue(const string &source1, const string &source2, bool use_log)
Computes t-test p-values for element-wise differences between two sources.
vector< Observation > observations_
Distribution * GetFittedDistribution(const string &element_name)
Get the fitted distribution for a specific element at dataset level.
double WilksLambda()
Computes Wilks' Lambda statistic for multivariate group separation.
map< string, ConcentrationSet > ExtractConcentrationSet()
Extracts concentration distributions for all elements across sources.
list< string > tools_used_
bool SetParameterValue(size_t index, double value)
Sets a parameter value and updates corresponding model components.
CVector GetParameterValue() const
Retrieves all current parameter values as a vector.
vector< string > SourceGroupNames() const
Retrieves the names of all source groups (excluding target)
bool ToolsUsed(const string &tool_name)
Checks if a specific analysis tool has been used.
vector< ResultItem > GetMLRResults()
Retrieves multiple linear regression results for all sample groups.
vector< string > RandomlypickSamples(const double &percentage) const
Randomly selects a subset of source samples.
CVector ObservedDataforSelectedSample_Isotope(const string &SelectedTargetSample="")
Retrieves the observed isotopic data for a selected target sample.
estimation_mode parameter_estimation_mode_
bool SetOutputPath(const string &output_path)
Set the output directory path.
ResultItem GetPredictedElementalProfile_Isotope(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Generates predicted isotope delta values for the target sample.
CMBVector BracketTest(const string &target_sample, bool correct_based_on_om_n_size)
Performs bracket test to check if target concentrations fall within source ranges.
bool ReadElementDatafromJsonObject(const QJsonObject &jsonobject)
Deserializes elemental profile data from a JSON object.
Elemental_Profile_Set ExtractSamplesAsProfileSet(const vector< vector< string > > &indicators) const
Extract samples as an Elemental_Profile_Set.
vector< string > isotope_order_
CVector GetContributionVectorSoftmax()
Retrieves the softmax parameters for source contributions.
void IncludeExcludeElementsBasedOn(const vector< string > &elements)
Sets element inclusion based on a specified list.
ResultItem GetPredictedElementalProfile(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Generates predicted elemental concentrations for the target sample.
CVector GetPredictedValues()
Retrieves predicted values for all observations.
QJsonObject ElementInformationToJsonObject() const
Exports element information metadata to a JSON object.
ResultItem GetCalculatedElementSigma()
Computes estimated standard deviations for all source elements.
QJsonObject OptionsToJsonObject() const
Exports analysis options/settings to a JSON object.
void SetOMandSizeConstituents(const string &_omconstituent, const string &_sizeconsituent)
Sets the names of OM and particle size constituents.
Parameter * parameter(size_t i)
Retrieves pointer to a parameter by index.
bool ReadToolsUsedFromJsonObject(const QJsonArray &jsonarray)
Deserializes the list of analysis tools from a JSON array.
SourceSinkData RandomlyEliminateSourceSamples(const double &percentage)
Creates dataset with randomly excluded source samples for validation.
CVector Gradient(const CVector &parameters, estimation_mode est_mode)
Computes the normalized gradient of the log-likelihood function.
void SetContributionSoftmax(size_t source_index, double softmax_value)
Sets a single softmax parameter value.
vector< string > constituent_order_
SourceSinkData ReplaceSourceAsTarget(const string &source_sample_name) const
Creates a new dataset with a source sample designated as the target.
double LogPriorContributions()
Calculates the log prior probability for source contributions.
CVector ResidualVector()
Calculates the combined residual vector for elemental and isotopic predictions.
SourceSinkData CreateCorrectedAndFilteredDataset(bool exclude_samples, bool exclude_elements, bool omnsizecorrect, const string &target="") const
Create a corrected and filtered copy of the dataset.
QJsonObject ElementDataToJsonObject() const
Exports all elemental profile data to a JSON object.
vector< string > NegativeValueCheck()
Checks for zero or negative concentration values across all sources.
CMBTimeSeriesSet VerifySource(const string &source_group, bool use_softmax, bool apply_om_size_correction)
Performs leave-one-out validation on a source group.
bool SetSelectedTargetSample(const string &sample_name)
Sets the currently selected target sample for analysis.
map< string, element_information > * GetElementInformation()
Retrieves pointer to the element information map.
void AddtoToolsUsed(const string &tool)
Adds a tool name to the list of tools used in analysis.
QMap< QString, double > options_
DFA_result DiscriminantFunctionAnalysis()
Performs discriminant function analysis for all source groups.
vector< string > ElementsToBeUsedInCMB()
Identifies chemical elements to be used in CMB analysis.
map< string, ConcentrationSet > element_distributions_
vector< string > SizeOMOrder()
Retrieves the ordering of size and OM constituents.
void PopulateConstituentOrders()
Populates all element ordering vectors used throughout CMB analysis.
vector< ResultItem > GetSourceProfiles()
Retrieves elemental profiles for all source groups.
CMatrix BuildSourceMeanMatrix_Isotopes(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Builds the source mean concentration matrix for isotopes.
map< string, element_information > element_information_
void PopulateElementInformation(const map< string, element_information > *ElementInfo=nullptr)
Populate element information metadata.
ProgressWindow * rtw_
ResultItem GetCalculatedElementMeans()
Computes estimated mean concentrations for all source elements.
Results MCMC(const string &target_sample, map< string, string > arguments, CMCMC< SourceSinkData > *mcmc, ProgressWindow *progress_window, const string &working_folder)
Performs Markov Chain Monte Carlo analysis for Bayesian source apportionment.
Elemental_Profile_Set DifferentiationPower(bool use_log, bool include_target)
Computes differentiation power for all source pairs.
string GetParameterName(int index) const
Get the name of a parameter by its index.
double LogLikelihoodSourceElementalDistributions()
Calculates the log-likelihood of source elemental distributions.
vector< string > samplesetsorder_
bool InitializeContributionsRandomly()
Initialize source contributions randomly (linear constraint)
double LogLikelihood(estimation_mode est_mode=estimation_mode::elemental_profile_and_contribution)
Calculates the total log-likelihood for Bayesian source apportionment.
QString Role(const element_information::role &role) const
Converts element role enum to string representation.
size_t ObservationsCount()
Returns the number of observations.
CVector GradientUpdate(estimation_mode estmode=estimation_mode::elemental_profile_and_contribution)
Performs one gradient ascent step with adaptive step size.
SourceSinkData CreateCorrectedDataset(const string &target, bool omnsizecorrect, map< string, element_information > *elementinfo)
Create a corrected copy of the dataset for a specific target sample.
vector< CMBVector > StepwiseDiscriminantFunctionAnalysis()
Performs stepwise discriminant analysis across all source groups.
vector< string > GetSampleNames(const string &group_name) const
Get all sample names within a specific group.
CMBVector MeanElementalContent()
Computes weighted mean elemental concentrations across all sources.
CMatrix TotalScatterMatrix()
Computes total scatter matrix.
ResultItem GetEstimatedElementSigma()
Retrieves estimated σ parameters from Bayesian inference for source elements.
double GrandMean(const string &element, bool use_log)
Computes grand mean concentration for an element across all sources.
void IncludeExcludeAllElements(bool include_in_analysis)
Sets inclusion flag for all elements.
string FirstOMConstituent()
Retrieves the name of the first organic matter constituent.
CVector OneStepLevenberg_Marquardt_softmax(double lambda)
Performs one iteration of Levenberg-Marquardt using softmax parameterization.
CVector PredictTarget(parameter_mode param_mode=parameter_mode::direct)
Predicts target sample elemental concentrations based on source contributions.
vector< string > ElementOrder()
Retrieves the ordering of chemical elements.
vector< string > GetGroupNames() const
Get all group names in the dataset.
string SelectedTargetSample() const
Retrieves the name of the currently selected target sample.
ResultItem GetObservedvsModeledElementalProfile(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Creates a comparison of observed vs modeled elemental profiles.
vector< string > IsotopeOrder()
Retrieves the ordering of isotopes.
int CountElements(bool exclude_elements) const
Count the number of elements in the dataset.
SourceSinkData ExtractSpecificElements(const vector< string > &element_list) const
Extract specific elements from source groups.
bool InitializeContributionsRandomlySoftmax()
Initialize source contributions randomly (softmax transformation)
int TotalNumberofSourceSamples() const
Counts the total number of source samples across all source groups.
Parameter * GetElementDistributionMuParameter(size_t element_index, size_t source_index)
Retrieves pointer to the μ (mean) parameter for an element distribution.
estimation_mode ParameterEstimationMode()
Retrieves the current estimation mode.
element_data ExtractElementConcentrations(const string &element, const string &group) const
Extract concentration data for a specific element from a group.
double DFA_P_Value()
Computes p-value for discriminant function analysis.
ResultItem GetEstimatedElementMean()
Computes actual mean concentrations from estimated log-normal parameters.
string GetTargetGroup() const
Retrieves the name of the target group.
void PopulateElementDistributions()
Populate element distributions from all groups.
Elemental_Profile_Set DifferentiationPower_P_value(bool include_target)
Computes t-test p-values for all source pairs.
CVector PredictTarget_Isotope_delta(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Predicts target sample isotopic compositions in delta notation.
ResultItem GetContribution()
Packages source contributions into a ResultItem for output.
CVector_arma ResidualVector_arma()
Calculates the combined residual vector using Armadillo vector format.
vector< string > AllSourceSampleNames() const
Retrieves names of all samples across all source groups.
string FirstSizeConstituent()
Retrieves the name of the first particle size constituent.
bool ReadOptionsfromJsonObject(const QJsonObject &jsonobject)
Deserializes analysis options from a JSON object.
string selected_target_sample_
double GetObjectiveFunctionValue()
Returns the objective function value for optimization algorithms.
CMBVector DFATransformed(const CMBVector &eigenvector, const string &source_group)
Projects samples onto a discriminant function axis.
CMBTimeSeriesSet LM_Batch(transformation transform, bool apply_om_size_correction, map< string, vector< string > > &negative_elements)
Solves CMB model for all target samples using Levenberg-Marquardt.
vector< Parameter > parameters_
bool SetTargetGroup(const string &targroup)
Sets the target/sink group designation.
vector< string > GetSourceOrder() const
Retrieves the ordering of source groups.
vector< string > ConstituentOrder()
Retrieves the ordering of all constituents.
CVector ObservedDataforSelectedSample(const string &SelectedTargetSample="")
Retrieves the observed elemental data for a selected target sample.
ResultItem GetObservedElementalProfile_Isotope()
Retrieves the observed isotope delta values for the selected target sample.
CMatrix ResidualJacobian()
Calculates the Jacobian matrix of residuals with respect to contributions.
CMatrix BuildSourceMeanMatrix(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Builds the source mean concentration matrix for chemical elements.
CVector GetSourceContributions()
Retrieves the contributions from all sources.
double GetElementDistributionSigmaValue(size_t element_index, size_t source_index)
Retrieves the current value of the σ parameter for an element distribution.
QJsonArray ToolsUsedToJsonObject() const
Exports the list of analysis tools used to a JSON array.
double error_stdev_isotope_
Elemental_Profile_Set LumpAllProfileSets()
Combines all source samples into a single profile set.
double LogLikelihoodModelvsMeasured_Isotope(estimation_mode est_mode=estimation_mode::elemental_profile_and_contribution)
Calculates the log-likelihood of model versus measured isotopic data.
bool WriteDataToFile(QFile *file)
Writes elemental profile data to a text file.
bool WriteToFile(QFile *file)
Writes dataset to a text file.
vector< string > SamplesetsOrder()
Retrieves the ordering of sample sets.
void SetContribution(size_t source_index, double contribution_value)
Sets a single source contribution value.
ResultItem GetEstimatedElementMu()
Retrieves estimated μ parameters from Bayesian inference for source elements.
CMBVector DFA_eigvector()
Computes the primary discriminant function eigenvector.
ResultItem GetObservedvsModeledElementalProfile_Isotope(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Creates a comparison of observed vs modeled isotope delta values.
vector< string > OMandSizeConstituents()
Retrieves the names of OM and particle size constituents.
SourceSinkData()
Default constructor.
parameter_mode
Specifies whether to use direct data statistics or fitted distribution parameters.
@ based_on_fitted_distribution
Calculate from fitted distribution parameters.
@ direct
Use empirical statistics from data.
@ elemental_profile_set
transformation
estimation_mode
@ elemental_profile_and_contribution
@ source_elemental_profiles_based_on_source_data
negative_reporting
CMBVectorSet projected
CMBVector p_values
CMBVectorSet eigen_vectors
CMBVector F_test_P_value
CMBVector wilkslambda
CMBVectorSetSet multi_projected
vector< string > sample_names
vector< vector< double > > values
vector< string > group_names
vector< string > sample_names
vector< double > values
Metadata describing an element's role and properties in analysis.
role
Classification of element types.
vector< vector< double > > values
vector< string > element_names
vector< string > sample_names