コード例 #1
0
 /**
  * The calculation is done here. Example: From 1.96 (Z-score) to 0.975 (P-value) From -1.96
  * (Z-score) to 0.025
  *
  * @return double a p value
  */
 public static double cumulativeProbability(Distribution obj, Number n) {
   NormalDistribution dist = new NormalDistributionImpl();
   double lQuantile = 0;
   try {
     lQuantile = dist.cumulativeProbability(obj.zScore(n));
   } catch (MathException e) {
     e.printStackTrace();
   }
   return lQuantile;
 }
コード例 #2
0
  @Override
  public void executeTest() {

    int iRange1 =
        (int) (Math.pow(1, iDecimalPlaces)) * (int) (this.fMaximumValue - this.fMinimumValue) + 1;

    String sLocalOutput = null;
    if (isHadoop) {
      Job conf = null;
      try {
        conf = this.test();
      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        sLocalOutput = UtilityHadoop.getFileFromHDFS(sOutput + File.separator + sFileName, conf);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      try {
        this.testLinear();
      } catch (IOException e) {
        e.printStackTrace();
      }
      sLocalOutput = sOutput + File.separator + this.sFileName;
    }
    int numOfCombinations = UtilityMath.getCombinationAmount(iRange1, 1, true, true).intValue();
    double[] dArrExpected = new double[numOfCombinations];
    for (int i = 0; i < dArrExpected.length; i++) {
      dArrExpected[i] = 1.0;
    }
    Evaluator evaluator = null;
    if (sLocalOutput != null) {
      evaluator =
          new Evaluator(
              sEvaluation, sLocalOutput, dArrExpected, dSignificance, iRange1, iDecimalPlaces);
    }

    boolean isPass = false;
    if (evaluator != null) {
      try {
        isPass = evaluator.evaluate();
      } catch (MathException e) {
        e.printStackTrace();
      } catch (ParameterNotValidException e) {
        e.printStackTrace();
      } catch (ArrayLengthNotEqualException e) {
        e.printStackTrace();
      }
    }

    System.out.println("Passed: " + isPass);
  }
  /**
   * Generate a random value from this distribution.
   *
   * @param rng random number generator
   * @return random value from this distribution
   */
  public double generate(MersenneTwisterFast rng) {
    try {
      return gammaDist.inverseCumulativeProbability(rng.nextDouble());
    } catch (MathException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      System.exit(-1);
    }

    return -1d;
  }
コード例 #4
0
ファイル: CombStat.java プロジェクト: vrodic/Clus
 /**
  * Checks weather values of a target attribute are significantly different
  *
  * @return
  */
 public boolean targetSignDifferent() {
   boolean res = false;
   int att = -1;
   String att_name;
   String att_name2;
   ClusStatistic targetStat = m_StatManager.getStatistic(ClusAttrType.ATTR_USE_TARGET);
   if (targetStat instanceof ClassificationStat) {
     for (int i = 0; i < targetStat.getNbNominalAttributes(); i++) {
       att_name = ((ClassificationStat) targetStat).getAttribute(i).getName();
       for (int j = 0; j < m_ClassStat.getNbNominalAttributes(); j++) {
         att_name2 = m_ClassStat.getAttribute(j).getName();
         if (att_name.equals(att_name2)) {
           att = j;
           break;
         }
       }
       if (SignDifferentNom(att)) {
         res = true;
         break; // TODO: If one target att significant, the whole rule significant!?
       }
     }
     // System.out.println("Target sign. testing: " + res);
     return res;
   } else if (targetStat instanceof RegressionStat) {
     for (int i = 0; i < targetStat.getNbNumericAttributes(); i++) {
       att_name = ((RegressionStat) targetStat).getAttribute(i).getName();
       for (int j = 0; j < m_RegStat.getNbNumericAttributes(); j++) {
         att_name2 = m_RegStat.getAttribute(j).getName();
         if (att_name.equals(att_name2)) {
           att = j;
           break;
         }
       }
       try {
         if (SignDifferentNum(att)) {
           res = true;
           break; // TODO: If one target att significant, the whole rule significant!?
         }
       } catch (IllegalArgumentException e) {
         e.printStackTrace();
       } catch (MathException e) {
         e.printStackTrace();
       }
     }
     return res;
   } else {
     // TODO: Classification and regression
     return true;
   }
 }
コード例 #5
0
  private void calculateZValues(int n) {

    zValues = new double[n];
    NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1);
    double x;

    try {
      x = 1 - Math.pow(0.5, 1.0 / n);
      zValues[0] = normalDist.inverseCumulativeProbability(x);

      for (int i = 2; i < n; i++) {
        x = (i - 0.3175) / (n + 0.365);
        zValues[i - 1] = normalDist.inverseCumulativeProbability(x);
      }

      x = Math.pow(0.5, 1.0 / n);
      zValues[n - 1] = normalDist.inverseCumulativeProbability(x);

    } catch (MathException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #6
0
ファイル: CombStat.java プロジェクト: vrodic/Clus
 /** Returns a number of attributes with significantly different distributions */
 public int signDifferent() {
   int sign_diff = 0;
   // Nominal attributes
   for (int i = 0; i < m_ClassStat.getNbAttributes(); i++) {
     if (SignDifferentNom(i)) {
       sign_diff++;
     }
   }
   // Numeric attributes
   for (int i = 0; i < m_RegStat.getNbAttributes(); i++) {
     try {
       if (SignDifferentNum(i)) {
         sign_diff++;
       }
     } catch (IllegalArgumentException e) {
       e.printStackTrace();
     } catch (MathException e) {
       e.printStackTrace();
     }
   }
   System.out.println("Nb.sig.atts: " + sign_diff);
   return sign_diff;
 }