Example usage for org.apache.commons.math3.exception NotStrictlyPositiveException getMessage

List of usage examples for org.apache.commons.math3.exception NotStrictlyPositiveException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception NotStrictlyPositiveException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Usage

From source file:ubic.basecode.math.linearmodels.LeastSquaresFit.java

/**
 * ANOVA f statistics etc./* www  .j a va2s  .  c o m*/
 * 
 * @param dof         raw degrees of freedom
 * @param fStats      results will be stored here
 * @param denominator residual sums of squares / rdof
 * @param pvalues     results will be stored here
 */
private void computeStats(DoubleMatrix2D dof, DoubleMatrix2D fStats, DoubleMatrix1D denominator,
        DoubleMatrix2D pvalues) {
    pvalues.assign(Double.NaN);
    int timesWarned = 0;
    for (int i = 0; i < fStats.rows(); i++) {

        int rdof;
        if (this.residualDofs.isEmpty()) {
            rdof = residualDof;
        } else {
            rdof = this.residualDofs.get(i);
        }

        for (int j = 0; j < fStats.columns(); j++) {

            double ndof = dof.get(i, j);

            if (ndof <= 0 || rdof <= 0) {
                pvalues.set(i, j, Double.NaN);
                fStats.set(i, j, Double.NaN);
                continue;
            }

            if (j == fStats.columns() - 1) {
                // don't fill in f & p values for the residual...
                pvalues.set(i, j, Double.NaN);
                fStats.set(i, j, Double.NaN);
                continue;
            }

            /*
             * Taking ratios of two very small values is not meaningful; happens if the data are ~constant.
             */
            if (fStats.get(i, j) < Constants.SMALLISH && denominator.get(i) < Constants.SMALLISH) {
                pvalues.set(i, j, Double.NaN);
                fStats.set(i, j, Double.NaN);
                continue;
            }

            fStats.set(i, j, fStats.get(i, j) / denominator.get(i));
            try {
                FDistribution pf = new FDistribution(ndof, rdof + this.dfPrior);
                pvalues.set(i, j, 1.0 - pf.cumulativeProbability(fStats.get(i, j)));
            } catch (NotStrictlyPositiveException e) {
                if (timesWarned < 10) {
                    log.warn("Pvalue could not be computed for F=" + fStats.get(i, j) + "; denominator was="
                            + denominator.get(i) + "; Error: " + e.getMessage()
                            + " (limited warnings of this type will be given)");
                    timesWarned++;
                }
                pvalues.set(i, j, Double.NaN);
            }

        }
    }
}