Example usage for org.apache.commons.math3.fraction Fraction percentageValue

List of usage examples for org.apache.commons.math3.fraction Fraction percentageValue

Introduction

In this page you can find the example usage for org.apache.commons.math3.fraction Fraction percentageValue.

Prototype

public double percentageValue() 

Source Link

Document

Gets the fraction percentage as a double.

Usage

From source file:bayesGame.ui.transformers.BayesNodeProbabilityToGridTransformer.java

@Override
public Icon transform(BayesNode node) {
    Fraction probability = node.getProbability();
    double cells = probability.percentageValue();

    Image grid;//from   ww  w.j a v  a 2  s.c om
    Color trueColor = BayesGame.trueColor;
    Color falseColor = BayesGame.falseColor;

    boolean hiddennode = node.hasProperty("hidden");
    boolean targetnode = node.hasProperty("target");

    if (node.hasProperty("misguessed")) {
        trueColor = Color.GRAY;
        falseColor = Color.BLACK;
    }

    // TODO: indicate target nodes somehow

    if (node.cptName == null) {
        node.cptName = "";
    }

    if (node.cptName.equals("DetIS")) {
        grid = new IsNodePainter().paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize);
    } else if (node.cptName.equals("DetNOT")) {
        grid = new NotNodePainter().paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize);
    } else if (node.cptName.equals("Prior")) {
        grid = PriorPainter.paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize);
    } else if (node.cptName.equals("DetOR")) {
        List<Object> parentTypeList = net.getParents(node.type);
        Fraction parentNode1Probability = net.getProbability(parentTypeList.get(0));
        Fraction parentNode2Probability = net.getProbability(parentTypeList.get(1));
        grid = OrNodePainter.paintPercentage(trueColor, falseColor, (int) (rows * squaresize * 3.5), squaresize,
                node, parentNode1Probability, parentNode2Probability);
    } else if (node.cptName.equals("DetAND")) {
        List<Object> parentTypeList = net.getParents(node.type);
        Fraction parentNode1Probability = net.getProbability(parentTypeList.get(0));
        Fraction parentNode2Probability = net.getProbability(parentTypeList.get(1));
        grid = AndNodePainter.paintPercentage(trueColor, falseColor, (int) (rows * squaresize * 3.5),
                squaresize, node, parentNode1Probability, parentNode2Probability);
    } else if (node.cptName.equals("DetNOTAnd")) {
        grid = DetNOTAnd.paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize, node);
    } else if (node.cptName.equals("Bayes")) {
        List<Object> parentTypeList = net.getParents(node.type);
        Fraction parentNodeProbability = net.getProbability(parentTypeList.get(0));
        grid = BayesPainter.paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize, node,
                parentNodeProbability);
    }

    else {
        grid = GridPainter.paintPercentage(cells, trueColor, falseColor, rows, columns, squaresize);
    }

    if (hiddennode) {
        grid = NodePainter.getBorders((BufferedImage) grid, Color.BLACK);
    } else if (!node.isObserved()) {
        grid = NodePainter.getBorders((BufferedImage) grid, Color.GRAY);
    }

    int x_size = grid.getHeight(null);
    double size_multiplier = 0.7;
    int new_x_size = (int) (x_size * size_multiplier);

    ImageIcon icon = new ImageIcon(grid.getScaledInstance(-1, new_x_size, Image.SCALE_SMOOTH));

    // ImageIcon icon = new ImageIcon(grid);

    return icon;
}