Package gem

Source Code of gem.OverallDistrChecker

package gem;

import gem.util.ArrayUtils;
import gem.util.FileUtil;
import gem.util.Histogram;

import java.io.BufferedReader;
import java.io.IOException;

/**
* @author Ozgun Babur
*/
public class OverallDistrChecker
{

  public static void main(String[] args) throws IOException
  {
    String dir = "resource/expdata/Ling/";
    boolean[][] pos = StageAnalyzer.getPos(dir);
    printChangeHisto(dir + "data.txt", pos[1], pos[5]);
  }
 
  public static void printChangeHisto(String datafile, boolean[] pos1, boolean[] pos2) throws IOException
  {
    Histogram h = new Histogram(0.01);
    int cnt1 = ArrayUtils.countTrue(pos1);
    int cnt2 = ArrayUtils.countTrue(pos2);

    assert pos1.length == pos2.length;
    BufferedReader reader = FileUtil.getReader(datafile);

    reader.readLine();
    for (String line = reader.readLine(); line != null; line = reader.readLine())
    {
      line = line.substring(line.indexOf("\t") + 1);
      String[] token = line.split("\t");
      assert token.length == pos1.length;

      double[] val = new double[token.length];
      for (int i = 0; i < val.length; i++)
      {
        val[i] = Double.parseDouble(token[i]);
      }

      double mean1 = 0;
      double mean2 = 0;
      for (int i = 0; i < val.length; i++)
      {
        if (pos1[i]) mean1 += val[i];
        if (pos2[i]) mean2 += val[i];
      }

      mean1 /= cnt1;
      mean2 /= cnt2;

      double rat = mean2 / mean1;
      double lograt = Math.log(rat);
      h.count(lograt);
    }

    reader.close();
    h.printDensity();
  }
}
TOP

Related Classes of gem.OverallDistrChecker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.