Search in sources :

Example 6 with SotaTreeCell

use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.

the class SotaDrawingPane method modelChanged.

/**
 * Creates the Tree structure for the JTree and paints it.
 *
 * @param first if <code>true</code> size of JPanel will be recomputed
 */
public void modelChanged(final boolean first) {
    if (m_root != null && m_data != null) {
        // computes size for the first time the oanel is shown
        if (first) {
            // when there is only a small amount of data increase the
            // default pixel width by the magic factor.
            int factor = 1;
            if (m_data.size() <= 150) {
                factor = 2;
                if (m_data.size() <= 50) {
                    factor = 5;
                }
            }
            m_jpWidth = m_data.size() * DEF_PIXEL_WIDTH * factor;
            // resize to optimal size
            setSize(m_jpWidth, m_jpHeight);
            setPreferredSize(new Dimension(m_jpWidth, m_jpHeight));
        }
        // compute pixel width of data pixels
        if (m_data.size() == 0) {
            m_pixelWidth = 0;
        } else {
            m_pixelWidth = m_jpWidth / m_data.size();
        }
        // get all cells
        m_cells = new ArrayList<SotaTreeCell>();
        SotaManager.getCells(m_cells, m_root);
        // set default locations
        m_cellLocations = new HashMap<SotaTreeCell, SotaTreeCellLocations>();
        SotaManager.initDefaultLocations(m_cellLocations, m_root);
        // compute maxmimum tree level
        m_maxLevel = getMaxLevel(m_maxLevel, m_root);
        m_clusterLineHeight = (m_jpHeight - PIXEL_HEIGHT) / m_maxLevel;
        // store max Level in each hierarchy if data is hierarchical
        if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
            getHierarchicalMaxLevels();
        }
        // reset X coordinates and related cells
        m_nodesCoordIndex.clear();
        // copmute the coordinates for the tree nodes and cluster lines
        computeTreeNodeCoordinates();
        // and redurce them if they are.
        if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
            // if clusterlines too high
            if (m_rootLocation.getEndY() < 0) {
                int lineCount = (Math.abs(m_rootLocation.getEndY()) + m_jpHeight - PIXEL_HEIGHT) / m_clusterLineHeight;
                m_clusterLineHeight = (m_jpHeight - PIXEL_HEIGHT) / lineCount;
                // after new computation of optimal cluster line height
                // recompute the cluster line positions.
                m_nodesCoordIndex.clear();
                computeTreeNodeCoordinates();
            }
        }
        repaint();
    }
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations) Dimension(java.awt.Dimension)

Example 7 with SotaTreeCell

use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.

the class SotaPredictorCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    if (row != null) {
        DataRow filteredRow = new FilterColumnRow(row, m_includedColsIndices);
        Iterator<DataCell> it = filteredRow.iterator();
        while (it.hasNext()) {
            if (it.next().isMissing()) {
                return new DataCell[] { DataType.getMissingCell() };
            }
        }
        SotaTreeCell winner = null;
        double minDist = Double.MAX_VALUE;
        Map<String, Double> minDists = new HashMap<String, Double>();
        for (int j = 0; j < m_cells.size(); j++) {
            double dist = m_distanceManager.getDistance(filteredRow, m_cells.get(j));
            String treeCellClass = m_cells.get(j).getTreeCellClass();
            if (minDists.containsKey(treeCellClass)) {
                Double old = minDists.get(treeCellClass);
                if (old.doubleValue() > dist) {
                    minDists.put(treeCellClass, dist);
                }
            } else {
                minDists.put(treeCellClass, dist);
            }
            if (dist < minDist) {
                winner = m_cells.get(j);
                minDist = dist;
            }
        }
        String predClass = SotaTreeCell.DEFAULT_CLASS;
        if (winner != null) {
            predClass = winner.getTreeCellClass();
        }
        DataCell[] ret;
        ret = new DataCell[m_newColumns.getNumColumns()];
        if (m_appendProbs) {
            double sumDists = 0d;
            for (Double d : minDists.values()) {
                sumDists += 1d / Math.max(EPSILON, d.doubleValue());
            }
            for (int i = ret.length; i-- > 0; ) {
                ret[i] = DataType.getMissingCell();
            }
            for (Entry<String, Double> entry : minDists.entrySet()) {
                final String target = entry.getKey();
                final String colName = PredictorHelper.getInstance().probabilityColumnName(m_targetColumn.getName(), target, m_suffix);
                int colIndex = m_newColumns.findColumnIndex(colName);
                if (colIndex >= 0) {
                    ret[colIndex] = new DoubleCell(1d / Math.max(EPSILON, entry.getValue().doubleValue()) / sumDists);
                }
            }
            ret[ret.length - 1] = new StringCell(predClass);
        } else {
            ret = new DataCell[] { new StringCell(predClass) };
        }
        return ret;
    }
    return null;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) HashMap(java.util.HashMap) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) FilterColumnRow(org.knime.base.data.filter.column.FilterColumnRow)

Example 8 with SotaTreeCell

use of org.knime.base.node.mine.sota.logic.SotaTreeCell in project knime-core by knime.

the class SotaDrawingPane method getToolTipText.

/**
 * {@inheritDoc}
 */
@Override
public String getToolTipText(final MouseEvent event) {
    if (m_data != null && m_root != null) {
        DataRow row = getDataRowAtCursor(event.getX(), event.getY());
        if (row != null) {
            String text = "RowKey: " + row.getKey().getString();
            text += "\nData: ";
            for (int i = 0; i < row.getNumCells(); i++) {
                text += row.getCell(i).toString() + m_toolTipSeperator;
            }
            return text;
        } else {
            SotaTreeCell cell = getCellAtCursor(event.getX(), event.getY());
            if (cell != null) {
                String title;
                if (cell.isCell()) {
                    title = "Cell";
                } else {
                    title = "Node";
                }
                String hAddOn = "";
                if (m_isHierarchicalFuzzyData) {
                    hAddOn = "(H-Level: " + cell.getHierarchyLevel() + ") (inner H-Level: " + cell.getLevelInHierarchy() + ")";
                }
                return title + ": " + "(Level: " + cell.getLevel() + ") " + hAddOn + "\n" + "Data: " + cell.getDataAsString(2);
            }
        }
    }
    return "Press + or - to zoom in or out. [" + event.getX() + ", " + event.getY() + "]";
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) DataRow(org.knime.core.data.DataRow)

Aggregations

SotaTreeCell (org.knime.base.node.mine.sota.logic.SotaTreeCell)8 SotaTreeCellLocations (org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)4 DataRow (org.knime.core.data.DataRow)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Dimension (java.awt.Dimension)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FilterColumnRow (org.knime.base.data.filter.column.FilterColumnRow)1 DataArray (org.knime.base.node.util.DataArray)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 DataCell (org.knime.core.data.DataCell)1 DataTable (org.knime.core.data.DataTable)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 StringCell (org.knime.core.data.def.StringCell)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ModelContentRO (org.knime.core.node.ModelContentRO)1