Examples of ChiSquaredDistribution

@version $Revision: 920852 $ $Date: 2010-03-09 13:53:44 +0100 (mar. 09 mars 2010) $
  • org.apache.commons.math3.distribution.ChiSquaredDistribution
    pedia.org/wiki/Chi-squared_distribution">Chi-squared distribution (Wikipedia) @see Chi-squared Distribution (MathWorld)

  • Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

            //  System.out.println(s + "\t" + t.getCount(s) + "\t" + f.getCount(s));
            //}
          }
         
          double ratio = trues.size() / (0.0 + trues.size() + falses.size());
          ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
          ChiSquareTest cst = new ChiSquareTestImpl();
         
          Bag<String> combined = new Bag<String>();
          combined.addAll(onlyTrues);
          combined.addAll(onlyFalses);
          Bag<String> tpf = new Bag<String>();
          tpf.addAll(trues);
          tpf.addAll(falses);
          tpf.discardInfrequent(5);
          //combined.discardInfrequent(8);
          Map<String,Double> mcNemarScores = new HashMap<String,Double>();
          for(String s : tpf.getList()) {
            int b = onlyTrues.getCount(s);
            int c = onlyFalses.getCount(s);
            double score = Math.pow(b-c, 2) / (b+c);
            int t = trues.getCount(s);
            int f = falses.getCount(s);
            double et = (t + f) * ratio;
            double ef = (t + f) * (1.0 - ratio);
            long [] obsArray = new long[]{t, f};
            double [] expectArray = new double[]{et, ef};
            double cs = cst.chiSquare(expectArray, obsArray);
            //score = cs;
            if(Double.isNaN(score)) score = 0.0;
            mcNemarScores.put(s, score);
          }

          int ss = mcNemarScores.size();
          int count = 0;
         
          boolean beforeCutOff = true;
          for(String s : StringTools.getSortedList(mcNemarScores)) {
            count++;
            double foo = count * 1.0 / ss;
            int b = onlyTrues.getCount(s);
            int c = onlyFalses.getCount(s);
           
            int t = trues.getCount(s);
            int f = falses.getCount(s);
            double et = (t + f) * ratio;
            double ef = (t + f) * (1.0 - ratio);
            long [] obsArray = new long[]{t, f};
            double [] expectArray = new double[]{et, ef};
            double cs = cst.chiSquare(expectArray, obsArray);
            if(beforeCutOff && ((1.0 - csd.cumulativeProbability(mcNemarScores.get(s))) / foo) > 0.05) {
              System.out.println(count - 1);
              beforeCutOff = false;
              //break;
            }
            System.out.println(s + "\t" + b + "\t" + c + "\t" + t + "\t" + f + "\t" + mcNemarScores.get(s)
                 + "\t" + (1.0 - csd.cumulativeProbability(mcNemarScores.get(s)))
                 + "\t" + ((1.0 - csd.cumulativeProbability(mcNemarScores.get(s))) / foo)
                 + "\t" + csd.cumulativeProbability(cs));
          }     
        }
      }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

        Query q;//if(true) {
        //  System.out.println(ChemNameDictSingleton.getInChIForShortestSmiles("sertraline"));
        //  return;
        //}
       
        ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
        List<Query> lq = new ArrayList<Query>();
        TextMiner tm = new TextMiner(new LuceneIndexerSearcher(false));

        System.out.println(tm.corpusBags.txtBag.totalCount());
        System.out.println(tm.corpusBags.txtBag.getCount("dextromethorphan"));
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

       
        Set<String> words = new HashSet<String>();
        words.addAll(wordsWithReact.getSet());
        words.addAll(wordsWithoutReact.getSet());
       
        ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
        ChiSquareTest cst = new ChiSquareTestImpl();
       
       
        for(String word : wordsWithReact.getList()) {
          int observed = wordsWithReact.getCount(word);
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

        Map<String,Double> excesses = new HashMap<String,Double>();
        time = System.currentTimeMillis();
        int ccount = 0;
        int hypotheses = ((toksAboveThresh-1) * (toksAboveThresh-2)) / 2;

        ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
        double upperThreshold = csd.inverseCumulativeProbability(1.0 - (fdr / hypotheses));
        double lowerThreshold = csd.inverseCumulativeProbability(1.0 - fdr);
        Map<String,String> reports = new HashMap<String,String>();
        int totalViable = 0;
        for(Long c : collocs) {
          if(c == colloc) {
            count++;
          } else {
            if(colloc != -1) {
              int [] r = decodeCollocation(colloc);
              int c1 = tCounts.getCount(r[0]);
              int c2 = tCounts.getCount(r[1]);
              //if(count > 2) {
              if(c1 > 2 && c2 > 2) {
                String s = tokenList.get(r[0]) + " " + tokenList.get(r[1]);
                //cBag.add(s, count);
                double expected = tCounts.getCount(r[0]) * tCounts.getCount(r[1]) * 1.0 / filenum;
                if(count > expected) totalViable++;

                //excesses.put(s, count - expected);
                //long [][] counts = new long[][]{{count, c1-count}, {c2-count, files.size()-c1-c2+count}};
                double cs = gTest(count, c1-count, c2-count, filenum-c1-c2+count);
                if(cs > lowerThreshold) {
                  //double cs = cst.chiSquare(counts);
                  //double p = csd.cumulativeProbability(cs);
                  //System.out.println(cs);
                  double pp;
                  if(cs > upperThreshold) {
                    pp = 0.0;
                  } else {
                    try {
                      pp = 1.0 - csd.cumulativeProbability(cs);               
                    } catch (MaxIterationsExceededException e) {
                      System.out.println(cs);
                      pp = 0.0;
                    }               
                  }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

      /**
       * @param args
       */
      public static void main(String[] args) throws Exception {
        if(false) {
          ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
          System.out.println(csd.inverseCumulativeProbability(1.0 - (0.05 / 1000000000)));
          System.out.println(csd.inverseCumulativeProbability(0.05));
          return;
        }
        if(false) {
          System.out.println(3 << 16);
          int [] r = decodeCollocation(encodeCollocation(1000, 10000));
          System.out.println(r[0] + "\t" + r[1]);
         
          ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(3);
          for(int i=0;i<50;i++) {
            double p = Math.pow(10.0, -i);
            System.out.println(p + "\t" + csd.inverseCumulativeProbability(p));
          }
         
          return;
        }
       
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

            //  System.out.println(s + "\t" + t.getCount(s) + "\t" + f.getCount(s));
            //}
          }
         
          double ratio = trues.size() / (0.0 + trues.size() + falses.size());
          ChiSquaredDistribution csd = new ChiSquaredDistributionImpl(1);
          ChiSquareTest cst = new ChiSquareTestImpl();
         
          Bag<String> combined = new Bag<String>();
          combined.addAll(onlyTrues);
          combined.addAll(onlyFalses);
          Bag<String> tpf = new Bag<String>();
          tpf.addAll(trues);
          tpf.addAll(falses);
          tpf.discardInfrequent(5);
          //combined.discardInfrequent(8);
          Map<String,Double> mcNemarScores = new HashMap<String,Double>();
          for(String s : tpf.getList()) {
            int b = onlyTrues.getCount(s);
            int c = onlyFalses.getCount(s);
            double score = Math.pow(b-c, 2) / (b+c);
            int t = trues.getCount(s);
            int f = falses.getCount(s);
            double et = (t + f) * ratio;
            double ef = (t + f) * (1.0 - ratio);
            long [] obsArray = new long[]{t, f};
            double [] expectArray = new double[]{et, ef};
            double cs = cst.chiSquare(expectArray, obsArray);
            //score = cs;
            if(Double.isNaN(score)) score = 0.0;
            mcNemarScores.put(s, score);
          }

          int ss = mcNemarScores.size();
          int count = 0;
         
          boolean beforeCutOff = true;
          for(String s : StringTools.getSortedList(mcNemarScores)) {
            count++;
            double foo = count * 1.0 / ss;
            int b = onlyTrues.getCount(s);
            int c = onlyFalses.getCount(s);
           
            int t = trues.getCount(s);
            int f = falses.getCount(s);
            double et = (t + f) * ratio;
            double ef = (t + f) * (1.0 - ratio);
            long [] obsArray = new long[]{t, f};
            double [] expectArray = new double[]{et, ef};
            double cs = cst.chiSquare(expectArray, obsArray);
            if(beforeCutOff && ((1.0 - csd.cumulativeProbability(mcNemarScores.get(s))) / foo) > 0.05) {
              System.out.println(count - 1);
              beforeCutOff = false;
              //break;
            }
            System.out.println(s + "\t" + b + "\t" + c + "\t" + t + "\t" + f + "\t" + mcNemarScores.get(s)
                 + "\t" + (1.0 - csd.cumulativeProbability(mcNemarScores.get(s)))
                 + "\t" + ((1.0 - csd.cumulativeProbability(mcNemarScores.get(s))) / foo)
                 + "\t" + csd.cumulativeProbability(cs));
          }     
        }
      }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

         * @throws IllegalArgumentException if preconditions are not met
         * @throws MathException if an error occurs computing the p-value
         */
        public double chiSquareTest(double[] expected, long[] observed)
            throws IllegalArgumentException, MathException {
            ChiSquaredDistribution chiSquaredDistribution =
                getDistributionFactory().createChiSquareDistribution(
                        (double) expected.length - 1);
            return 1 - chiSquaredDistribution.cumulativeProbability(
                    chiSquare(expected, observed));
        }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

         */
        public double chiSquareTest(long[][] counts)
        throws IllegalArgumentException, MathException {
            checkArray(counts);
            double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
            ChiSquaredDistribution chiSquaredDistribution =
                getDistributionFactory().createChiSquareDistribution(df);
            return 1 - chiSquaredDistribution.cumulativeProbability(chiSquare(counts));
        }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

         * @throws IllegalArgumentException if preconditions are not met
         * @throws MathException if an error occurs computing the p-value
         */
        public double chiSquareTest(double[] expected, long[] observed)
            throws IllegalArgumentException, MathException {
            ChiSquaredDistribution chiSquaredDistribution =
                getDistributionFactory().createChiSquareDistribution(
                        (double) expected.length - 1);
            return 1 - chiSquaredDistribution.cumulativeProbability(
                    chiSquare(expected, observed));
        }
    View Full Code Here

    Examples of org.apache.commons.math.distribution.ChiSquaredDistribution

         */
        public double chiSquareTest(long[][] counts)
        throws IllegalArgumentException, MathException {
            checkArray(counts);
            double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
            ChiSquaredDistribution chiSquaredDistribution =
                getDistributionFactory().createChiSquareDistribution(df);
            return 1 - chiSquaredDistribution.cumulativeProbability(chiSquare(counts));
        }
    View Full Code Here
    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.