32 static const std::set<string> fingerprinting_commands = {
33 "Levenberg-Marquardt",
"Levenberg-Marquardt-Batch",
34 "GA",
"GA (fixed elemental contribution)",
"GA (disregarding targets)",
35 "CMB Bayesian",
"CMB Bayesian-Batch",
"Test CMB Bayesian",
36 "Error_Analysis",
"Source_Verify"};
37 if (fingerprinting_commands.count(command) > 0)
40 if (!problems.empty())
43 for (
const string& problem : problems)
44 message += problem +
"\n";
45 message +=
"\nInclude the base element in the analysis (Settings > Constituent Properties), "
46 "or exclude the isotope.";
47 host->ShowWarning(message);
52#ifdef SEDSAT3_ENABLE_GA
55 return ExecuteGA(arguments);
57 if (command ==
"GA (fixed elemental contribution)")
59 return ExecuteGA_FixedProfile(arguments);
61 if (command ==
"GA (disregarding targets)")
63 return ExecuteGA_NoTargets(arguments);
66 if (command.rfind(
"GA", 0) == 0)
68 host->ShowWarning(
"The genetic algorithm is not included in this build of SedSAT3. "
69 "Use Levenberg-Marquardt, or build with ENABLE_GA (CMake) or CONFIG+=ga (qmake).");
73 if (command ==
"Levenberg-Marquardt")
77 if (command ==
"Levenberg-Marquardt-Batch")
81 if (command ==
"OM-Size Correct")
89 if (command ==
"CovMat")
93 if (command ==
"CorMat")
102 if (command ==
"DFAOnevsRest")
106 if (command ==
"DFAM")
110 if (command ==
"SDFA")
115 if (command ==
"SDFAM")
120 if (command ==
"SDFAOnevsRest")
129 if (command ==
"KS-individual")
133 if (command ==
"CMB Bayesian")
137 if (command ==
"CMB Bayesian-Batch")
141 if (command ==
"Test CMB Bayesian")
151 if (command ==
"Bracketing Analysis")
155 if (command ==
"Bracketing Analysis Batch")
159 if (command ==
"BoxCox")
164 if (command ==
"Outlier")
169 if (command ==
"EDP")
174 if (command ==
"EDPM")
178 if (command ==
"ANOVA")
183 if (command ==
"Error_Analysis")
188 if (command ==
"Source_Verify")
193 if (command ==
"AutoSelect")
207 if (NegativeCheckResults.size()>0)
212 vector<string> imported_results;
213 if (_data !=
Data() &&
Data() !=
nullptr)
217 for (
unsigned int i=0; i<NegativeCheckResults.size(); i++)
219 message += QString::fromStdString(NegativeCheckResults[i]);
220 if (_data !=
Data() &&
221 std::find(imported_results.begin(), imported_results.end(), NegativeCheckResults[i]) == imported_results.end())
222 message +=
" (after the organic matter and size correction; the imported values are positive)";
225 host->ShowWarning(message.toStdString());
235 for (map<
string,vector<string>>::iterator it = negative_elements.begin(); it!=negative_elements.end(); it++)
237 if (it->second.size()>0)
238 { message +=
"For target sample '" + QString::fromStdString(it->first) +
":\n";
239 for (
unsigned int i=0; i<it->second.size(); i++)
241 message += QString::fromStdString(
"\t" + it->second[i]) +
"\n";
248 {
host->ShowWarning(message.toStdString());
257 if (offenders.empty())
261 "The fit returned a negative contribution, which is not a physically "
262 "possible result - a source cannot supply a negative share of the "
263 "target sample:\n\n";
267 const unsigned int most_to_list = 20;
268 for (
unsigned int i = 0; i < offenders.size() && i < most_to_list; i++)
269 message +=
"\t" + offenders[i] +
"\n";
271 if (offenders.size() > most_to_list)
273 message +=
"\t... and " +
274 aquiutils::numbertostring(
static_cast<unsigned int>(offenders.size() - most_to_list)) +
279 "\nWithout the softmax transformation the contributions are only "
280 "constrained to sum to one, so the optimization is free to drive one "
281 "below zero to fit the remaining sources more closely. Re-run with "
282 "'Softmax transformation' enabled, which makes a negative contribution "
283 "impossible; a source that is not present then comes out at or near "
285 "Expect the reported error to be slightly larger with the softmax "
286 "transformation. That is the cost of a solution that stays physically "
289 host->ShowWarning(message);
295 for (
auto& [group_name, profile_set] : dataset)
297 if (!group.empty() && group_name != group)
299 for (
const std::string& element : profile_set.ElementsNotBoxCoxTransformable())
300 message +=
"\t" + element +
" in group '" + group_name +
"'\n";
302 if (!message.empty())
303 host->ShowWarning(
"The Box-Cox transformation needs positive values, so these constituents "
304 "with zero or negative values were not transformed; " + consequence +
":\n" + message);
309 const std::string text = arguments.count(
"Random seed") ? arguments.at(
"Random seed") :
"";
312 host->ShowWarning(
"The random seed '" + text +
"' is not a whole number between 0 and "
313 "18446744073709551615. Leave it blank to have one chosen.");
316 arguments[
"Random seed"] = std::to_string(seed);
326#ifdef SEDSAT3_ENABLE_GA
327bool Conductor::ExecuteGA(
const std::map<std::string, std::string>& arguments)
331 bool organic_size_correction =
false;
332 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
334 organic_size_correction =
true;
335 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
337 host->
ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
343 organic_size_correction =
false;
347 arguments.at(
"Sample"),
348 organic_size_correction,
349 Data()->GetElementInformation()
358 GA = std::make_unique<CGA<SourceSinkData>>(&corrected_data);
360 GA->SetRunTimeWindow(rtw);
361 GA->SetProperties(arguments);
362 GA->InitiatePopulation();
365 results.SetName(
"GA " + arguments.at(
"Sample"));
367 ResultItem result_contribution = GA->Model_out.GetContribution();
371 results.Append(result_contribution);
373 ResultItem result_modeled_vs_measured = GA->Model_out.GetObservedvsModeledElementalProfile();
376 results.Append(result_modeled_vs_measured);
378 ResultItem result_modeled_vs_measured_isotope = GA->Model_out.GetObservedvsModeledElementalProfile_Isotope();
381 results.Append(result_modeled_vs_measured_isotope);
383 ResultItem result_calculated_means = GA->Model_out.GetCalculatedElementMeans();
386 results.Append(result_calculated_means);
388 ResultItem result_estimated_means = GA->Model_out.GetEstimatedElementMean();
391 results.Append(result_estimated_means);
393 ResultItem result_calculated_mu = GA->Model_out.GetCalculatedElementMu();
396 results.Append(result_calculated_mu);
398 ResultItem result_estimated_mu = GA->Model_out.GetEstimatedElementMu();
401 results.Append(result_estimated_mu);
403 ResultItem result_calculated_sigma = GA->Model_out.GetCalculatedElementSigma();
406 results.Append(result_calculated_sigma);
408 ResultItem result_estimated_sigma = GA->Model_out.GetEstimatedElementSigma();
411 results.Append(result_estimated_sigma);
417bool Conductor::ExecuteGA_FixedProfile(
const std::map<std::string, std::string>& arguments)
419 ScopedProgressReporter rtw(
host);
420 rtw->SetTitle(
"Fitness", 0);
421 rtw->SetYAxisTitle(
"Fitness", 0);
423 bool organic_size_correction =
false;
424 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
426 organic_size_correction =
true;
427 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
429 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
435 organic_size_correction =
false;
439 arguments.at(
"Sample"),
440 organic_size_correction,
441 Data()->GetElementInformation()
449 arguments.at(
"Sample"),
454 GA = std::make_unique<CGA<SourceSinkData>>(&corrected_data);
456 GA->SetRunTimeWindow(rtw);
457 GA->SetProperties(arguments);
458 GA->InitiatePopulation();
461 results.SetName(
"GA (fixed profile) " + arguments.at(
"Sample"));
463 ResultItem result_contribution = GA->Model_out.GetContribution();
464 results.Append(result_contribution);
466 ResultItem result_modeled_vs_measured = GA->Model_out.GetObservedvsModeledElementalProfile(
parameter_mode::direct);
467 results.Append(result_modeled_vs_measured);
469 ResultItem result_modeled_vs_measured_isotope = GA->Model_out.GetObservedvsModeledElementalProfile_Isotope(
parameter_mode::direct);
470 results.Append(result_modeled_vs_measured_isotope);
475bool Conductor::ExecuteGA_NoTargets(
const std::map<std::string, std::string>& arguments)
477 ScopedProgressReporter rtw(
host);
481 arguments.at(
"Sample"),
486 GA = std::make_unique<CGA<SourceSinkData>>(
Data());
488 GA->SetRunTimeWindow(rtw);
489 GA->SetProperties(arguments);
490 GA->InitiatePopulation();
493 results.SetName(
"GA (no targets) " + arguments.at(
"Sample"));
495 ResultItem result_calculated_means = GA->Model_out.GetCalculatedElementMeans();
496 results.Append(result_calculated_means);
498 ResultItem result_estimated_means = GA->Model_out.GetEstimatedElementMean();
499 results.Append(result_estimated_means);
501 ResultItem result_calculated_stds = GA->Model_out.GetCalculatedElementSigma();
502 results.Append(result_calculated_stds);
504 ResultItem result_estimated_stds = GA->Model_out.GetEstimatedElementSigma();
505 results.Append(result_estimated_stds);
516 bool organic_size_correction =
false;
517 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
519 organic_size_correction =
true;
520 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
522 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
528 organic_size_correction =
false;
534 arguments.at(
"Sample"),
535 organic_size_correction,
536 Data()->GetElementInformation()
545 if (arguments.at(
"Softmax transformation") ==
"true")
559 results.SetName(
"LM " + arguments.at(
"Sample"));
563 results.Append(result_contribution);
567 results.Append(result_modeled);
571 results.Append(result_modeled_vs_measured);
575 results.Append(result_modeled_vs_measured_isotope);
584 bool organic_size_correction =
false;
585 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
587 organic_size_correction =
true;
588 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
590 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
596 organic_size_correction =
false;
604 std::map<std::string, std::vector<std::string>> negative_elements;
606 if (arguments.at(
"Softmax transformation") ==
"true")
610 organic_size_correction,
618 organic_size_correction,
623 if (negative_elements.size() > 0)
632 const double round_off = -1e-9;
633 vector<string> negative_contributions;
635 for (
unsigned int source = 0; source < contributions->size(); source++)
637 for (
unsigned int sample = 0; sample < contributions->at(source).size(); sample++)
639 const double contribution = contributions->at(source).getValue(sample);
642 negative_contributions.push_back(
643 contributions->
Label(sample, source) +
" / " +
644 contributions->getSeriesName(source) +
": " +
660 contributions_result_item.
SetName(
"Levenberg-Marquardt-Batch");
661 contributions_result_item.
SetResult(contributions);
672 results.Append(contributions_result_item);
679 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
680 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
688 arguments.at(
"Sample")
693 results.SetName(
"Corrected Elemental Profiles for Target" + arguments.at(
"Sample"));
695 for (
size_t i = 0; i < result_items.size(); i++)
697 results.Append(result_items[i]);
705 if (arguments.at(
"Organic Matter constituent") ==
"" &&
706 arguments.at(
"Particle Size constituent") ==
"")
708 host->ShowWarning(
"At least one of Organic Matter constituent and "
709 "Particle Size constituent must be selected");
713 results.SetName(
"MLR_vs_OM&Size ");
715 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
723 double p_value_threshold = QString::fromStdString(arguments.at(
"P-value threshold")).toDouble();
725 if (arguments.at(
"Equation") ==
"Linear")
728 arguments.at(
"Organic Matter constituent"),
729 arguments.at(
"Particle Size constituent"),
737 arguments.at(
"Organic Matter constituent"),
738 arguments.at(
"Particle Size constituent"),
745 arguments.at(
"Organic Matter constituent"),
746 arguments.at(
"Particle Size constituent")
749 for (std::map<std::string, Elemental_Profile_Set>::iterator it =
Data()->begin();
753 if (it->first !=
Data()->GetTargetGroup())
755 it->second.SetRegressionModels(transformed_data[it->first].GetRegressionModels());
759 std::vector<ResultItem> regression_results = transformed_data.
GetMLRResults();
761 for (
size_t i = 0; i < regression_results.size(); i++)
763 results.Append(regression_results[i]);
771 results.SetName(
"Covariance Matrix for " + arguments.at(
"Source/Target group"));
774 covariance_matrix_item.
SetName(
"Covariance Matrix for " + arguments.at(
"Source/Target group"));
780 Data()->at(arguments.at(
"Source/Target group")).CalculateCovarianceMatrix()
783 covariance_matrix_item.
SetResult(covariance_matrix);
784 results.Append(covariance_matrix_item);
792 results.SetName(
"Correlation Matrix for " + arguments.at(
"Source/Target group"));
795 correlation_matrix_item.
SetName(
"Correlation Matrix");
797 correlation_matrix_item.
setTableTitle(
"Correlation Matrix for source group '" +
798 arguments.at(
"Source/Target group") +
"'");
803 double threshold = QString::fromStdString(arguments.at(
"Threshold")).toDouble();
804 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
805 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
811 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
813 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
815 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
819 arguments.at(
"OM and Size Correct based on target sample"),
821 Data()->GetElementInformation()
834 transformed_data.at(arguments.at(
"Source/Target group")).CalculateCorrelationMatrix()
840 correlation_matrix_item.
SetResult(correlation_matrix);
841 results.Append(correlation_matrix_item);
848 if (arguments.at(
"Source/Target group I") == arguments.at(
"Source/Target group II"))
850 host->ShowWarning(
"The selected sources must be different");
857 results.SetName(
"DFA between " + arguments.at(
"Source/Target group I") +
858 "&" + arguments.at(
"Source/Target group II"));
860 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
861 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
865 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
867 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
869 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
873 arguments.at(
"OM and Size Correct based on target sample"),
875 Data()->GetElementInformation()
887 if (arguments.at(
"Box-cox transformation") ==
"true")
893 arguments.at(
"Source/Target group I"),
894 arguments.at(
"Source/Target group II")
899 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
906 dfa_p_value.
SetName(
"Chi-squared P-Value");
916 dfa_f_test_p_value.
SetName(
"F-test P-Value");
920 dfa_f_test_p_value.
SetResult(f_test_p_value);
921 results.Append(dfa_f_test_p_value);
925 dfa_projected.
SetName(
"Projected Elemental Profiles");
936 dfa_eigen_vector.
SetName(
"Eigen vector");
942 dfa_eigen_vector.
SetResult(eigen_vector);
943 results.Append(dfa_eigen_vector);
955 results.SetName(
"DFA between " + arguments.at(
"Source group") +
"& the rest");
957 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
958 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
962 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
964 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
966 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
970 arguments.at(
"OM and Size Correct based on target sample"),
972 Data()->GetElementInformation()
984 if (arguments.at(
"Box-cox transformation") ==
"true")
990 arguments.at(
"Source group")
995 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
1002 dfa_p_value.
SetName(
"Chi-squared P-Value");
1012 dfa_f_test_p_value.
SetName(
"F-test P-Value");
1016 dfa_f_test_p_value.
SetResult(f_test_p_value);
1017 results.Append(dfa_f_test_p_value);
1021 dfa_projected.
SetName(
"Projected Elemental Profiles");
1028 results.Append(dfa_projected);
1032 dfa_eigen_vector.
SetName(
"Eigen vector");
1038 dfa_eigen_vector.
SetResult(eigen_vector);
1039 results.Append(dfa_eigen_vector);
1051 results.SetName(
"Multi-way DFA analysis");
1053 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1054 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1058 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
1060 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1062 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1066 arguments.at(
"OM and Size Correct based on target sample"),
1068 Data()->GetElementInformation()
1083 if (arguments.at(
"Box-cox transformation") ==
"true")
1092 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
1099 dfa_p_value.
SetName(
"Chi-squared P-Value");
1109 dfa_f_test_p_value.
SetName(
"F-test P-Value");
1113 dfa_f_test_p_value.
SetResult(f_test_p_value);
1114 results.Append(dfa_f_test_p_value);
1118 dfa_projected.
SetName(
"Multiway Projected Elemental Profiles");
1125 results.Append(dfa_projected);
1129 dfa_eigen_vectors.
SetName(
"Eigen vectors");
1135 dfa_eigen_vectors.
SetResult(eigen_vectors);
1136 results.Append(dfa_eigen_vectors);
1145 if (arguments.at(
"Source/Target group I") == arguments.at(
"Source/Target group II"))
1147 host->ShowWarning(
"The selected sources must be different");
1154 results.SetName(
"Stepwise DFA between " + arguments.at(
"Source/Target group I") +
1155 "&" + arguments.at(
"Source/Target group II"));
1157 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1158 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1162 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
1164 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1166 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1170 arguments.at(
"OM and Size Correct based on target sample"),
1172 Data()->GetElementInformation()
1187 if (arguments.at(
"Box-cox transformation") ==
"true")
1195 arguments.at(
"Source/Target group I"),
1196 arguments.at(
"Source/Target group II")
1199 if (sdfa_results[0].size() == 0)
1201 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
1208 sdfa_p_values.
SetName(
"Chi-squared P-Values");
1210 sdfa_p_values.
setXAxisTitle(
"Constituents, in the order added");
1216 results.Append(sdfa_p_values);
1221 sdfa_wilks_lambda.
SetName(
"Wilks' Lambda");
1223 sdfa_wilks_lambda.
setXAxisTitle(
"Constituents, in the order added");
1228 sdfa_wilks_lambda.
SetResult(wilks_lambda_vector);
1229 results.Append(sdfa_wilks_lambda);
1234 sdfa_f_test_p_value.
SetName(
"F-test P-Value");
1236 sdfa_f_test_p_value.
setXAxisTitle(
"Constituents, in the order added");
1241 sdfa_f_test_p_value.
SetResult(f_test_p_value);
1242 results.Append(sdfa_f_test_p_value);
1252 results.SetName(
"Multiway Stepwise DFA");
1254 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1255 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1259 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
1261 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1263 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1267 arguments.at(
"OM and Size Correct based on target sample"),
1269 Data()->GetElementInformation()
1284 if (arguments.at(
"Box-cox transformation") ==
"true")
1293 if (sdfa_results[0].size() == 0)
1295 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
1302 sdfa_p_values.
SetName(
"Chi-squared P-Values");
1304 sdfa_p_values.
setXAxisTitle(
"Constituents, in the order added");
1310 results.Append(sdfa_p_values);
1314 sdfa_selected.
SetName(
"Elements to be Selected");
1316 sdfa_selected.
setXAxisTitle(
"Constituents, in the order added");
1325 if (arguments.at(
"Modify the included elements based on the results") ==
"true")
1330 for (
size_t i = 0; i < selected.size(); i++)
1332 p_vector_selected->
append(selected[i], p_vector->
valueAt(i));
1335 sdfa_selected.
SetResult(p_vector_selected);
1336 results.Append(sdfa_selected);
1341 sdfa_wilks_lambda.
SetName(
"Wilks' Lambda");
1343 sdfa_wilks_lambda.
setXAxisTitle(
"Constituents, in the order added");
1348 sdfa_wilks_lambda.
SetResult(wilks_lambda_vector);
1349 results.Append(sdfa_wilks_lambda);
1354 sdfa_f_test_p_value.
SetName(
"F-test P-Value");
1356 sdfa_f_test_p_value.
setXAxisTitle(
"Constituents, in the order added");
1361 sdfa_f_test_p_value.
SetResult(f_test_p_value);
1362 results.Append(sdfa_f_test_p_value);
1366 if (selected.size() >= 2)
1375 dfa_projected.
SetName(
"Multiway Projected Elemental Profiles (selected constituents)");
1381 results.Append(dfa_projected);
1384 dfa_eigen_vectors.
SetName(
"Eigen vectors (selected constituents)");
1391 results.Append(dfa_eigen_vectors);
1397 confusion.
SetName(
"Confusion matrix (selected constituents, leave-one-out)");
1402 confusion.
setTableTitle(
"Confusion matrix: rows are the true source groups, columns the groups assigned");
1415 results.SetName(
"Stepwise DFA between " + arguments.at(
"Source group") +
"& the rest");
1417 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1418 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1422 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
1424 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1426 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1430 arguments.at(
"OM and Size Correct based on target sample"),
1432 Data()->GetElementInformation()
1447 if (arguments.at(
"Box-cox transformation") ==
"true")
1455 arguments.at(
"Source group")
1458 if (sdfa_results[0].size() == 0)
1460 host->ShowWarning(
"Singular matrix in within group scatter matrix!\n");
1467 sdfa_p_values.
SetName(
"Chi-squared P-Values");
1469 sdfa_p_values.
setXAxisTitle(
"Constituents, in the order added");
1475 results.Append(sdfa_p_values);
1480 sdfa_wilks_lambda.
SetName(
"Wilks' Lambda");
1482 sdfa_wilks_lambda.
setXAxisTitle(
"Constituents, in the order added");
1487 sdfa_wilks_lambda.
SetResult(wilks_lambda_vector);
1488 results.Append(sdfa_wilks_lambda);
1493 sdfa_f_test_p_value.
SetName(
"F-test P-Value");
1495 sdfa_f_test_p_value.
setXAxisTitle(
"Constituents, in the order added");
1500 sdfa_f_test_p_value.
SetResult(f_test_p_value);
1501 results.Append(sdfa_f_test_p_value);
1508 results.SetName(
"Kolmogorov–Smirnov statististics for " + arguments.at(
"Source/Target group"));
1511 ks_item.
SetName(
"Kolmogorov–Smirnov statististics for " + arguments.at(
"Source/Target group"));
1516 if (arguments.at(
"Distribution") ==
"Normal")
1520 else if (arguments.at(
"Distribution") ==
"Lognormal")
1526 Data()->at(arguments.at(
"Source/Target group")).CalculateKolmogorovSmirnovStatistics(dist)
1538 results.SetName(
"Kolmogorov–Smirnov statististics for constituent " +
1539 arguments.at(
"Constituent") +
" in group " +
1540 arguments.at(
"Source/Target group"));
1543 ks_item.
SetName(
"Kolmogorov–Smirnov statististics for constituent " +
1544 arguments.at(
"Constituent") +
" in group " +
1545 arguments.at(
"Source/Target group"));
1549 if (arguments.at(
"Distribution") ==
"Normal")
1553 else if (arguments.at(
"Distribution") ==
"Lognormal")
1564 host->ShowWarning(
"'" + arguments.at(
"Constituent") +
"' was not found in group '" +
1565 arguments.at(
"Source/Target group") +
"'.");
1570 host->ShowWarning(
"'" + arguments.at(
"Constituent") +
"' in group '" + arguments.at(
"Source/Target group") +
1571 "' has zero or negative values, so it cannot be compared with a log-normal distribution.");
1587 std::map<std::string, std::string> arguments = given_arguments;
1588 std::uint64_t seed = 0;
1592 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
1594 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1596 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1602 MCMC = std::make_unique<CMCMC<SourceSinkData>>();
1606 rtw->SetTitle(
"Acceptance Rate", 0);
1607 rtw->SetTitle(
"Perturbation Factor", 1);
1608 rtw->SetTitle(
"Log posterior value", 2);
1609 rtw->SetYAxisTitle(
"Acceptance Rate", 0);
1610 rtw->SetYAxisTitle(
"Perturbation Factor", 1);
1611 rtw->SetYAxisTitle(
"Log posterior value", 2);
1615 std::vector<std::string> failed_writes;
1626 if (!failed_writes.empty())
1628 std::string message =
"Some per-sample result files could not be written:\n";
1629 for (
const std::string& failure : failed_writes)
1630 message += failure +
"\n";
1631 host->ShowWarning(message);
1634 results.SetName(
"CMB Bayesian-Batch (random seed " + std::to_string(seed) +
")");
1638 contribution_matrix_item.
SetName(
"Contribution Range Matrix");
1641 contribution_matrix_item.
SetResult(contributions);
1643 results.Append(contribution_matrix_item);
1645 rtw->SetProgress(1);
1652 std::map<std::string, std::string> arguments = given_arguments;
1653 std::uint64_t seed = 0;
1657 results.SetName(
"MCMC results for testing MCMC (random seed " + std::to_string(seed) +
")");
1663 mcmc_samples.SetName(
"MCMC samples for testing MCMC'");
1670 mcmc_for_testing->
Model = &testing_model;
1674 rtw->
SetTitle(
"Acceptance Rate", 0);
1675 rtw->
SetTitle(
"Perturbation Factor", 1);
1676 rtw->
SetTitle(
"Log posterior value", 2);
1683 std::vector<double> mins;
1684 std::vector<double> maxs;
1685 mins.push_back(0.1);
1687 maxs.push_back(1.0);
1693 mcmc_for_testing->
SetProperty(
"number_of_samples", arguments.at(
"Number of samples"));
1694 mcmc_for_testing->
SetProperty(
"number_of_chains", arguments.at(
"Number of chains"));
1695 mcmc_for_testing->
SetProperty(
"number_of_burnout_samples", arguments.at(
"Samples to be discarded (burnout)"));
1696 if (arguments.count(
"Correlated proposal") > 0)
1697 mcmc_for_testing->
SetProperty(
"covariance_proposal", arguments.at(
"Correlated proposal"));
1703 std::string folder_path;
1704 if (!QString::fromStdString(arguments.at(
"samples_file_name")).contains(
"/"))
1710 mcmc_for_testing->
step(
1711 QString::fromStdString(arguments.at(
"Number of chains")).toInt(),
1712 QString::fromStdString(arguments.at(
"Number of samples")).toInt(),
1713 folder_path + arguments.at(
"samples_file_name"),
1724 *dists =
samples->distribution(
1726 QString::fromStdString(arguments.at(
"Samples to be discarded (burnout)")).toInt()
1729 distribution_result_item.
SetName(
"Posterior Distributions");
1732 distribution_result_item.
SetResult(dists);
1733 results.Append(distribution_result_item);
1736 delete mcmc_for_testing;
1743 results.SetName(
"Distribution fitting results for '" + arguments.at(
"Constituent") +
1744 "' in '" + arguments.at(
"Source/Target group"));
1748 distribution_item.
SetName(
"Fitted PDF for '" + arguments.at(
"Constituent") +
1749 "' in '" + arguments.at(
"Source/Target group"));
1757 cumulative_distribution_item.
SetName(
"Fitted CDF for '" + arguments.at(
"Constituent") +
1758 "' in '" + arguments.at(
"Source/Target group"));
1765 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1769 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
1771 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1773 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1777 arguments.at(
"OM and Size Correct based on target sample"),
1779 Data()->GetElementInformation()
1790 if (arguments.at(
"Box-cox transformation") ==
"true")
1795 const std::string& group = arguments.at(
"Source/Target group");
1796 const std::string& constituent = arguments.at(
"Constituent");
1797 const bool box_cox = (arguments.at(
"Box-cox transformation") ==
"true");
1799 if (transformed_data.count(group) == 0)
1801 host->ShowWarning(
"Group '" + group +
"' was not found in the data.");
1807 host->ShowWarning(
"Constituent '" + constituent +
"' was not found in group '" + group +
"'.");
1812 host->ShowWarning(
"Distribution fitting needs at least two samples of '" + constituent +
1813 "' in group '" + group +
"'; there are " + std::to_string(
distribution->size()) +
".");
1818 host->ShowWarning(
"All values of '" + constituent +
"' in group '" + group +
1819 "' are equal, so no distribution can be fitted.");
1824 host->ShowWarning(
"'" + constituent +
"' in group '" + group +
1825 "' has zero or negative values, so a log-normal distribution cannot be fitted.");
1850 bool complete = fitted_normal.Contains(
"Observed") && fitted_normal.Contains(
"Fitted") &&
1851 observed_fitted_normal_cdf.Contains(
"Observed") && observed_fitted_normal_cdf.Contains(
"Fitted");
1853 complete =
complete && fitted_lognormal.Contains(
"Fitted") && observed_fitted_lognormal_cdf.Contains(
"Fitted");
1856 host->ShowWarning(
"The distributions of '" + constituent +
"' in group '" + group +
"' could not be fitted.");
1864 pdf->append(fitted_normal[
"Observed"],
"Samples");
1865 pdf->append(fitted_normal[
"Fitted"],
"Normal");
1868 pdf->append(fitted_lognormal[
"Fitted"],
"Log-normal");
1873 cdf->append(observed_fitted_normal_cdf[
"Observed"],
"Observed");
1874 cdf->append(observed_fitted_normal_cdf[
"Fitted"],
"Normal");
1877 cdf->append(observed_fitted_lognormal_cdf[
"Fitted"],
"Log-normal");
1881 cumulative_distribution_item.
SetResult(cdf);
1883 results.Append(distribution_item);
1884 results.Append(cumulative_distribution_item);
1894 auto it = arguments.find(
"Tolerance (%)");
1895 if (it == arguments.end() || QString::fromStdString(it->second).trimmed().isEmpty())
1899 if (!
parseNumericValue(QString::fromStdString(it->second), percent, reason) || percent < 0)
1901 host->
ShowWarning(
"The tolerance must be a number of percent, 0 or more.\n");
1904 tolerance = percent / 100.0;
1910 results.SetName(
"Bracketing analysis for sample '" + arguments.at(
"Sample") +
"'");
1913 bracketing_result_item.
SetName(
"Bracketing results");
1918 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1919 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1920 bool correct_based_on_size_and_organic_matter = (arguments.at(
"Correct based on size and organic matter") ==
"true");
1921 double tolerance = 0;
1928 correct_based_on_size_and_organic_matter,
1929 arguments.at(
"Sample")
1936 transformed_data.
BracketTest(arguments.at(
"Sample"),
false, tolerance)
1940 bracketing_result_item.
SetResult(bracketing_result);
1941 results.Append(bracketing_result_item);
1948 results.SetName(
"Bracketing analysis");
1951 bracketing_result_item.
SetName(
"Bracketing results");
1957 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
1958 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
1959 bool correct_based_on_size_and_organic_matter = (arguments.at(
"Correct based on size and organic matter") ==
"true");
1960 double tolerance = 0;
1967 if (correct_based_on_size_and_organic_matter)
1969 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
1971 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
1977 Data()->BracketTest(
1978 correct_based_on_size_and_organic_matter,
1986 bracketing_result_item.
SetResult(bracketing_result);
1987 results.Append(bracketing_result_item);
1994 results.SetName(
"Box-Cox parameter for '" + arguments.at(
"Source/Target group") +
"'");
1997 boxcox_result_item.
SetName(
"Box-Cox parameters");
2006 Data()->at(arguments.at(
"Source/Target group")).CalculateBoxCoxParameters()
2009 boxcox_result_item.
SetResult(boxcox_params);
2010 results.Append(boxcox_result_item);
2017 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
2018 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
2029 results.SetName(
"Outlier analysis for '" + arguments.at(
"Source/Target group") +
"'");
2032 outlier_result_item.
SetName(
"Outlier Analysis");
2038 double threshold = QString::fromStdString(arguments.at(
"Threshold")).toDouble();
2041 "their scores are computed from the untransformed values");
2044 transformed_data.at(arguments.at(
"Source/Target group")).DetectOutliers(-threshold, threshold)
2050 outlier_result_item.
SetResult(outlier_matrix);
2051 results.Append(outlier_result_item);
2058 results.SetName(
"Two-way element discriminant power between '" +
2059 arguments.at(
"Source/Target group I") +
"' and '" +
2060 arguments.at(
"Source/Target group II") +
"'");
2062 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
2066 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
2068 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2070 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2074 arguments.at(
"OM and Size Correct based on target sample"),
2076 Data()->GetElementInformation()
2087 if (arguments.at(
"Box-cox transformation") ==
"true")
2094 edp_result_std.
SetName(
"Discreminant difference to standard deviation ratio");
2102 arguments.at(
"Source/Target group I"),
2103 arguments.at(
"Source/Target group II"),
2110 edp_result_std.
SetResult(edp_profile_set);
2112 edp_result_std.
setYAxisTitle(
"Standard deviation to mean ratio");
2113 results.Append(edp_result_std);
2117 edp_result_percent.
SetName(
"Discriminat fraction");
2120 edp_result_percent.
setYAxisTitle(
"Percentage discriminated");
2126 arguments.at(
"Source/Target group I"),
2127 arguments.at(
"Source/Target group II")
2133 edp_result_percent.
SetResult(edp_profile_set_percent);
2136 results.Append(edp_result_percent);
2140 edp_result_p_value.
SetName(
"Discriminat p-value");
2149 arguments.at(
"Source/Target group I"),
2150 arguments.at(
"Source/Target group II"),
2157 edp_result_p_value.
SetResult(edp_profile_set_p_value);
2158 edp_profile_set_p_value->
SetLimit(
_range::high, aquiutils::atof(arguments.at(
"P-value threshold")));
2162 results.Append(edp_result_p_value);
2169 bool include_target = (arguments.at(
"Include target samples") ==
"true");
2170 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
2174 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
2176 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2178 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2182 arguments.at(
"OM and Size Correct based on target sample"),
2184 Data()->GetElementInformation()
2195 if (arguments.at(
"Box-cox transformation") ==
"true")
2202 results.SetName(
"Multi-way element discriminant power");
2206 edp_result_std.
SetName(
"Multi-way discreminant difference to standard deviation ratio");
2218 edp_result_std.
SetResult(edp_profile_set);
2219 results.Append(edp_result_std);
2223 edp_result_percent.
SetName(
"Multi-way discriminat fraction");
2226 edp_result_percent.
setYAxisTitle(
"Percentage discriminated");
2236 edp_result_percent.
SetResult(edp_profile_set_percent);
2237 results.Append(edp_result_percent);
2241 edp_p_value.
SetName(
"Multi-way discriminat p-value");
2254 edp_p_value.
SetResult(edp_profile_set_p_value);
2255 edp_profile_set_p_value->
SetLimit(
_range::high, aquiutils::atof(arguments.at(
"P-value threshold")));
2264 bool log_transformation = (arguments.at(
"Log Transformation") ==
"true");
2265 bool exclude_samples = (arguments.at(
"Use only selected samples") ==
"true");
2266 bool exclude_elements = (arguments.at(
"Use only selected elements") ==
"true");
2272 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
2274 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2276 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2280 arguments.at(
"OM and Size Correct based on target sample"),
2282 Data()->GetElementInformation()
2293 if (arguments.at(
"Box-cox transformation") ==
"true")
2296 log_transformation =
false;
2299 results.SetName(
"ANOVA analysis");
2302 anova_results.
SetName(
"ANOVA");
2318 if (arguments.at(
"Modify the included elements based on the results") ==
"true")
2322 aquiutils::atof(arguments.at(
"P-value threshold"))
2327 results.Append(anova_results);
2336 std::map<std::string, std::string> arguments = given_arguments;
2337 std::uint64_t seed = 0;
2340 results.SetName(
"Error Analysis (random seed " + std::to_string(seed) +
")");
2344 bool organic_size_correction =
false;
2345 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
2347 organic_size_correction =
true;
2348 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2350 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2356 organic_size_correction =
false;
2362 arguments.at(
"Sample"),
2363 organic_size_correction,
2364 Data()->GetElementInformation()
2372 bool softmax = (arguments.at(
"Softmax transformation") ==
"true");
2378 const std::string percentage_key =
2379 (arguments.count(
"Percentage eliminated") == 0 && arguments.count(
"Pecentage eliminated") != 0)
2380 ?
"Pecentage eliminated" :
"Percentage eliminated";
2382 bool outcome = corrected_data.
BootStrap(
2384 aquiutils::atof(arguments.at(percentage_key)),
2385 aquiutils::atoi(arguments.at(
"Number of realizations")),
2386 arguments.at(
"Sample"),
2396 results.SetName(
"Source Verification");
2400 bool organic_size_correction =
false;
2401 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
2403 organic_size_correction =
true;
2404 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2406 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2412 organic_size_correction =
false;
2417 int included_samples = 0;
2418 for (
const auto& [sample_name, profile] : *
Data()->GetSampleSet(arguments.at(
"Source Group")))
2419 if (!sample_name.empty() && profile.IsIncludedInAnalysis())
2421 if (included_samples < 3)
2423 host->ShowWarning(
"Source verification needs at least 3 included samples in '" + arguments.at(
"Source Group") +
"'.\n");
2435 bool softmax = (arguments.at(
"Softmax transformation") ==
"true");
2439 arguments.at(
"Source Group"),
2441 organic_size_correction
2446 results.SetName(
"Source verification for source'" + arguments.at(
"Source Group") +
"'");
2452 contributions_result_item.
SetName(
"Source Verification");
2453 contributions_result_item.
SetResult(contributions);
2464 results.Append(contributions_result_item);
2473 results.SetName(
"Auto-select elements");
2477 if (arguments.at(
"OM and Size Correct based on target sample") !=
"")
2479 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2481 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2485 arguments.at(
"OM and Size Correct based on target sample"),
2487 Data()->GetElementInformation()
2498 bool isotopes = (arguments.at(
"Include Isotopes") ==
"true");
2504 edp_p_value.
SetName(
"Multi-way discriminat p-value");
2517 edp_p_value.
SetResult(edp_profile_set_p_value);
2523 aquiutils::atoi(arguments.at(
"Number of elements from each pair"))
2529 selected_elements.
SetName(
"Selected Elements");
2535 results.Append(selected_elements);
2537 if (arguments.at(
"Modify the included elements based on the results") ==
"true")
2547 std::map<std::string, std::string> arguments = given_arguments;
2548 std::uint64_t seed = 0;
2552 if (arguments.at(
"Apply size and organic matter correction") ==
"true")
2554 if (
Data()->OMandSizeConstituents()[0] ==
"" &&
Data()->OMandSizeConstituents()[1] ==
"")
2556 host->ShowWarning(
"Perform Organic Matter and Size Correction first!\n");
2562 MCMC = std::make_unique<CMCMC<SourceSinkData>>();
2566 rtw->SetTitle(
"Acceptance Rate", 0);
2567 rtw->SetTitle(
"Perturbation Factor", 1);
2568 rtw->SetTitle(
"Log posterior value", 2);
2569 rtw->SetYAxisTitle(
"Acceptance Rate", 0);
2570 rtw->SetYAxisTitle(
"Perturbation Factor", 1);
2571 rtw->SetYAxisTitle(
"Log posterior value", 2);
2576 arguments.at(
"Sample"),
2590 rtw->SetProgress(1);
Abstract environment that an analysis runs inside.
virtual void ShowWarning(const std::string &message)=0
Reports a condition that prevented an analysis from running.
Matrix class with labeled rows and columns for Chemical Mass Balance analysis.
void SetBooleanValue(bool val)
Sets boolean display mode for table widget.
Collection of time series with labels and observed values.
string Label(unsigned int i) const
Gets label for time point (uses custom labels if set).
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.
CMBVector ExtractWithinRange(const double &lowval, const double &highval) const
Extracts elements with values within specified range.
void SetBooleanValue(bool val)
Sets boolean display mode for table widget.
CMBVector ExtractUpToMinimum() const
Extracts elements up to first minimum value.
void append(const string &label, const double &val)
Appends a labeled element to the vector.
double valueAt(int i) const
Gets value at specified index.
vector< string > Labels() const
Gets all element labels.
Markov Chain Monte Carlo sampler for Bayesian parameter estimation.
bool SetProperty(const string &varname, const string &value)
Set MCMC properties from string key-value pairs.
bool step(int k, int chain_counter)
Perform single MCMC step for one chain.
T * Model
Pointer to the model object being calibrated.
void initialize(CMBTimeSeriesSet *results, bool random=false)
Initialize MCMC chains with starting parameter values.
void SetRandomSeed(std::uint64_t seed)
Sets the master seed for the chains' random streams.
Manages a collection of concentration measurements with statistical analysis.
bool ExecuteOutlierAnalysis(const std::map< std::string, std::string > &arguments)
Executes outlier detection analysis for a source/target group.
bool ExecuteTestCMBBayesian(const std::map< std::string, std::string > &arguments)
Executes MCMC test with a simple analytical model.
bool ExecuteCMBBayesian(const std::map< std::string, std::string > &arguments)
Executes Bayesian Chemical Mass Balance using MCMC sampling.
bool ExecuteDFAM(const std::map< std::string, std::string > &arguments)
Executes multi-way Discriminant Function Analysis across all groups.
bool ExecuteDFA(const std::map< std::string, std::string > &arguments)
Executes Discriminant Function Analysis between two groups.
bool ExecuteSDFAM(const std::map< std::string, std::string > &arguments)
Executes multi-way Stepwise Discriminant Function Analysis across all groups.
bool ExecuteBoxCox(const std::map< std::string, std::string > &arguments)
Calculates optimal Box-Cox transformation parameters.
bool ExecuteKolmogorovSmirnovIndividual(const std::map< std::string, std::string > &arguments)
Executes Kolmogorov-Smirnov test for a single constituent in a group.
void ReportBoxCoxSkips(SourceSinkData &dataset, const std::string &group, const std::string &consequence)
Warns about constituents the Box-Cox transformation leaves untransformed.
bool CheckNegativeElements(SourceSinkData *data=nullptr)
Validates that all element concentrations are non-negative.
bool ExecuteCMBBayesianBatch(const std::map< std::string, std::string > &arguments)
Executes Bayesian Chemical Mass Balance across all target samples.
bool ResolveRandomSeed(std::map< std::string, std::string > &arguments, std::uint64_t &seed)
Resolves the "Random seed" argument of an MCMC analysis.
bool ExecuteAutoSelect(const std::map< std::string, std::string > &arguments)
Executes automatic element selection based on discriminant power.
bool ExecuteSDFA(const std::map< std::string, std::string > &arguments)
Executes Stepwise Discriminant Function Analysis between two groups.
bool Execute(const std::string &command, const std::map< std::string, std::string > &arguments)
Executes a specified analysis command with given parameters.
bool ExecuteBracketingAnalysisBatch(const std::map< std::string, std::string > &arguments)
Executes bracketing analysis across all target samples.
bool ExecuteANOVA(const std::map< std::string, std::string > &arguments)
Executes Analysis of Variance (ANOVA) for element discrimination.
bool ExecuteErrorAnalysis(const std::map< std::string, std::string > &given_arguments)
Executes bootstrap error analysis for uncertainty quantification.
AnalysisHost * host
Non-owning pointer to the running environment.
QString workingfolder
Output directory path.
bool ExecuteSourceVerify(const std::map< std::string, std::string > &arguments)
Executes source verification analysis.
bool ExecuteMLR(const std::map< std::string, std::string > &arguments)
Executes multiple linear regression versus organic matter and particle size.
Conductor(AnalysisHost *host)
Constructs a Conductor that reports through host.
bool ExecuteDistributionFitting(const std::map< std::string, std::string > &arguments)
Executes distribution fitting analysis for a constituent.
bool ExecuteLevenbergMarquardtBatch(const std::map< std::string, std::string > &arguments)
Executes Levenberg-Marquardt optimization across all target samples.
bool ExecuteKolmogorovSmirnov(const std::map< std::string, std::string > &arguments)
Executes Kolmogorov-Smirnov goodness-of-fit test for a source/target group.
SourceSinkData * Data()
Returns pointer to the current SourceSinkData.
SourceSinkData * data
Non-owning pointer to analysis data.
bool ExecuteSDFAOnevsRest(const std::map< std::string, std::string > &arguments)
Executes Stepwise Discriminant Function Analysis for one group versus all others.
bool ExecuteBracketingAnalysis(const std::map< std::string, std::string > &arguments)
Executes bracketing analysis for a single target sample.
bool ExecuteDFAOnevsRest(const std::map< std::string, std::string > &arguments)
Executes Discriminant Function Analysis for one group versus all others.
SourceSinkData BoxCoxTransformedWithReport(SourceSinkData &dataset)
Box-Cox transforms data with optimal lambdas, reporting skipped constituents.
bool ExecuteCovarianceMatrix(const std::map< std::string, std::string > &arguments)
Calculates covariance matrix for a source or target group.
Results results
Current analysis results (cleared each Execute).
void ReportNegativeContributions(const std::vector< std::string > &offenders)
Reports negative source contributions through the AnalysisHost.
bool ExecuteOMSizeCorrect(const std::map< std::string, std::string > &arguments)
Executes organic matter and particle size correction.
bool ExecuteLevenbergMarquardt(const std::map< std::string, std::string > &arguments)
Executes Levenberg-Marquardt nonlinear optimization.
bool ExecuteEDP(const std::map< std::string, std::string > &arguments)
Calculates two-way element discriminant power between two groups.
bool ExecuteEDPM(const std::map< std::string, std::string > &arguments)
Calculates multi-way element discriminant power across all groups.
bool ExecuteCorrelationMatrix(const std::map< std::string, std::string > &arguments)
Calculates correlation matrix for a source or target group.
std::unique_ptr< CMCMC< SourceSinkData > > MCMC
MCMC sampler (owned).
Manages a collection of elemental profiles (samples) for source fingerprinting analysis.
Elemental_Profile SelectTopElementsAggregate(int n) const
Select top N elements across all samples (aggregate minimum).
Container for elemental concentration data of a single sediment sample.
vector< string > GetElementNames() const
Get list of all element names.
options & GetOptions()
Get reference to the options structure.
void SetOption(options_key opt, bool val)
Set a configuration option.
void SetLimit(_range lowhigh, const double &value)
Set upper or lower limit for value highlighting.
virtual void Start()
Makes the reporter visible or otherwise begins reporting.
virtual void SetYAxisTitle(const QString &title, int chart=0)=0
Sets the vertical axis title of a chart.
virtual void SetProgress(const double &prog)=0
Sets the primary progress fraction.
virtual void SetTitle(const QString &title, int chart=0)=0
Sets the title of a chart.
void SetAbsoluteValue(bool val)
void SetShowGraph(bool state)
void setYAxisTitle(const string &title)
void SetXAxisMode(xaxis_mode mode)
void SetYLimit(_range highlow, const double &value)
void setTableTitle(const string &Title)
void SetName(const string &_name)
void SetResult(Interface *_result)
void SetShowTable(bool state)
void setXAxisTitle(const string &title)
void SetYAxisMode(yaxis_mode mode)
void SetShowAsString(bool value)
void SetType(const result_type &_type)
Holds a progress reporter for the duration of one analysis.
bool InitializeParametersAndObservations(const string &targetsamplename, estimation_mode est_mode=estimation_mode::elemental_profile_and_contribution)
Initialize parameters and observations for MCMC optimization.
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 > NegativeContributionCheck()
Checks the solved source contributions for negative values.
vector< string > IsotopesWithUnusableBaseElement() const
Lists the isotopes included in the analysis whose base element cannot be used.
Elemental_Profile_Set DifferentiationPower_Percentage(bool include_target)
Computes rank-based differentiation percentage for all source pairs.
SourceSinkData ExtractChemicalElements(bool isotopes) const
Extract only chemical elements (and optionally isotopes).
CMBVector ANOVA(bool use_log)
Performs one-way ANOVA for all elements across source groups.
bool SolveLevenberg_Marquardt(transformation trans=transformation::linear)
Solves for optimal source contributions using the Levenberg-Marquardt algorithm.
CMBMatrix DFAConfusionMatrix()
Leave-one-out confusion matrix of the source samples.
vector< CMBVector > StepwiseDiscriminantFunctionAnalysis(const string &source1, const string &source2)
Performs stepwise discriminant analysis between two specific sources.
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.
void SetParameterEstimationMode(estimation_mode est_mode)
Sets the estimation mode for parameter optimization.
CMBVector BracketTest(const string &target_sample, bool correct_based_on_om_n_size, double tolerance=0)
Performs bracket test to check if target concentrations fall within source ranges.
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< ResultItem > GetMLRResults()
Retrieves multiple linear regression results for all sample groups.
void SetOMandSizeConstituents(const string &_omconstituent, const string &_sizeconstituent)
Sets the names of OM and particle size constituents.
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.
SourceSinkData CreateCorrectedAndFilteredDataset(bool exclude_samples, bool exclude_elements, bool omnsizecorrect, const string &target="") const
Create a corrected and filtered copy of the dataset.
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.
void AddtoToolsUsed(const string &tool)
Adds a tool name to the list of tools used in analysis.
DFA_result DiscriminantFunctionAnalysis()
Performs discriminant function analysis for all source groups.
vector< ResultItem > GetSourceProfiles()
Retrieves elemental profiles for all source groups.
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.
CMBTimeSeriesSet BootStrap(const double &percentage, unsigned int num_iterations, const string &target_sample, bool use_softmax, std::uint64_t seed=DefaultRandomSeed)
Performs bootstrap uncertainty analysis on source contributions.
Elemental_Profile_Set DifferentiationPower(bool use_log, bool include_target)
Computes differentiation power for all source pairs.
SourceSinkData CreateTracerDataset(bool exclude_samples, bool exclude_elements, bool omnsizecorrect, const string &target="") const
As CreateCorrectedAndFilteredDataset, keeping only the tracers.
SourceSinkData CreateCorrectedDataset(const string &target, bool omnsizecorrect, map< string, element_information > *elementinfo)
Create a corrected copy of the dataset for a specific target sample.
ResultItem GetObservedvsModeledElementalProfile(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Creates a comparison of observed vs modeled elemental profiles.
Elemental_Profile_Set DifferentiationPower_P_value(bool include_target)
Computes t-test p-values for all source pairs.
ResultItem GetContribution()
Packages source contributions into a ResultItem for output.
ResultItem GetObservedvsModeledElementalProfile_Isotope(parameter_mode param_mode=parameter_mode::based_on_fitted_distribution)
Creates a comparison of observed vs modeled isotope delta values.
void SetProgressReporter(ProgressReporter *_rtw)
Sets the progress window for displaying optimization progress.
void InitializeParametersObservations(const vector< double > &mins, const vector< double > &maxs)
@ direct
Use empirical statistics from data.
distribution_type
Enumeration of probability distribution types supported in SedSat3.
@ lognormal
Lognormal distribution: ln(x) ~ N(μ, σ²), for strictly positive variables.
@ normal
Normal (Gaussian) distribution: p(x) = N(μ, σ²).
static bool ReadBracketTolerance(const std::map< std::string, std::string > &arguments, AnalysisHost *host, double &tolerance)
@ single_column_x
Enable single-column mode for X-axis data representation.
bool parseNumericValue(const QVariant &value, double &out, QString &error)
Parses a spreadsheet cell value as a finite number.
The one place where data values entering SedSAT3 are checked.
@ low
Lower bound of the parameter range.
@ high
Upper bound of the parameter range.
bool ParseRandomSeed(const std::string &text, std::uint64_t &seed)
Parses a user-entered seed.
@ predicted_concentration
@ timeseries_set_first_symbol
@ source_elemental_profiles_based_on_source_data
CMBVectorSet eigen_vectors
CMBVectorSetSet multi_projected
QString X_suffix
Suffix appended to X-axis field names in serialization.
QString Y_suffix
Suffix appended to Y-axis field names in serialization.