⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrixpanel.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* *    MatrixPanel.java *    Copyright (C) 2002 Ashraf M. Kibriya * */package weka.gui.visualize;import java.io.IOException;import java.io.FileReader;import java.io.BufferedReader;import java.lang.ref.SoftReference;import java.util.Random;import java.awt.Dimension;import java.awt.Font;import java.awt.Color;import java.awt.Graphics;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.Image;import java.awt.image.BufferedImage;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseAdapter;import java.awt.event.ActionEvent;import java.awt.event.WindowEvent;import java.awt.event.ComponentEvent;import java.awt.event.WindowAdapter;import java.awt.event.ComponentAdapter;import javax.swing.JPanel;import javax.swing.JDialog;import javax.swing.JSplitPane;import javax.swing.ButtonGroup;import javax.swing.JFrame;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JList;import javax.swing.JSlider;import javax.swing.JTextField;import javax.swing.JComboBox;import javax.swing.JRadioButton;import javax.swing.BorderFactory;import javax.swing.JFileChooser;import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;import weka.gui.*;import weka.gui.visualize.*;import weka.core.*;/**  * This panel displays a plot matrix of the user selected attributes * of a given data set.  *  * The datapoints are coloured using a discrete colouring set if the  * user has selected a nominal attribute for colouring. If the user * has selected a numeric attribute then the datapoints are coloured * using a colour spectrum ranging from blue to red (low values to * high). Datapoints missing a class value are displayed in black. *  * @author Ashraf M. Kibriya (amk14@cs.waikato.ac.nz) * @version $Revision: 1.1.1.1 $ */public class MatrixPanel extends JPanel{  /** The that panel contains the actual matrix */  private final Plot m_plotsPanel;  /** The panel that displays the legend of the colouring attribute */  protected final ClassPanel m_cp = new ClassPanel();  /** The panel that contains all the buttons and tools, i.e. resize, jitter bars and sub-sampling buttons etc      on the bottom of the panel */  protected JPanel optionsPanel;  /** Split pane for splitting the matrix and the buttons and bars */  protected JSplitPane jp;  /** The button that updates the display to reflect the changes made by the user.       E.g. changed attribute set for the matrix    */  protected JButton m_updateBt = new JButton("Update");  /** The button to display a window to select attributes */  protected JButton m_selAttrib = new JButton("Select Attributes");  /** The dataset for which this panel will display the plot matrix for  */  protected Instances m_data=null;  /** The list for selecting the attributes to display the plot matrix */  protected JList m_attribList = new JList();  /** The scroll pane to scrolling the matrix */  protected final JScrollPane m_js = new JScrollPane();  /** The combo box to allow user to select the colouring attribute */  protected JComboBox m_classAttrib = new JComboBox();  /** The slider to adjust the size of the cells in the matrix  */    protected JSlider m_cellSize = new JSlider(50, 500, 100);  /** The slider to add jitter to the plots */    protected JSlider m_jitter = new JSlider(0, 20, 0);   /** For adding random jitter */  private Random rnd = new Random();      /** Array containing precalculated jitter values */  private int jitterVals[][];   /** The text area for percentage to resample data */  protected JTextField m_resamplePercent = new JTextField(5);  /** The label for resample percentage */  protected JButton m_resampleBt =  new JButton("SubSample % :");  /** Random seed for random subsample */  protected JTextField m_rseed = new JTextField(5);   /** For selecting same class distribution in the subsample as in the input */  protected JRadioButton origDist = new JRadioButton("Class distribution as in input data");  /** For selecting uniform class distribution in the subsample */  protected JRadioButton unifDist = new JRadioButton("Uniform class distribution");  /** Button group for subsampling radio buttons */  private ButtonGroup distGroup = new ButtonGroup();  /** Displays the current size beside the slider bar for cell size */  private final JLabel m_sizeLb = new JLabel("Size: [100]");  /** This array contains the indices of the attributes currently selected  */  private int [] m_selectedAttribs;  /** This contains the index of the currently selected colouring attribute  */  private int m_classIndex;  /** This is a local array cache for all the instance values for faster rendering */  private int [][] m_points;  /** This is an array cache for the colour of each of the instances depending on the       colouring attribute. If the colouring attribute is nominal then it contains the       index of the colour in our colour list. Otherwise, for numeric colouring attribute,      it contains the precalculated red component for each instance's colour */  private int [] m_pointColors;  /** Contains true for each value that is  missing, for each instance */   private boolean [][] m_missing;  /** This array contains: <br>      m_type[0][i] = [type of attribute, nominal, string or numeric]<br>      m_type[1][i] = [number of discrete values of nominal or string attribute <br>      or same as m_type[0][i] for numeric attribute] */  private int [][] m_type;  /** Stores the maximum size for Size label to keep it's size constant */  private Dimension m_sizeD;  /** Contains discrete colours for colouring for nominal attributes */  private FastVector m_colorList = new FastVector();  /** default colour list */  private static final Color [] m_defaultColors = {Color.blue,		 				   Color.red,						   Color.cyan,						   new Color(75, 123, 130),						   Color.pink,						   Color.green,						   Color.orange,						   new Color(255, 0, 255),						   new Color(255, 0, 0),						   new Color(0, 255, 0),						   Color.black};  /** Constructor      @param ins The instances object for the matrix  */  public MatrixPanel() {    m_rseed.setText("1");    origDist.setSelected(true);    distGroup.add(origDist);    distGroup.add(unifDist);     /** Setting up GUI **/    m_selAttrib.addActionListener( new ActionListener() {	public void actionPerformed(ActionEvent e) {	  final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 					 "Attribute Selection Panel",					 true);	  JPanel jp = new JPanel();	  JScrollPane js = new JScrollPane(m_attribList);	  JButton okBt = new JButton("OK");	  JButton cancelBt = new JButton("Cancel");	  final int [] savedSelection = m_attribList.getSelectedIndices();						  okBt.addActionListener( new ActionListener() {		      public void actionPerformed(ActionEvent e) {		jd.dispose(); }	    } );	  cancelBt.addActionListener( new ActionListener() {	      public void actionPerformed(ActionEvent e) {		m_attribList.setSelectedIndices(savedSelection);		jd.dispose();}	    });	  jd.addWindowListener( new WindowAdapter() {	      public void windowClosing(WindowEvent e) {		m_attribList.setSelectedIndices(savedSelection);		jd.dispose();}	    });	  jp.add(okBt);	  jp.add(cancelBt);	  jd.getContentPane().add(js, BorderLayout.CENTER); 	  jd.getContentPane().add(jp, BorderLayout.SOUTH);	  if(js.getPreferredSize().width < 200)	    jd.setSize( 250, 250 );	  else	    jd.setSize( (int) js.getPreferredSize().width+10, 250);						  jd.setLocation( m_selAttrib.getLocationOnScreen().x,			  m_selAttrib.getLocationOnScreen().y-jd.getHeight() );	  jd.show();	}      });          m_updateBt.addActionListener( new ActionListener() {	public void actionPerformed(ActionEvent e) {	  m_selectedAttribs = m_attribList.getSelectedIndices();	  initInternalFields();						  Plot a = m_plotsPanel;	  java.awt.FontMetrics fm = a.getFontMetrics(a.getFont());	  a.setCellSize( m_cellSize.getValue() );						  Dimension d = new Dimension((m_selectedAttribs.length)*(a.cellSize+a.extpad)+100, 				      (m_selectedAttribs.length)*(a.cellSize+a.extpad)				      +2*fm.getHeight()+a.extpad);	  //System.out.println("Size: "+a.cellSize+" Extpad: "+	  //		   a.extpad+" selected: "+	  //		   m_selectedAttribs.length+' '+d); 	  a.setPreferredSize(d);	  a.setSize( a.getPreferredSize() );	  a.setJitter( m_jitter.getValue() );						  m_js.revalidate();	  m_cp.setColours(m_colorList);	  m_cp.setCindex(m_classIndex);						  repaint();	}      });    m_updateBt.setPreferredSize( m_selAttrib.getPreferredSize() );          m_cellSize.addChangeListener( new ChangeListener() {	public void stateChanged(ChangeEvent ce) {	  m_sizeLb.setText("Size: ["+m_cellSize.getValue()+"]");	  m_sizeLb.setPreferredSize( m_sizeD );	  m_jitter.setMaximum( m_cellSize.getValue()/5 ); //20% of cell Size	}      });     m_resampleBt.addActionListener( new ActionListener() { 	public void actionPerformed(ActionEvent e) {	  JLabel rseedLb = new JLabel("Random Seed: ");	  JTextField rseedTxt = m_rseed;	  JLabel percentLb = new JLabel("Subsample as");	  JLabel percent2Lb = new JLabel("% of input: ");	  final JTextField percentTxt = new JTextField(5);	  percentTxt.setText( m_resamplePercent.getText() );	  JButton doneBt = new JButton("Done");	  final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 					 "Attribute Selection Panel",					 true) {	      public void dispose() { 		m_resamplePercent.setText(percentTxt.getText());		super.dispose();	      } 	    };	  jd.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );			       	  doneBt.addActionListener( new ActionListener(){ 	      public void actionPerformed(ActionEvent ae) {		jd.dispose();  	      }	    });	  GridBagLayout gbl = new GridBagLayout();	  GridBagConstraints gbc = new GridBagConstraints();	  JPanel p1 = new JPanel( gbl );			  gbc.anchor = gbc.WEST; gbc.fill = gbc.HORIZONTAL;	  gbc.insets = new Insets(0,2,2,2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -