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 "progressreporter.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 ProgressReporter* progress_window,
960 const string& working_folder
961 );
962
989 map<string, string> arguments,
991 ProgressReporter* progress_window,
992 const string& working_folder,
993 vector<string>* failed_writes = nullptr
994 );
995
996 // --- Likelihood and Objective Functions ---
997
1008
1020
1021
1022 // ========== Bootstrap and Validation ==========
1023
1041 const double& percentage,
1042 unsigned int num_iterations,
1043 string target_sample,
1044 bool use_softmax
1045 );
1046
1067 bool BootStrap(
1068 Results* results,
1069 const double& percentage,
1070 unsigned int num_iterations,
1071 string target_sample,
1072 bool use_softmax
1073 );
1074
1094 const string& source_group,
1095 bool use_softmax,
1096 bool apply_om_size_correction
1097 );
1098
1099 // ========== Results Retrieval ==========
1100
1112
1124
1137
1152 );
1153
1169 );
1170
1186 );
1187
1203 );
1204
1217
1229
1241
1253
1265
1277
1288 vector<ResultItem> GetSourceProfiles();
1289
1290 // ========== Utility ==========
1291
1300 void AddtoToolsUsed(const string& tool);
1301
1302 // ========== Accessors (inline for performance) ==========
1303
1308 vector<Parameter>& Parameters();
1309
1314 size_t ParametersCount();
1315
1320 size_t ObservationsCount();
1321
1327 Parameter* parameter(size_t i);
1328
1334 const Parameter* parameter(size_t i) const;
1335
1341 Observation* observation(size_t i);
1342
1348
1354 ConcentrationSet* GetElementDistribution(const string& element_name);
1355
1362 ConcentrationSet* GetElementDistribution(const string& element_name, const string& sample_group);
1363
1370 element_information* GetElementInformation(const string& element_name);
1371
1372 // --- Distribution Management ---
1373
1385
1398 void PopulateElementInformation(const map<string, element_information>* ElementInfo = nullptr);
1399
1415
1416 // --- Data Extraction and Management ---
1417
1428 int CountElements(bool exclude_elements) const;
1429
1439 vector<string> GetSampleNames(const string& group_name) const;
1440
1449 vector<string> GetGroupNames() const;
1450
1460 vector<string> GetElementNames() const;
1461
1471 void IncludeExcludeAllElements(bool include_in_analysis);
1472
1486 Elemental_Profile Sample(const string& sample_name) const;
1487
1498 profiles_data ExtractConcentrationData(const vector<vector<string>>& indicators) const;
1499
1510 Elemental_Profile_Set ExtractSamplesAsProfileSet(const vector<vector<string>>& indicators) const;
1511
1523 element_data ExtractElementConcentrations(const string& element, const string& group) const;
1524
1535 map<string, vector<double>> ExtractElementDataByGroup(const string& element) const;
1536
1547 SourceSinkData ExtractSpecificElements(const vector<string>& element_list) const;
1548
1562 map<string, ConcentrationSet> ExtractConcentrationSet();
1563
1564 // --- Element Ordering ---
1565
1576 vector<string> ElementsToBeUsedInCMB();
1577
1589 vector<string> IsotopesToBeUsedInCMB();
1590
1607
1613 string SelectedTargetSample() const;
1614
1615 // --- Tools Tracking ---
1616
1626 bool ToolsUsed(const string& tool_name);
1627
1628 // --- File I/O ---
1629
1638 string GetOutputPath() const;
1639
1646 QMap<QString, double>* GetOptions();
1647
1657 bool SetOutputPath(const string& output_path);
1658
1667 QJsonObject ElementInformationToJsonObject() const;
1668
1677 QJsonArray ToolsUsedToJsonObject() const;
1678
1687 QJsonObject OptionsToJsonObject() const;
1688
1695 bool ReadToolsUsedFromJsonObject(const QJsonArray& jsonarray);
1696
1708 bool ReadElementInformationfromJsonObject(const QJsonObject& jsonobject);
1709
1721 bool ReadElementDatafromJsonObject(const QJsonObject& jsonobject);
1722
1731 bool ReadOptionsfromJsonObject(const QJsonObject& jsonobject);
1732
1740 QJsonObject ElementDataToJsonObject() const;
1741
1753 bool WriteDataToFile(QFile* file);
1754
1763 bool WriteToFile(QFile* file);
1764
1777 bool ReadFromFile(QFile* fil);
1778private:
1779 // ========== Private Data Members ==========
1780
1781 // Element Metadata and Distributions
1782 map<string, element_information> element_information_;
1783 map<string, ConcentrationSet> element_distributions_;
1784
1785 // Counters
1789
1790 // MCMC/Optimization Data
1791 vector<Observation> observations_;
1792 vector<Parameter> parameters_;
1793
1794 // File Paths
1796
1797 // Group and Sample Identifiers
1800
1801 // Ordering Vectors
1802 vector<string> samplesetsorder_;
1803 vector<string> constituent_order_;
1804 vector<string> element_order_;
1805 vector<string> isotope_order_;
1806 vector<string> size_om_order_;
1807
1808 // Analysis Settings
1816 double epsilon_;
1817
1818 // UI and Tracking
1820 list<string> tools_used_;
1821 QMap<QString, double> options_;
1822
1823 // ========== Private Helper Methods ==========
1824
1825
1839 Elemental_Profile* GetElementalProfile(const string& sample_name);
1840
1841public:
1842 // --- Element Role Conversion ---
1843
1862 QString Role(const element_information::role& role) const;
1863
1882 element_information::role Role(const QString& role_string) const;
1883private:
1884
1885 // --- Parameter Management ---
1886
1895 double GetParameterValue(size_t index) const;
1896
1908 bool SetParameterValue(const CVector& values);
1909
1918 CVector GetParameterValue() const;
1919
1920 // --- Contribution Initialization ---
1921
1932
1946
1947 // --- Contribution Accessors ---
1948
1960 CVector GetSourceContributions();
1961
1976 CVector GetContributionVector(bool include_all = true);
1977
1989
2001 void SetContribution(size_t source_index, double contribution_value);
2002
2014 void SetContributionSoftmax(size_t source_index, double softmax_value);
2015
2026 void SetContribution(const CVector& contributions);
2027
2038 void SetContributionSoftmax(const CVector& softmax_params);
2039
2040 // --- Distribution Parameter Accessors ---
2041
2054 Parameter* GetElementDistributionMuParameter(size_t element_index, size_t source_index);
2055
2068 Parameter* GetElementDistributionSigmaParameter(size_t element_index, size_t source_index);
2069
2077 double GetElementDistributionMuValue(size_t element_index, size_t source_index);
2078
2086 double GetElementDistributionSigmaValue(size_t element_index, size_t source_index);
2087
2088 // --- Observation Data ---
2089
2099 CVector ObservedDataforSelectedSample(const string& SelectedTargetSample = "");
2100
2112
2123
2124 // --- Prediction Methods ---
2125
2137
2148
2159
2173
2189
2190 // --- Likelihood and Prior Calculations ---
2199 double LogPriorContributions();
2200
2210
2224
2238
2239 // --- Optimization Helper Methods ---
2240
2257 CVector Gradient(const CVector& parameters, estimation_mode est_mode);
2258
2272 CVector ResidualVector();
2273
2282 CVector_arma ResidualVector_arma();
2283
2297 CMatrix_arma ResidualJacobian_arma();
2298
2309 CMatrix ResidualJacobian();
2310
2322 CMatrix ResidualJacobian_softmax();
2323
2338 CVector OneStepLevenberg_Marquardt(double lambda);
2339
2350 CVector OneStepLevenberg_Marquardt_softmax(double lambda);
2351
2357 vector<string> GetSourceOrder() const;
2358
2364 vector<string> SamplesetsOrder();
2365
2371 vector<string> ConstituentOrder();
2372
2378 vector<string> ElementOrder();
2379
2385 vector<string> IsotopeOrder();
2386
2392 vector<string> SizeOMOrder();
2393
2394 // --- Statistical Methods ---
2395
2405 int TotalNumberofSourceSamples() const;
2406
2421 double GrandMean(const string& element, bool use_log);
2422
2433
2434 // --- Box-Cox Transformation ---
2435
2456
2457 // --- Bootstrap Helpers ---
2458
2471 SourceSinkData RandomlyEliminateSourceSamples(const double& percentage);
2472
2483 vector<string> AllSourceSampleNames() const;
2484
2497 vector<string> RandomlypickSamples(const double& percentage) const;
2498
2510 SourceSinkData ReplaceSourceAsTarget(const string& source_sample_name) const;
2511
2512 // --- DFA Helper Methods ---
2513
2528
2542
2557 CMatrix TotalScatterMatrix();
2558
2575 double WilksLambda();
2576
2590 double DFA_P_Value();
2591
2601
2611 CMBVectorSet DFA_Projected(const string& source1, const string& source2);
2612
2625 CMBVectorSet DFA_Projected(const string& source1, SourceSinkData* original);
2626
2639
2652 CMBVector DFA_weight_vector(const string& source1, const string& source2);
2653
2666 CMBVector DFATransformed(const CMBVector& eigenvector, const string& source_group);
2667
2679 Elemental_Profile_Set TheRest(const string& excluded_source);
2680
2681 // --- Mean Calculation ---
2682
2694 CMBVector MeanElementalContent(const string& group_name);
2695
2710
2711
2712};
2713
2714#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
Abstract sink for progress information produced by a running analysis.
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.
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.
CMBMatrix MCMC_Batch(map< string, string > arguments, CMCMC< SourceSinkData > *mcmc, ProgressReporter *progress_window, const string &working_folder, vector< string > *failed_writes=nullptr)
Performs batch MCMC analysis on all target samples.
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_
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.
ProgressReporter * rtw_
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.
Results MCMC(const string &target_sample, map< string, string > arguments, CMCMC< SourceSinkData > *mcmc, ProgressReporter *progress_window, const string &working_folder)
Performs Markov Chain Monte Carlo analysis for Bayesian source apportionment.
ResultItem GetCalculatedElementMeans()
Computes estimated mean concentrations for all source elements.
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.
void SetProgressReporter(ProgressReporter *_rtw)
Sets the progress window for displaying optimization progress.
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