List of usage examples for org.apache.commons.math.distribution DistributionFactory createChiSquareDistribution
public abstract ChiSquaredDistribution createChiSquareDistribution(double degreesOfFreedom);
From source file:clus.statistic.ClassificationStat.java
/** * Computes a G statistic and returns the p-value of a G test. * G = 2*SUM(obs*ln(obs/exp))//ww w .j a va 2 s.c o m * @param att attribute index * @return p-value * @throws MathException */ public double getGTestPValue(int att, ClusStatManager stat_manager) throws MathException { double global_n = ((CombStat) stat_manager.getTrainSetStat()).getTotalWeight(); double local_n = getTotalWeight(); double ratio = local_n / global_n; double global_counts[] = ((CombStat) stat_manager.getTrainSetStat()).m_ClassStat.getClassCounts(att); double local_counts[] = getClassCounts(att); double g = 0; for (int i = 0; i < global_counts.length; i++) { if ((local_counts[i] > 0) && (global_counts[i] > 0)) { g += 2 * local_counts[i] * Math.log(local_counts[i] / (global_counts[i] * ratio)); } } double degreesOfFreedom = ((double) global_counts.length) - 1; DistributionFactory distributionFactory = DistributionFactory.newInstance(); ChiSquaredDistribution chiSquaredDistribution = distributionFactory .createChiSquareDistribution(degreesOfFreedom); return 1 - chiSquaredDistribution.cumulativeProbability(g); }
From source file:clus.main.ClusStatManager.java
/** * Initializes a table with Chi Squared inverse probabilities used in * significance testing of rules./* w w w . ja v a2 s . c om*/ * * @throws MathException * */ public void initSignifcanceTestingTable() { int max_nom_val = 0; int num_nom_atts = m_Schema.getNbNominalAttrUse(ClusAttrType.ATTR_USE_ALL); for (int i = 0; i < num_nom_atts; i++) { if (m_Schema.getNominalAttrUse(ClusAttrType.ATTR_USE_ALL)[i].m_NbValues > max_nom_val) { max_nom_val = m_Schema.getNominalAttrUse(ClusAttrType.ATTR_USE_ALL)[i].m_NbValues; } } if (max_nom_val == 0) { // If no nominal attributes in data set max_nom_val = 1; } double[] table = new double[max_nom_val]; table[0] = 1.0 - getSettings().getRuleSignificanceLevel(); // Not really used except below for (int i = 1; i < table.length; i++) { DistributionFactory distributionFactory = DistributionFactory.newInstance(); ChiSquaredDistribution chiSquaredDistribution = distributionFactory.createChiSquareDistribution(i); try { table[i] = chiSquaredDistribution.inverseCumulativeProbability(table[0]); } catch (MathException e) { e.printStackTrace(); } } m_ChiSquareInvProb = table; }