Search in sources :

Example 41 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.

the class DataCellRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    // Have to set the alignment here, since this is the only place the col
    // index of the component is available...
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) c;
    if (dataSet.getNumColumns() > 0 && col >= getNumLeadingCols() && col < dataSet.getNumColumns() + getNumLeadingCols()) {
        int dataCol = col - getNumLeadingCols();
        Node variable = dataSet.getVariable(dataCol);
        if (variable instanceof DiscreteVariable) {
            renderer.setHorizontalAlignment(JLabel.RIGHT);
        } else {
            renderer.setHorizontalAlignment(JLabel.RIGHT);
        }
    }
    return renderer;
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 42 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.

the class SubsetDiscreteVariablesAction method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    DataModel selectedDataModel = getDataEditor().getSelectedDataModel();
    if (selectedDataModel instanceof DataSet) {
        DataSet dataSet = (DataSet) selectedDataModel;
        for (int i = dataSet.getNumColumns(); i >= 0; i--) {
            if (dataSet.getVariable(i) instanceof DiscreteVariable) {
                dataSet.removeColumn(i);
            }
        }
        DataModelList list = new DataModelList();
        list.add(dataSet);
        getDataEditor().reset(list);
        getDataEditor().selectFirstTab();
    } else {
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Requires a tabular data set.");
    }
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) DataSet(edu.cmu.tetrad.data.DataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) DataModel(edu.cmu.tetrad.data.DataModel)

Example 43 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.

the class TabularDataTable method swapDiscreteColumnForContinuous.

private Node swapDiscreteColumnForContinuous(int col) {
    Node variable = dataSet.getVariable(col - getNumLeadingCols());
    if (variable == null) {
        throw new NullPointerException();
    }
    if (!isEmpty(dataSet, col - getNumLeadingCols())) {
        throw new IllegalArgumentException("Old column not empty.");
    }
    String name = variable.getName();
    DiscreteVariable var = new DiscreteVariable(name);
    var.setCategoryNamesDisplayed(true);
    dataSet.removeColumn(col - getNumLeadingCols());
    dataSet.addVariable(col - getNumLeadingCols(), var);
    pcs.firePropertyChange("modelChanged", null, null);
    return var;
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node)

Example 44 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.

the class TimeoutComparison method getSubgraph.

private Graph getSubgraph(Graph graph, boolean discrete1, boolean discrete2, DataModel DataModel) {
    if (discrete1 && discrete2) {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof DiscreteVariable && node2 instanceof DiscreteVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    } else if (!discrete1 && !discrete2) {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof ContinuousVariable && node2 instanceof ContinuousVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    } else {
        Graph newGraph = new EdgeListGraph(graph.getNodes());
        for (Edge edge : graph.getEdges()) {
            Node node1 = DataModel.getVariable(edge.getNode1().getName());
            Node node2 = DataModel.getVariable(edge.getNode2().getName());
            if (node1 instanceof DiscreteVariable && node2 instanceof ContinuousVariable) {
                newGraph.addEdge(edge);
            }
            if (node1 instanceof ContinuousVariable && node2 instanceof DiscreteVariable) {
                newGraph.addEdge(edge);
            }
        }
        return newGraph;
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) TakesInitialGraph(edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Edge(edu.cmu.tetrad.graph.Edge)

Example 45 with DiscreteVariable

use of edu.cmu.tetrad.data.DiscreteVariable in project tetrad by cmu-phil.

the class DescriptiveStats method generateDescriptiveStats.

/**
 * Constructs a readable table of normality test results
 */
public static String generateDescriptiveStats(DataSet dataSet, Node variable) {
    NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
    int col = dataSet.getColumn(variable);
    double[] data = new double[dataSet.getNumRows()];
    boolean continuous = false;
    if (variable instanceof ContinuousVariable) {
        continuous = true;
        for (int i = 0; i < dataSet.getNumRows(); i++) {
            data[i] = dataSet.getDouble(i, col);
        }
    } else {
        try {
            for (int i = 0; i < dataSet.getNumRows(); i++) {
                DiscreteVariable var = (DiscreteVariable) variable;
                String category = var.getCategory(dataSet.getInt(i, col));
                int value = Integer.parseInt(category);
                data[i] = value;
            }
        } catch (NumberFormatException e) {
            return "Not a numerical discrete column.";
        }
    }
    String result = "Descriptive Statistics for: " + variable.getName() + "\n";
    result += "------------------------------------\n\n";
    double[] normalValues = normalParams(data);
    result += "Sample Size:\t\t" + dataSet.getNumRows() + "\n";
    result += "Mean:\t\t\t" + nf.format(normalValues[0]) + "\nStandard Deviation:\t" + nf.format(normalValues[1]) + "\nVariance:\t\t" + nf.format(normalValues[2]) + "\n";
    result += "Skewness:\t\t" + nf.format(StatUtils.skewness(data)) + "\n";
    result += "Excess Kurtosis:\t" + nf.format(StatUtils.kurtosis(data)) + "\n";
    if (continuous) {
        result += "SE Mean:\t\t" + nf.format(standardErrorMean(normalValues[1], dataSet.getNumRows())) + "\n";
    }
    double[] median = median(data);
    result += "Median:\t\t\t" + nf.format(median[0]) + "\n";
    if (continuous) {
        result += "Minimum Value:\t\t" + nf.format(median[1]) + "\nMaximum Value:\t\t" + nf.format(median[2]);
    }
    return result;
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) NumberFormat(java.text.NumberFormat)

Aggregations

DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)56 Node (edu.cmu.tetrad.graph.Node)37 DataSet (edu.cmu.tetrad.data.DataSet)18 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)16 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)11 LinkedList (java.util.LinkedList)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Dag (edu.cmu.tetrad.graph.Dag)3 NumberFormat (java.text.NumberFormat)3 Element (nu.xom.Element)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)2 Graph (edu.cmu.tetrad.graph.Graph)2 LogisticRegression (edu.cmu.tetrad.regression.LogisticRegression)2 List (java.util.List)2 Elements (nu.xom.Elements)2 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)1 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)1 StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)1 BoxDataSet (edu.cmu.tetrad.data.BoxDataSet)1