2016-04-06 18:39:03 +01:00
|
|
|
/*
|
|
|
|
* sample_plot_corr.cpp, part of LatAnalyze 3
|
|
|
|
*
|
2020-01-13 09:57:06 +00:00
|
|
|
* Copyright (C) 2013 - 2020 Antonin Portelli
|
2016-04-06 18:39:03 +01:00
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-04 20:05:23 +01:00
|
|
|
#include <LatAnalyze/Core/OptParser.hpp>
|
2019-02-10 00:23:36 +00:00
|
|
|
#include <LatAnalyze/Io/Io.hpp>
|
|
|
|
#include <LatAnalyze/Core/Math.hpp>
|
|
|
|
#include <LatAnalyze/Core/Plot.hpp>
|
2016-04-06 18:39:03 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
|
|
|
using namespace Math;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-04-04 20:05:23 +01:00
|
|
|
OptParser opt;
|
|
|
|
bool parsed;
|
|
|
|
string outCorrName = "", outVarName = "";
|
|
|
|
|
|
|
|
opt.addOption("", "saveCorr", OptParser::OptType::value, true,
|
|
|
|
"save correlation matrix (default: not saved)");
|
|
|
|
opt.addOption("", "saveVar", OptParser::OptType::value, true,
|
|
|
|
"save variance matrix (default: not saved)");
|
|
|
|
opt.addOption("" , "help" , OptParser::OptType::trigger, true,
|
|
|
|
"show this help message and exit");
|
|
|
|
parsed = opt.parse(argc, argv);
|
|
|
|
if (!parsed or (opt.getArgs().size() != 1) or opt.gotOption("help"))
|
2016-04-06 18:39:03 +01:00
|
|
|
{
|
2019-04-04 20:05:23 +01:00
|
|
|
cerr << "usage: " << argv[0];
|
|
|
|
cerr << "<options> <sample file>" << endl;
|
|
|
|
cerr << endl << "Possible options:" << endl << opt << endl;
|
2016-04-06 18:39:03 +01:00
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2019-04-04 20:05:23 +01:00
|
|
|
if (opt.gotOption("saveCorr"))
|
|
|
|
{
|
|
|
|
outCorrName = opt.optionValue("saveCorr");
|
|
|
|
}
|
|
|
|
if (opt.gotOption("saveVar"))
|
|
|
|
{
|
|
|
|
outVarName = opt.optionValue("saveVar");
|
|
|
|
}
|
2016-04-06 18:39:03 +01:00
|
|
|
|
2019-04-04 20:05:23 +01:00
|
|
|
string fileName = opt.getArgs()[0], name;
|
2016-04-06 18:39:03 +01:00
|
|
|
DMatSample sample;
|
2019-04-04 20:05:23 +01:00
|
|
|
DMat var, corr;
|
2016-04-06 18:39:03 +01:00
|
|
|
Plot p;
|
|
|
|
|
|
|
|
cout << "-- computing variance matrix from '" << fileName << "'..." << endl;
|
|
|
|
name = Io::getFirstName(fileName);
|
|
|
|
sample = Io::load<DMatSample>(fileName);
|
2016-06-14 12:34:46 +01:00
|
|
|
sample = sample.block(0, 0, sample[central].rows(), 1);
|
2016-04-06 18:39:03 +01:00
|
|
|
var = sample.varianceMatrix();
|
2019-04-04 20:05:23 +01:00
|
|
|
corr = sample.correlationMatrix();
|
2022-02-16 18:55:24 +00:00
|
|
|
|
2022-03-10 08:21:10 +00:00
|
|
|
cout << "dynamic range " << Math::svdDynamicRangeDb(corr) << " dB" << endl;
|
2022-02-16 18:55:24 +00:00
|
|
|
p << PlotCorrMatrix(corr);
|
2016-04-06 18:39:03 +01:00
|
|
|
p.display();
|
2019-04-04 20:05:23 +01:00
|
|
|
if (!outVarName.empty())
|
|
|
|
{
|
|
|
|
Io::save(var, outVarName);
|
|
|
|
}
|
|
|
|
if (!outCorrName.empty())
|
|
|
|
{
|
|
|
|
Io::save(corr, outCorrName);
|
|
|
|
}
|
2016-04-06 18:39:03 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|