mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-11 03:20:46 +01:00
correlation matrix plot utility can (optionally) save matrices
This commit is contained in:
parent
11ecea3c6d
commit
070f91a4ed
@ -17,6 +17,7 @@
|
|||||||
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LatAnalyze/Core/OptParser.hpp>
|
||||||
#include <LatAnalyze/Io/Io.hpp>
|
#include <LatAnalyze/Io/Io.hpp>
|
||||||
#include <LatAnalyze/Core/Math.hpp>
|
#include <LatAnalyze/Core/Math.hpp>
|
||||||
#include <LatAnalyze/Core/Plot.hpp>
|
#include <LatAnalyze/Core/Plot.hpp>
|
||||||
@ -27,16 +28,37 @@ using namespace Math;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
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] << " <file>" << endl;
|
cerr << "usage: " << argv[0];
|
||||||
|
cerr << "<options> <sample file>" << endl;
|
||||||
|
cerr << endl << "Possible options:" << endl << opt << endl;
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
if (opt.gotOption("saveCorr"))
|
||||||
|
{
|
||||||
|
outCorrName = opt.optionValue("saveCorr");
|
||||||
|
}
|
||||||
|
if (opt.gotOption("saveVar"))
|
||||||
|
{
|
||||||
|
outVarName = opt.optionValue("saveVar");
|
||||||
|
}
|
||||||
|
|
||||||
string fileName = argv[1], name;
|
string fileName = opt.getArgs()[0], name;
|
||||||
DMatSample sample;
|
DMatSample sample;
|
||||||
DMat var;
|
DMat var, corr;
|
||||||
Plot p;
|
Plot p;
|
||||||
|
|
||||||
cout << "-- computing variance matrix from '" << fileName << "'..." << endl;
|
cout << "-- computing variance matrix from '" << fileName << "'..." << endl;
|
||||||
@ -44,8 +66,17 @@ int main(int argc, char *argv[])
|
|||||||
sample = Io::load<DMatSample>(fileName);
|
sample = Io::load<DMatSample>(fileName);
|
||||||
sample = sample.block(0, 0, sample[central].rows(), 1);
|
sample = sample.block(0, 0, sample[central].rows(), 1);
|
||||||
var = sample.varianceMatrix();
|
var = sample.varianceMatrix();
|
||||||
p << PlotMatrix(varToCorr(var));
|
corr = sample.correlationMatrix();
|
||||||
|
p << PlotMatrix(corr);
|
||||||
p.display();
|
p.display();
|
||||||
|
if (!outVarName.empty())
|
||||||
|
{
|
||||||
|
Io::save(var, outVarName);
|
||||||
|
}
|
||||||
|
if (!outCorrName.empty())
|
||||||
|
{
|
||||||
|
Io::save(corr, outCorrName);
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user