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

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

Introduction

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

Prototype

@Override
public String getMessage() 

Source Link

Usage

From source file:edu.stanford.cfuller.imageanalysistools.filter.VariableSizeMeanFilter.java

protected boolean shouldSubDivide(OcttreeNode node, Image im, Image laplacianFiltered) {

    im.setBoxOfInterest(node.getBoxMin(), node.getBoxMax());
    laplacianFiltered.setBoxOfInterest(node.getBoxMin(), node.getBoxMax());

    double l_sum = 0;
    double sum = 0;
    double count = 0;

    for (ImageCoordinate ic : im) {
        l_sum += laplacianFiltered.getValue(ic);
        sum += im.getValue(ic);//from  www  .ja v  a 2  s  . c  om
        count++;

    }

    if (count == 1)
        return false;

    l_sum /= count;
    sum /= count;

    double l_var = 0;
    double var = 0;

    for (ImageCoordinate ic : im) {

        l_var += Math.pow(laplacianFiltered.getValue(ic) - l_sum, 2);
        var += Math.pow(im.getValue(ic) - sum, 2);

    }

    l_var /= (count - 1);
    var /= (count - 1);

    im.clearBoxOfInterest();
    laplacianFiltered.clearBoxOfInterest();

    double cutoff = 0.0001;

    double smallerVar = var < l_var ? var : l_var;
    double largerVar = var > l_var ? var : l_var;
    try {

        FDistribution f = new FDistribution(count - 1, count - 1);
        double valueAtLowerCutoff = f.inverseCumulativeProbability(cutoff);
        double valueAtUpperCutoff = f.inverseCumulativeProbability(1 - cutoff);
        boolean result = (smallerVar / largerVar > valueAtUpperCutoff
                || smallerVar / largerVar < valueAtLowerCutoff);
        return result;

    } catch (MathIllegalArgumentException e) {
        LoggingUtilities.getLogger()
                .severe("Exception while calculating variable size mean QO partition: " + e.getMessage());
        e.printStackTrace();
        return false;
    }
}