Example usage for weka.gui.visualize VisualizePanel VisualizePanel

List of usage examples for weka.gui.visualize VisualizePanel VisualizePanel

Introduction

In this page you can find the example usage for weka.gui.visualize VisualizePanel VisualizePanel.

Prototype

public VisualizePanel() 

Source Link

Document

Constructor

Usage

From source file:adams.flow.sink.WekaClassifierErrors.java

License:Open Source License

/**
 * Creates the panel to display in the dialog.
 *
 * @return      the panel/* w w w .  ja v  a  2 s. c o  m*/
 */
@Override
protected BasePanel newPanel() {
    BasePanel result;

    result = new BasePanel(new BorderLayout());
    m_VisualizePanel = new VisualizePanel();
    result.add(m_VisualizePanel, BorderLayout.CENTER);

    return result;
}

From source file:adams.flow.sink.WekaClassifierErrors.java

License:Open Source License

/**
 * Creates a new panel for the token.//  w  w  w.j  a v a  2 s  .c o  m
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel
 */
public AbstractDisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;
    String name;

    if (token != null)
        name = "Classifier errors (" + getEvaluation(token).getHeader().relationName() + ")";
    else
        name = "Classifier errors";

    result = new AbstractComponentDisplayPanel(name) {
        private static final long serialVersionUID = -7362768698548152899L;
        protected VisualizePanel m_VisualizePanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
            m_VisualizePanel = new VisualizePanel();
            add(m_VisualizePanel, BorderLayout.CENTER);
        }

        @Override
        public void display(Token token) {
            try {
                Evaluation eval = getEvaluation(token);
                DataGenerator generator = new DataGenerator(eval, m_ErrorScaler);
                PlotData2D plotdata = generator.getPlotData();
                plotdata.setPlotName(generator.getPlotInstances().relationName());
                m_VisualizePanel.addPlot(plotdata);
                m_VisualizePanel.setColourIndex(plotdata.getPlotInstances().classIndex());
                if ((m_VisualizePanel.getXIndex() == 0) && (m_VisualizePanel.getYIndex() == 1)) {
                    try {
                        m_VisualizePanel.setXIndex(m_VisualizePanel.getInstances().classIndex()); // class
                        m_VisualizePanel.setYIndex(m_VisualizePanel.getInstances().classIndex() - 1); // predicted class
                    } catch (Exception e) {
                        // ignored
                    }
                }
            } catch (Exception e) {
                getLogger().log(Level.SEVERE, "Failed to display token: " + token, e);
            }
        }

        @Override
        public JComponent supplyComponent() {
            return m_VisualizePanel;
        }

        @Override
        public void clearPanel() {
            m_VisualizePanel.removeAllPlots();
        }

        public void cleanUp() {
            m_VisualizePanel.removeAllPlots();
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:adams.flow.sink.WekaCostCurve.java

License:Open Source License

/**
 * Creates a new panel for the token.//ww  w  . j a va2  s .c o  m
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel
 */
public AbstractDisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;
    String name;

    if (token != null)
        name = "Cost curve (" + getEvaluation(token).getHeader().relationName() + ")";
    else
        name = "Cost curve";

    result = new AbstractComponentDisplayPanel(name) {
        private static final long serialVersionUID = -3513994354297811163L;
        protected VisualizePanel m_VisualizePanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
            m_VisualizePanel = new VisualizePanel();
            add(m_VisualizePanel, BorderLayout.CENTER);
        }

        @Override
        public void display(Token token) {
            try {
                Evaluation eval = getEvaluation(token);
                m_ClassLabelRange.setMax(eval.getHeader().classAttribute().numValues());
                int[] indices = m_ClassLabelRange.getIntIndices();
                for (int index : indices) {
                    weka.classifiers.evaluation.CostCurve curve = new weka.classifiers.evaluation.CostCurve();
                    Instances data = curve.getCurve(eval.predictions(), index);
                    PlotData2D plot = new PlotData2D(data);
                    plot.setPlotName(eval.getHeader().classAttribute().value(index));
                    plot.m_displayAllPoints = true;
                    boolean[] connectPoints = new boolean[data.numInstances()];
                    for (int cp = 1; cp < connectPoints.length; cp++)
                        connectPoints[cp] = true;
                    plot.setConnectPoints(connectPoints);
                    m_VisualizePanel.addPlot(plot);
                }
            } catch (Exception e) {
                getLogger().log(Level.SEVERE, "Failed to display token: " + token, e);
            }
        }

        @Override
        public JComponent supplyComponent() {
            return m_VisualizePanel;
        }

        @Override
        public void clearPanel() {
            m_VisualizePanel.removeAllPlots();
        }

        public void cleanUp() {
            m_VisualizePanel.removeAllPlots();
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:adams.flow.sink.WekaInstancesPlot.java

License:Open Source License

/**
 * Creates a new panel for the token./* w w w. j a  v  a 2s  . c om*/
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel
 */
public AbstractDisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;
    String name;

    name = "Instances plot";

    result = new AbstractComponentDisplayPanel(name) {
        private static final long serialVersionUID = -7362768698548152899L;
        protected VisualizePanel m_VisualizePanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
            m_VisualizePanel = new VisualizePanel();
            add(m_VisualizePanel, BorderLayout.CENTER);
        }

        @Override
        public void display(Token token) {
            PlotData2D plot;
            Instances data;

            try {
                data = (Instances) token.getPayload();
                m_AttributeX.setData(data);
                m_AttributeY.setData(data);
                plot = new PlotData2D(data);
                if ((m_AttributeX.getIntIndex() != -1) && (m_AttributeY.getIntIndex() != -1))
                    plot.setPlotName(data.attribute(m_AttributeX.getIntIndex()).name() + " vs "
                            + data.attribute(m_AttributeX.getIntIndex()).name());
                plot.m_displayAllPoints = true;
                m_VisualizePanel.addPlot(plot);
                if (m_AttributeX.getIntIndex() != -1)
                    m_VisualizePanel.setXIndex(m_AttributeX.getIntIndex());
                if (m_AttributeY.getIntIndex() != -1)
                    m_VisualizePanel.setYIndex(m_AttributeY.getIntIndex());
            } catch (Exception e) {
                handleException("Failed to display token: " + token, e);
            }
        }

        @Override
        public JComponent supplyComponent() {
            return m_VisualizePanel;
        }

        @Override
        public void clearPanel() {
            m_VisualizePanel.removeAllPlots();
        }

        public void cleanUp() {
            m_VisualizePanel.removeAllPlots();
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:adams.flow.sink.WekaMarginCurve.java

License:Open Source License

/**
 * Creates a new panel for the token./*from w ww. ja  v a 2  s . co  m*/
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel
 */
public AbstractDisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;
    String name;

    if (token != null)
        name = "Margin curve (" + getEvaluation(token).getHeader().relationName() + ")";
    else
        name = "Margin curve";

    result = new AbstractComponentDisplayPanel(name) {
        private static final long serialVersionUID = -3513994354297811163L;
        protected VisualizePanel m_VisualizePanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
            m_VisualizePanel = new VisualizePanel();
            add(m_VisualizePanel, BorderLayout.CENTER);
        }

        @Override
        public void display(Token token) {
            try {
                Evaluation eval = getEvaluation(token);
                weka.classifiers.evaluation.MarginCurve curve = new weka.classifiers.evaluation.MarginCurve();
                Instances data = curve.getCurve(eval.predictions());
                PlotData2D plot = new PlotData2D(data);
                plot.m_displayAllPoints = true;
                boolean[] connectPoints = new boolean[data.numInstances()];
                for (int cp = 1; cp < connectPoints.length; cp++)
                    connectPoints[cp] = true;
                plot.setConnectPoints(connectPoints);
                m_VisualizePanel.addPlot(plot);
            } catch (Exception e) {
                getLogger().log(Level.SEVERE, "Failed to display token: " + token, e);
            }
        }

        @Override
        public JComponent supplyComponent() {
            return m_VisualizePanel;
        }

        @Override
        public void clearPanel() {
            m_VisualizePanel.removeAllPlots();
        }

        public void cleanUp() {
            m_VisualizePanel.removeAllPlots();
        }
    };

    if (token != null)
        result.display(token);

    return result;
}

From source file:adams.gui.menu.InstancesPlot.java

License:Open Source License

/**
 * Launches the functionality of the menu item.
 *///from w w  w  . ja  va 2 s  .c o  m
@Override
public void launch() {
    File file;
    AbstractFileLoader loader;
    if (m_Parameters.length == 0) {
        // choose file
        int retVal = m_FileChooser.showOpenDialog(getOwner());
        if (retVal != JFileChooser.APPROVE_OPTION)
            return;
        file = m_FileChooser.getSelectedFile();
        loader = m_FileChooser.getLoader();
    } else {
        file = new PlaceholderFile(m_Parameters[0]).getAbsoluteFile();
        loader = ConverterUtils.getLoaderForFile(file);
    }

    // build plot
    VisualizePanel panel = new VisualizePanel();
    getLogger().severe("Loading instances from " + file);
    try {
        loader.setFile(file);
        Instances i = loader.getDataSet();
        i.setClassIndex(i.numAttributes() - 1);
        PlotData2D pd1 = new PlotData2D(i);
        pd1.setPlotName("Master plot");
        panel.setMasterPlot(pd1);
    } catch (Exception e) {
        getLogger().log(Level.SEVERE, "Failed to load: " + file, e);
        GUIHelper.showErrorMessage(getOwner(),
                "Error loading file '" + file + "':\n" + Utils.throwableToString(e));
        return;
    }

    // create frame
    ChildFrame frame = createChildFrame(panel, GUIHelper.getDefaultDialogDimension());
    frame.setTitle(frame.getTitle() + " - " + file);
}

From source file:adams.gui.menu.MarginCurve.java

License:Open Source License

/**
 * Launches the functionality of the menu item.
 *//*from   ww w . j  av a  2s .  c om*/
@Override
public void launch() {
    File file;
    if (m_Parameters.length == 0) {
        // choose file
        int retVal = m_FileChooser.showOpenDialog(null);
        if (retVal != JFileChooser.APPROVE_OPTION)
            return;
        file = m_FileChooser.getSelectedFile();
    } else {
        file = new PlaceholderFile(m_Parameters[0]).getAbsoluteFile();
        m_FileChooser.setSelectedFile(file);
    }

    // create plot
    Instances result;
    try {
        result = m_FileChooser.getLoader().getDataSet();
    } catch (Exception e) {
        GUIHelper.showErrorMessage(getOwner(),
                "Error loading file '" + file + "':\n" + adams.core.Utils.throwableToString(e));
        return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    VisualizePanel vp = new VisualizePanel();
    PlotData2D plot = new PlotData2D(result);
    plot.m_displayAllPoints = true;
    boolean[] connectPoints = new boolean[result.numInstances()];
    for (int cp = 1; cp < connectPoints.length; cp++)
        connectPoints[cp] = true;
    try {
        plot.setConnectPoints(connectPoints);
        vp.addPlot(plot);
    } catch (Exception e) {
        GUIHelper.showErrorMessage(getOwner(), "Error adding plot:\n" + adams.core.Utils.throwableToString(e));
        return;
    }

    ChildFrame frame = createChildFrame(vp, GUIHelper.getDefaultDialogDimension());
    frame.setTitle(frame.getTitle() + " - " + file);
}

From source file:cyber009.main.MainSyntacticData.java

public static void main(String[] args) {
    Random r = new Random(System.currentTimeMillis());
    Variable v = new Variable();
    long timeStart = 0, timeEnd = 0;
    ANN ann = new ANN(v, 0.014013);
    for (int f = 2; f <= 2; f++) {
        v.N = f;/*from   w  ww  . j  a  v a  2s.  co m*/
        v.D = 4000;
        v.threshold = 0.0;
        cyber009.function.LinearFunction func = new cyber009.function.LinearFunction(v.N);
        v.X = new double[v.D][];
        v.TARGET = new double[v.D];
        v.WEIGHT = new double[v.N + 1];
        for (int d = 0; d < v.D; d++) {
            v.X[d] = new double[v.N + 1];
            v.X[d][0] = 1.0;
            for (int n = 1; n <= v.N; n++) {
                v.X[d][n] = r.nextGaussian();
            }
            v.TARGET[d] = func.syntacticFunction(v.X[d], v.threshold);
        }

        //v.showAll();
        //Lib.Utility.writeCSVDataSet("data/syn_data_x_"+v.N+"_d_"+v.D+".csv", v);

        List<Attribute> atts = new ArrayList<>();
        Attribute[] att = new Attribute[v.N + 2];
        for (int i = 0; i <= v.N; i++) {
            att[i] = new Attribute("X" + i);
            atts.add(att[i]);
        }
        List<String> classValus = new ArrayList<>();
        classValus.add("1.0");
        classValus.add("0.0");
        att[v.N + 1] = new Attribute("class", classValus);
        atts.add(att[v.N + 1]);
        Instances dataSet = new Instances("Syn Data", (ArrayList<Attribute>) atts, v.D);

        for (int d = 0; d < v.D; d++) {
            Instance ins = new DenseInstance(v.N + 2);
            for (int i = 0; i <= v.N; i++) {
                ins.setValue(atts.get(i), v.X[d][i]);
            }
            ins.setValue(atts.get(v.N + 1), v.TARGET[d]);
            dataSet.add(ins);
        }
        //System.out.println(dataSet);
        PlotData2D p2D = new PlotData2D(dataSet);
        p2D.setPlotName("Syn data");
        VisualizePanel vp = new VisualizePanel();
        vp.setName("Show Data");
        try {
            vp.addPlot(p2D);

            JFrame frame = new JFrame("Show Data");
            frame.setSize(600, 600);
            frame.setVisible(true);
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(vp, BorderLayout.CENTER);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            func.showCoefficients();
        } catch (Exception ex) {
            Logger.getLogger(MainSyntacticData.class.getName()).log(Level.SEVERE, null, ex);
        }

        ann.weightReset();
        timeStart = System.currentTimeMillis();
        ann.gradientDescent(10000L, 2, v.D);
        timeEnd = System.currentTimeMillis();
        //v.showTable();
        //v.showWEIGHT();
        System.out.println("feature #:" + v.N + " time:(" + (timeEnd - timeStart) + ")");
        v.showResult();
        //func.showCoefficients();
    }
}

From source file:cyber009.main.UDAL.java

public void showData() {
    List<Attribute> atts = new ArrayList<>();
    Attribute[] att = new Attribute[v.N + 2];
    for (int i = 0; i <= v.N; i++) {
        att[i] = new Attribute("X" + i);
        atts.add(att[i]);/*from  ww  w  . j  av a2 s.c om*/
    }
    List<String> classValus = new ArrayList<>();
    classValus.add("1.0");
    classValus.add("0.0");
    att[v.N + 1] = new Attribute("class", classValus);
    atts.add(att[v.N + 1]);
    Instances dataSet = new Instances("Syn Data", (ArrayList<Attribute>) atts, v.D);

    for (int d = 0; d < v.D; d++) {
        Instance ins = new DenseInstance(v.N + 2);
        for (int i = 0; i <= v.N; i++) {
            ins.setValue(atts.get(i), v.X[d][i]);
        }
        ins.setValue(atts.get(v.N + 1), v.TARGET[d]);
        dataSet.add(ins);
    }
    //System.out.println(dataSet);
    PlotData2D p2D = new PlotData2D(dataSet);
    p2D.setPlotName("Syn data");
    VisualizePanel vp = new VisualizePanel();
    vp.setName("Show Data");
    try {
        vp.addPlot(p2D);

        JFrame frame = new JFrame("Show Data");
        frame.setSize(600, 600);
        frame.setVisible(true);
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(vp, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        func.showCoefficients();
    } catch (Exception ex) {
        Logger.getLogger(MainSyntacticData.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:cyber009.main.UDALNeuralNetwork.java

public void showData() {
    //System.out.println(dataSet);
    PlotData2D p2D = new PlotData2D(dataSet);
    p2D.setPlotName("Syn data");
    VisualizePanel vp = new VisualizePanel();
    vp.setName("Show Data");
    try {/*from   ww w . j av  a2s  . c o  m*/
        vp.addPlot(p2D);

        JFrame frame = new JFrame("Show Data");
        frame.setSize(600, 600);
        frame.setVisible(true);
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(vp, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        func.showCoefficients();
    } catch (Exception ex) {
        Logger.getLogger(MainSyntacticData.class.getName()).log(Level.SEVERE, null, ex);
    }

}