List of usage examples for weka.gui.visualize PlotData2D getPlotName
public String getPlotName()
From source file:milk.visualize.MIPlot2D.java
License:Open Source License
/** * Renders this component/*from w ww . jav a 2 s.c om*/ * @param gx the graphics context */ public void paintComponent(Graphics gx) { //if(!isEnabled()) // return; super.paintComponent(gx); if (plotExemplars != null) { gx.setColor(m_axisColour); // Draw the axis name String xname = plotExemplars.attribute(m_xIndex).name(), yname = plotExemplars.attribute(m_yIndex).name(); gx.drawString(yname, m_XaxisStart + m_labelMetrics.stringWidth("M"), m_YaxisStart + m_labelMetrics.getAscent() / 2 + m_tickSize); gx.drawString(xname, m_XaxisEnd - m_labelMetrics.stringWidth(yname) + m_tickSize, (int) (m_YaxisEnd - m_labelMetrics.getAscent() / 2)); // Draw points Attribute classAtt = plotExemplars.classAttribute(); for (int j = 0; j < m_plots.size(); j++) { PlotData2D temp_plot = (PlotData2D) (m_plots.elementAt(j)); Instances instances = temp_plot.getPlotInstances(); StringTokenizer st = new StringTokenizer( instances.firstInstance().stringValue(plotExemplars.idIndex()), "_"); //////////////////// TLD stuff ///////////////////////////////// /* double[] mu = new double[plotExemplars.numAttributes()], sgm = new double[plotExemplars.numAttributes()]; st.nextToken(); // Squeeze first element int p=0; while(p<mu.length){ if((p==plotExemplars.idIndex()) || (p==plotExemplars.classIndex())) p++; if(p<mu.length){ mu[p] = Double.parseDouble(st.nextToken()); sgm[p] = Double.parseDouble(st.nextToken()); p++; } } Instance ins = instances.firstInstance(); gx.setColor((Color)m_colorList.elementAt((int)ins.classValue())); double mux=mu[m_xIndex], muy=mu[m_yIndex], sgmx=sgm[m_xIndex], sgmy=sgm[m_yIndex]; double xs = convertToPanelX(mux-3*sgmx), xe = convertToPanelX(mux+3*sgmx), xleng = Math.abs(xe-xs); double ys = convertToPanelY(muy+3*sgmy), ye = convertToPanelY(muy-3*sgmy), yleng = Math.abs(ye-ys); // Draw oval gx.drawOval((int)xs,(int)ys,(int)xleng,(int)yleng); // Draw a dot gx.fillOval((int)convertToPanelX(mux)-2, (int)convertToPanelY(muy)-2, 4, 4); */ //////////////////// TLD stuff ///////////////////////////////// //////////////////// instance-based stuff ///////////////////////////////// /* double[] core = new double[plotExemplars.numAttributes()], range=new double[plotExemplars.numAttributes()]; st.nextToken(); // Squeeze first element int p=0; while(p<range.length){ if((p==plotExemplars.idIndex()) || (p==plotExemplars.classIndex())) p++; if(p<range.length) range[p++] = Double.parseDouble(st.nextToken()); } p=0; while(st.hasMoreTokens()){ if((p==plotExemplars.idIndex()) || (p==plotExemplars.classIndex())) p++; core[p++] = Double.parseDouble(st.nextToken()); } Instance ins = instances.firstInstance(); gx.setColor((Color)m_colorList.elementAt((int)ins.classValue())); double rgx=range[m_xIndex], rgy=range[m_yIndex]; double x1 = convertToPanelX(core[m_xIndex]-rgx/2), y1 = convertToPanelY(core[m_yIndex]-rgy/2), x2 = convertToPanelX(core[m_xIndex]+rgx/2), y2 = convertToPanelY(core[m_yIndex]+rgy/2), x = convertToPanelX(core[m_xIndex]), y = convertToPanelY(core[m_yIndex]); // Draw a rectangle gx.drawLine((int)x1, (int)y1, (int)x2, (int)y1); gx.drawLine((int)x1, (int)y1, (int)x1, (int)y2); gx.drawLine((int)x2, (int)y1, (int)x2, (int)y2); gx.drawLine((int)x1, (int)y2, (int)x2, (int)y2); // Draw a dot gx.fillOval((int)x-3, (int)y-3, 6, 6); // Draw string StringBuffer text =new StringBuffer(temp_plot.getPlotName()+":"+instances.numInstances()); gx.drawString(text.toString(), (int)x1, (int)y2+m_labelMetrics.getHeight()); */ //////////////////// instance-based stuff ///////////////////////////////// //////////////////// normal graph ///////////////////////////////// // Paint numbers for (int i = 0; i < instances.numInstances(); i++) { Instance ins = instances.instance(i); if (!ins.isMissing(m_xIndex) && !ins.isMissing(m_yIndex)) { if (classAtt.isNominal()) gx.setColor((Color) m_colorList.elementAt((int) ins.classValue())); else { double r = (ins.classValue() - m_minC) / (m_maxC - m_minC); r = (r * 240) + 15; gx.setColor(new Color((int) r, 150, (int) (255 - r))); } double x = convertToPanelX(ins.value(m_xIndex)); double y = convertToPanelY(ins.value(m_yIndex)); String id = temp_plot.getPlotName(); gx.drawString(id, (int) (x - m_labelMetrics.stringWidth(id) / 2), (int) (y + m_labelMetrics.getHeight() / 2)); } } //////////////////// normal graph ///////////////////////////////// } } //////////////////// TLD stuff ///////////////////////////////// // Draw two Guassian contour with 3 stdDev // (-1, -1) with stdDev 1, 2 // (1, 1) with stdDev 2, 1 /*gx.setColor(Color.black); double mu=-1.5, sigmx, sigmy; // class 0 if(m_xIndex == 1) sigmx = 1; else sigmx = 2; if(m_yIndex == 1) sigmy = 1; else sigmy = 2; double x1 = convertToPanelX(mu-3*sigmx), x2 = convertToPanelX(mu+3*sigmx), xlen = Math.abs(x2-x1); double y1 = convertToPanelY(mu+3*sigmy), y2 = convertToPanelY(mu-3*sigmy), ylen = Math.abs(y2-y1); // Draw heavy oval gx.drawOval((int)x1,(int)y1,(int)xlen,(int)ylen); gx.drawOval((int)x1-1,(int)y1-1,(int)xlen+2,(int)ylen+2); gx.drawOval((int)x1+1,(int)y1+1,(int)xlen-2,(int)ylen-2); // Draw a dot gx.fillOval((int)convertToPanelX(mu)-3, (int)convertToPanelY(mu)-3, 6, 6); mu=1.5; // class 1 if(m_xIndex == 1) sigmx = 1; else sigmx = 2; if(m_yIndex == 1) sigmy = 1; else sigmy = 2; x1 = convertToPanelX(mu-3*sigmx); x2 = convertToPanelX(mu+3*sigmx); xlen = Math.abs(x2-x1); y1 = convertToPanelY(mu+3*sigmy); y2 = convertToPanelY(mu-3*sigmy); ylen = Math.abs(y2-y1); // Draw heavy oval gx.drawOval((int)x1,(int)y1,(int)xlen,(int)ylen); gx.drawOval((int)x1-1,(int)y1-1,(int)xlen+2,(int)ylen+2); gx.drawOval((int)x1+1,(int)y1+1,(int)xlen-2,(int)ylen-2); // Draw a dot gx.fillOval((int)convertToPanelX(mu)-3, (int)convertToPanelY(mu)-3, 6, 6); */ //////////////////// TLD stuff ///////////////////////////////// //////////////////// instance-based stuff ///////////////////////////////// /* // Paint a log-odds line: 1*x0+2*x1=0 double xstart, xend, ystart, yend, xCoeff, yCoeff; if(m_xIndex == 1) xCoeff = 1; else xCoeff = 2; if(m_yIndex == 1) yCoeff = 1; else yCoeff = 2; xstart = m_minX; ystart = -xstart*xCoeff/yCoeff; if(ystart > m_maxY){ ystart = m_maxY; xstart = -ystart*yCoeff/xCoeff; } yend = m_minY; xend = -yend*yCoeff/xCoeff; if(xend > m_maxX){ xend = m_maxX; yend = -xend*xCoeff/yCoeff; } // Draw a heavy line gx.setColor(Color.black); gx.drawLine((int)convertToPanelX(xstart), (int)convertToPanelY(ystart), (int)convertToPanelX(xend), (int)convertToPanelY(yend)); gx.drawLine((int)convertToPanelX(xstart)+1, (int)convertToPanelY(ystart)+1, (int)convertToPanelX(xend)+1, (int)convertToPanelY(yend)+1); gx.drawLine((int)convertToPanelX(xstart)-1, (int)convertToPanelY(ystart)-1, (int)convertToPanelX(xend)-1, (int)convertToPanelY(yend)-1); */ //////////////////// instance-based stuff ///////////////////////////////// }