List of usage examples for org.apache.commons.math.distribution DistributionFactory newInstance
public static DistributionFactory newInstance()
DistributionFactory
From source file:de.tud.kom.p2psim.impl.util.stats.ConfidenceInterval.java
/** * Returns the delta between the mean and the lower(x1)/upper(x2) bound as * positive number. That is, the probabilistic bounds of x1 and x2 are given * by x1 <= mean <= x2 <=> mean-delta <= mean <= mean + delta * //www . j ava 2 s . c om * @param sdev * the given standard deviation * @param n * the given sample size * @param alpha * the given significance level * @return the upper/lower bound as positiv number */ public static double getDeltaBound(double sdev, int n, double alpha) { TDistribution tDist = DistributionFactory.newInstance().createTDistribution(n - 1); double errorConfCoeff = 1d - (alpha / 2); double delta; try { double t = Math.abs(tDist.inverseCumulativeProbability(errorConfCoeff)); delta = t * sdev / Math.sqrt(n); } catch (MathException e) { throw new IllegalStateException(e); } return delta; }
From source file:clus.statistic.RegressionStatBase.java
/** * Computes a 2-sample t statistic, without the hypothesis of equal sub-population variances, * and returns the p-value of a t test.//from w ww .ja v a 2 s .c o m * t = (m1 - m2) / sqrt(var1/n1 + var2/n2); * @param att attribute index * @return t p-value * @throws MathException */ public double getTTestPValue(int att, ClusStatManager stat_manager) throws MathException { double global_mean = ((CombStat) stat_manager.getTrainSetStat()).m_RegStat.getMean(att); double global_var = ((CombStat) stat_manager.getTrainSetStat()).m_RegStat.getVariance(att); double global_n = ((CombStat) stat_manager.getTrainSetStat()).getTotalWeight(); double local_mean = getMean(att); double local_var = getVariance(att); double local_n = getTotalWeight(); double t = Math.abs(local_mean - global_mean) / Math.sqrt(local_var / local_n + global_var / global_n); double degreesOfFreedom = 0; degreesOfFreedom = df(local_var, global_var, local_n, global_n); DistributionFactory distributionFactory = DistributionFactory.newInstance(); TDistribution tDistribution = distributionFactory.createTDistribution(degreesOfFreedom); return 1.0 - tDistribution.cumulativeProbability(-t, t); }
From source file:clus.pruning.C45Pruner.java
public double computeZScore() throws ClusException { try {/* www .jav a 2s.c o m*/ DistributionFactory distributionFactory = DistributionFactory.newInstance(); return distributionFactory.createNormalDistribution() .inverseCumulativeProbability(1 - m_ConfidenceFactor); } catch (MathException e) { throw new ClusException(e.getMessage()); } }
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))//from w w w . ja v a 2 s. c om * @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.//from w w w . j a va2s.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; }