1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 01:45:35 +00:00
LatAnalyze/utils/sample-plot-corr.cpp

85 lines
2.7 KiB
C++
Raw Normal View History

/*
* sample_plot_corr.cpp, part of LatAnalyze 3
*
2020-01-13 09:57:06 +00:00
* Copyright (C) 2013 - 2020 Antonin Portelli
*
* 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/>.
*/
#include <LatAnalyze/Core/OptParser.hpp>
#include <LatAnalyze/Io/Io.hpp>
#include <LatAnalyze/Core/Math.hpp>
#include <LatAnalyze/Core/Plot.hpp>
using namespace std;
using namespace Latan;
using namespace Math;
int main(int argc, char *argv[])
{
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"))
{
cerr << "usage: " << argv[0];
cerr << "<options> <sample file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
if (opt.gotOption("saveCorr"))
{
outCorrName = opt.optionValue("saveCorr");
}
if (opt.gotOption("saveVar"))
{
outVarName = opt.optionValue("saveVar");
}
string fileName = opt.getArgs()[0], name;
DMatSample sample;
DMat var, corr;
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);
var = sample.varianceMatrix();
corr = sample.correlationMatrix();
2022-02-16 18:55:24 +00:00
2024-01-12 13:21:39 +00:00
cout << "dynamic range " << Math::cdr(corr) << " dB" << endl;
2022-02-16 18:55:24 +00:00
p << PlotCorrMatrix(corr);
p.display();
if (!outVarName.empty())
{
Io::save(var, outVarName);
}
if (!outCorrName.empty())
{
Io::save(corr, outCorrName);
}
return EXIT_SUCCESS;
}