mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-11-04 08:04:32 +00:00 
			
		
		
		
	correlation matrix plot utility can (optionally) save matrices
This commit is contained in:
		@@ -17,6 +17,7 @@
 | 
			
		||||
 * 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>
 | 
			
		||||
@@ -27,16 +28,37 @@ using namespace Math;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
    }
 | 
			
		||||
    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;
 | 
			
		||||
    DMat       var;
 | 
			
		||||
    DMat       var, corr;
 | 
			
		||||
    Plot       p;
 | 
			
		||||
    
 | 
			
		||||
    cout << "-- computing variance matrix from '" << fileName << "'..." << endl;
 | 
			
		||||
@@ -44,8 +66,17 @@ int main(int argc, char *argv[])
 | 
			
		||||
    sample = Io::load<DMatSample>(fileName);
 | 
			
		||||
    sample = sample.block(0, 0, sample[central].rows(), 1);
 | 
			
		||||
    var    = sample.varianceMatrix();
 | 
			
		||||
    p << PlotMatrix(varToCorr(var));
 | 
			
		||||
    corr   = sample.correlationMatrix();
 | 
			
		||||
    p << PlotMatrix(corr);
 | 
			
		||||
    p.display();
 | 
			
		||||
    if (!outVarName.empty())
 | 
			
		||||
    {
 | 
			
		||||
        Io::save(var, outVarName);
 | 
			
		||||
    }
 | 
			
		||||
    if (!outCorrName.empty())
 | 
			
		||||
    {
 | 
			
		||||
        Io::save(corr, outCorrName);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user