Java PrintWriter Write saveChiPhiTableCsv(PrintWriter wr, double[][] coefficients, String[] labelNames)

Here you can find the source of saveChiPhiTableCsv(PrintWriter wr, double[][] coefficients, String[] labelNames)

Description

Save Chi and Phi coefficients as .csv file.

License

Open Source License

Parameter

Parameter Description
wr PrintWriter
coefficients Coefficients
labelNames Label names

Declaration

public static void saveChiPhiTableCsv(PrintWriter wr, double[][] coefficients, String[] labelNames) 

Method Source Code


//package com.java2s;
/*/*  ww  w. j a  va 2 s .  c  o m*/
 * This file is part of the MLDA.
 *
 * (c)  Jose Maria Moyano Murillo
 *      Eva Lucrecia Gibaja Galindo
 *      Sebastian Ventura Soto <sventura@uco.es>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import java.io.PrintWriter;

public class Main {
    /**
     * Save Chi and Phi coefficients as .csv file. They are stored in two different tables instead only one
     * 
     * @param wr PrintWriter
     * @param coefficients Coefficients
     * @param labelNames Label names
     */
    public static void saveChiPhiTableCsv(PrintWriter wr, double[][] coefficients, String[] labelNames) {
        //Save label names row
        String line;

        //Save Chi table
        line = "Chi;";

        for (String labelName : labelNames) {
            line += labelName + ";";
        }

        wr.write(line);
        wr.write(System.getProperty("line.separator"));

        for (int i = 0; i < labelNames.length; i++) {
            line = "";
            line += labelNames[i] + ";";

            for (int j = 0; j < coefficients[i].length; j++) {

                if (i >= j) {
                    if (coefficients[j][i] == 0.0) {
                        line += "" + ";";
                    } else {
                        line += coefficients[j][i] + ";";
                    }
                } else {
                    if (coefficients[i][j] == 0.0) {
                        line += "" + ";";
                    } else {
                        line += coefficients[i][j] + ";";
                    }
                }
            }
            wr.write(line);
            wr.write(System.getProperty("line.separator"));
        }

        //Save Phi table
        wr.write(System.getProperty("line.separator"));
        wr.write(System.getProperty("line.separator"));
        line = "Phi;";

        for (String labelName : labelNames) {
            line += labelName + ";";
        }

        wr.write(line);
        wr.write(System.getProperty("line.separator"));

        for (int i = 0; i < labelNames.length; i++) {
            line = "";
            line += labelNames[i] + ";";

            for (int j = 0; j < coefficients[i].length; j++) {
                if (j >= i) {
                    if (coefficients[j][i] == 0.0) {
                        line += "" + ";";
                    } else {
                        line += coefficients[j][i] + ";";
                    }
                } else {
                    if (coefficients[i][j] == 0.0) {
                        line += "" + ";";
                    } else {
                        line += coefficients[i][j] + ";";
                    }
                }
            }
            wr.write(line);
            wr.write(System.getProperty("line.separator"));
        }
    }
}

Related

  1. save(final Multimap map, final Writer target, final String sep)
  2. save(Map map, String fileName)
  3. save(String fileName, List list)
  4. save(String s, File file)
  5. saveConvert(final String text, final int escapeMode, final PrintWriter writer)
  6. saveFile(File f, String text)
  7. saveFile(String fileName, String data)
  8. saveFile(String path, String text)