30 bool MultiAnalyzer::CheckMergability(
const QStringList dataset_keys)
32 for (
auto key: dataset_keys)
33 if (
workspace_->GetDataset(key)->spectra_ptr()->n_rows
34 !=
workspace_->GetDataset(dataset_keys.first())->spectra_ptr()->n_rows)
39 bool MultiAnalyzer::ConcatenateSpectra(QStringList dataset_keys)
41 if (!CheckMergability(dataset_keys))
return false;
44 start_indices_.set_size(datasets_.size());
45 end_indices_.set_size(datasets_.size());
46 data_ = datasets_[0]->spectra_ref();
48 start_indices_(0) = 0;
49 end_indices_(0) = datasets_[0]->spectra_ref().n_cols - 1;
51 for (uword i = 1; i < start_indices_.n_rows; ++ i){
52 start_indices_(i) =
data_.n_cols;
53 data_ = join_horiz(
data_, datasets_[i]->spectra_ref());
54 end_indices_(i) =
data_.n_cols - 1;
66 for (uword i = 0; i < start_indices_.n_rows; ++i){
67 mat spectra =
data_.cols(start_indices_(i), end_indices_(i));
68 vec
abscissa = datasets_[i]->abscissa();
69 vec x = datasets_[i]->x();
70 vec y = datasets_[i]->y();
71 datasets_[i]->SetData(spectra, abscissa, x, y);
80 vec SVD_vec({double(rank)});
82 QSharedPointer<AnalysisResults> results(
new AnalysisResults(
"QUIC-SVD",
"QUIC-SVD"));
83 results->AddMatrix(
"Left Singualr Vectors", U);
84 results->AddMatrix(
"Right Singualr Vectors", V);
85 results->AddMatrix(
"Singualr Values", s);
86 results->AddMatrix(
"Rank", SVD_vec);
88 for (uword i = 0; i < start_indices_.n_rows; ++i){
89 mat spectra =
data_.cols(start_indices_(i), end_indices_(i));
90 vec
abscissa = datasets_[i]->abscissa();
91 vec x = datasets_[i]->x();
92 vec y = datasets_[i]->y();
93 datasets_[i]->SetData(spectra, abscissa, x, y);
95 AddAnalysisResults(results, QStringList());
102 vec SVD_vec({double(k)});
103 QSharedPointer<AnalysisResults> results(
new AnalysisResults(
"QUIC-SVD",
"QUIC-SVD"));
104 results->AddMatrix(
"Left Singualr Vectors", U);
105 results->AddMatrix(
"Right Singualr Vectors", V);
106 results->AddMatrix(
"Singualr Values", s);
107 results->AddMatrix(
"Rank", SVD_vec);
108 for (uword i = 0; i < start_indices_.n_rows; ++i){
109 mat spectra =
data_.cols(start_indices_(i), end_indices_(i));
110 vec
abscissa = datasets_[i]->abscissa();
111 vec x = datasets_[i]->x();
112 vec y = datasets_[i]->y();
113 datasets_[i]->SetData(spectra, abscissa, x, y);
116 AddAnalysisResults(results, QStringList());
126 void MultiAnalyzer::GetDatasets(QStringList keys)
128 for (
auto key: keys){
129 if (
workspace_->dataset_names().contains(key)){
130 datasets_.append(
workspace_->GetDataset(key));
138 void MultiAnalyzer::GetData()
140 GetDatasets(dataset_keys_);
141 bool ok = ConcatenateSpectra(dataset_keys_);
142 if (!ok)
throw runtime_error(
"Could not concatenate datasets");
145 void MultiAnalyzer::AddAnalysisResults(QSharedPointer<AnalysisResults> results, QStringList matrices)
147 for (uword i = 0; i < uword(datasets_.size()); ++i){
148 datasets_[i]->AddAnalysisResult(results, start_indices_(i), end_indices_(i));
149 if (!matrices.isEmpty())
150 datasets_[i]->AddAnalysisResult(results->Subset(matrices, start_indices_(i), end_indices_(i)));
154 QString MultiAnalyzer::FindUniqueName(QString name)
156 QString new_name = name;
157 QStringList results_names;
158 for (
auto dataset: datasets_){
159 results_names = results_names + dataset->AnalysisResultsKeys();
162 QString basename = name;
163 while (results_names.contains(new_name)){
164 new_name = basename +
" (" + QString::number(i++) +
")";
void QUIC_SVD(double epsilon)
VESPUCCI_EXPORT arma::mat SNVNorm(const arma::mat &X, const double offset, bool center)
Vespucci::Math::Normalization::SNVNorm.
VESPUCCI_EXPORT arma::mat QUICSVDDenoise(const arma::mat &X, double epsilon, arma::mat &U, arma::vec &s, arma::mat &V, arma::uword &rank)
VESPUCCI_EXPORT arma::mat SVDDenoise(const arma::mat &X, arma::uword k, arma::mat &U, arma::vec &s, arma::mat &V)
MultiAnalyzer(QSharedPointer< VespucciWorkspace > workspace, QStringList dataset_keys)
The AnalysisResults class A container for a mat object that allows a mat to be copied to a heap-alloc...
void SNVNormalize(double offset)