Package org.apache.commons.math.distribution

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


    return Beta.qnbeta(p, shape1, shape2, ncp, lowerTail, logP);
  }

  @DataParallel @Internal
  public static double dchisq(@Recycle double x, @Recycle double df, boolean log) {
    return d(new ChiSquaredDistributionImpl(df), x, log);
  }
View Full Code Here


  @DataParallel @Internal
  public static double pchisq(@Recycle double q, @Recycle double df, boolean lowerTail, boolean logP) {
    if(df == 0) {
      return p(new ChisquareZeroDfDistribution(), q, lowerTail, logP);
    } else {
      return p(new ChiSquaredDistributionImpl(df), q, lowerTail, logP);
    }
  }
View Full Code Here

  @DataParallel @Internal
  public static double qchisq(@Recycle double p, @Recycle double df, boolean lowerTail, boolean logP) {
    if(df == 0) {
      return q(new ChisquareZeroDfDistribution(), p, lowerTail, logP);
    } else {
      return q(new ChiSquaredDistributionImpl(df), p, lowerTail, logP);
    }
  }
View Full Code Here

    /**
     * Construct a ChiSquareTestImpl
     */
    public ChiSquareTestImpl() {
        this(new ChiSquaredDistributionImpl(1.0));
    }
View Full Code Here

     * @return random value sampled from the ChiSquare(df) distribution
     * @throws MathException if an error occurs generating the random value
     * @since 2.2
     */
    public double nextChiSquare(double df) throws MathException {
        return nextInversionDeviate(new ChiSquaredDistributionImpl(df));
    }
View Full Code Here

        //  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

    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

   
    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

    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

  /**
   * @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

TOP

Related Classes of org.apache.commons.math.distribution.ChiSquaredDistributionImpl

Copyright © 2018 www.massapicom. 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.