Examples of Plot2D


Examples of weka.gui.visualize.Plot2D

   
    String plotTitle = "Line chart";
    String userTitle = getOption(optionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
   
    Plot2D offScreenPlot = new Plot2D();
    offScreenPlot.setSize(width, height);
   
    // master plot
    PlotData2D master = new PlotData2D(series.get(0));
    master.setPlotName(plotTitle);
    boolean[] connectPoints = new boolean[series.get(0).numInstances()];
    for (int i = 0; i < connectPoints.length; i++) {
      connectPoints[i] = true;
    }
    master.setConnectPoints(connectPoints);
    offScreenPlot.setMasterPlot(master);
    // find x and y axis
    Instances masterInstances = series.get(0);
    int xAx = getIndexOfAttribute(masterInstances, xAxis);
    int yAx = getIndexOfAttribute(masterInstances, yAxis);
    if (xAx < 0) {
      xAx = 0;
    }
    if (yAx < 0) {
      yAx = 0;
    }
   
    // plotting axes and color
    offScreenPlot.setXindex(xAx);
    offScreenPlot.setYindex(yAx);
    offScreenPlot.setCindex(masterInstances.numAttributes() - 1);
    String colorAtt = getOption(optionalArgs, "-color");
    int tempC = getIndexOfAttribute(masterInstances, colorAtt);
    if (tempC >= 0) {
      offScreenPlot.setCindex(tempC);
    }
   
    // additional plots
    if (series.size() > 1) {
      for (Instances plotI : series) {
        PlotData2D plotD = new PlotData2D(plotI);
        connectPoints = new boolean[plotI.numInstances()];
        for (int i = 0; i < connectPoints.length; i++) {
          connectPoints[i] = true;
        }
        plotD.setConnectPoints(connectPoints);
        offScreenPlot.addPlot(plotD);
      }
    }
   
    // render
    java.awt.Graphics g = osi.getGraphics();
    offScreenPlot.paintComponent(g);
   
    return osi;
  }
View Full Code Here

Examples of weka.gui.visualize.Plot2D

   
    String plotTitle = "Scatter plot";
    String userTitle = getOption(optionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
   
    Plot2D offScreenPlot = new Plot2D();
    offScreenPlot.setSize(width, height);
   
    // master plot
    PlotData2D master = new PlotData2D(series.get(0));
    master.setPlotName(plotTitle);
    master.m_displayAllPoints = true;
   
    offScreenPlot.setMasterPlot(master);
   
    Instances masterInstances = series.get(0);
    int xAx = getIndexOfAttribute(masterInstances, xAxis);
    int yAx = getIndexOfAttribute(masterInstances, yAxis);
    if (xAx < 0) {
      xAx = 0;
    }
    if (yAx < 0) {
      yAx = 0;
    }
   
    // plotting axes and color
    offScreenPlot.setXindex(xAx);
    offScreenPlot.setYindex(yAx);
    offScreenPlot.setCindex(masterInstances.numAttributes() - 1);
    String colorAtt = getOption(optionalArgs, "-color");
    int tempC = getIndexOfAttribute(masterInstances, colorAtt);
    if (tempC >= 0) {
      offScreenPlot.setCindex(tempC);
    }
   
    String hasErrors = getOption(optionalArgs, "-hasErrors");
    // master plot is the error cases
    if (hasErrors != null) {
      int[] plotShapes = new int[masterInstances.numInstances()];
      for (int i = 0; i < plotShapes.length; i++) {
        plotShapes[i] = Plot2D.ERROR_SHAPE;
      }
      master.setShapeType(plotShapes);
    }
   
    // look for  an additional attribute that stores the
    // shape sizes
    String shapeSize = getOption(optionalArgs, "-shapeSize");
    if (shapeSize != null && shapeSize.length() > 0) {
      int shapeSizeI = getIndexOfAttribute(masterInstances, shapeSize);
     
      if (shapeSizeI >= 0) {
        int[] plotSizes = new int[masterInstances.numInstances()];
        for (int i = 0; i < masterInstances.numInstances(); i++) {
          plotSizes[i] = (int)masterInstances.instance(i).value(shapeSizeI);
        }
        master.setShapeSize(plotSizes);
      }
    }       
   
    // additional plots
    if (series.size() > 1) {
      for (Instances plotI : series) {
        PlotData2D plotD = new PlotData2D(plotI);
        plotD.m_displayAllPoints = true;

        offScreenPlot.addPlot(plotD);

        if (shapeSize != null && shapeSize.length() > 0) {
          int shapeSizeI = getIndexOfAttribute(plotI, shapeSize);
          if (shapeSizeI >= 0) {
            int[] plotSizes = new int[plotI.numInstances()];
            for (int i = 0; i < plotI.numInstances(); i++) {
              plotSizes[i] = (int)plotI.instance(i).value(shapeSizeI);
            }
            plotD.setShapeSize(plotSizes);
          }
        }
       
        // all other plots will have x shape if master plot are errors
        if (hasErrors != null) {
          int[] plotShapes = new int[plotI.numInstances()];
          for (int i = 0; i < plotShapes.length; i++) {
            plotShapes[i] = Plot2D.X_SHAPE;
          }
          plotD.setShapeType(plotShapes);
        }
      }
    }
   
    // render
    java.awt.Graphics g = osi.getGraphics();
    offScreenPlot.paintComponent(g);
   
    return osi;
  }
View Full Code Here

Examples of weka.gui.visualize.Plot2D

        {
            System.out.println(ex.toString());
        }

        //        PhaseIwrep.res_ROC_curves = new double[randData.numClasses()][2][tcEachClass.numInstances()];
            Plot2D myPlot2Db = new Plot2D();
            tc = new ThresholdCurve();
           
        for (int class_index =0 ; class_index< randData.numClasses();class_index++){
            tcEachClass[class_index] = tc.getCurve(eval_validationE.predictions(),class_index); // Uses Class 0-end
        }
        
           
        double[][] CL4 = new double[tcEachClass[0].numInstances()][randData.numClasses()];
        double[][] CL5 = new double[tcEachClass[0].numInstances()][randData.numClasses()];

        for (int tec_len = 0; tec_len < tcEachClass.length; tec_len++) {
            for (int cac = 0; cac < CL5.length; cac++) {
                CL4[cac][tec_len] = -1;
                CL5[cac][tec_len] = -1;
            }
        }

try{
        for (int instance_counter = 0; instance_counter < tcEachClass[0].numInstances(); instance_counter++) {   // here comes the first inst
            CL4[instance_counter][0] = (tcEachClass[0].instance(instance_counter).value(4));
            CL5[instance_counter][0] = (tcEachClass[0].instance(instance_counter).value(5));
           

            // map the threshold of the other curves to the 0-curve
            double thress = (tcEachClass[0].instance(instance_counter).value(tcEachClass[0].numAttributes()-1));
            for (int curves_added_counter = 1; curves_added_counter < tcEachClass.length; curves_added_counter++) { // pop open the second curve
                CL4[instance_counter][curves_added_counter] = (tcEachClass[curves_added_counter].instance(
                        ThresholdCurve.getThresholdInstance(tcEachClass[curves_added_counter], thress)).value(4));
                CL5[instance_counter][curves_added_counter] = (tcEachClass[curves_added_counter].instance(
                        ThresholdCurve.getThresholdInstance(tcEachClass[curves_added_counter], thress)).value(5));
            }

            double CL4_Total = 0;
            double CL4_Counter = 0;
            double CL5_Total = 0;
            double CL5_Counter = 0;
            for (int curves_counter = 0; curves_counter < tcEachClass.length; curves_counter++) {
                if (CL4[instance_counter][curves_counter] > -1) {CL4_Total += CL4[instance_counter][curves_counter]; CL4_Counter++;}
                if (CL5[instance_counter][curves_counter] > -1) {CL5_Total += CL5[instance_counter][curves_counter]; CL5_Counter++;}
            }

            double CL4_Average  = CL4_Total / CL4_Counter;  //average everything out
            double CL5_Average  = CL5_Total / CL5_Counter;
            double[] instArray = new double[tcResult2.numAttributes()];
            for (int i = 0; i < instArray.length; i++) {
                if (i == 0) {instArray[i] = instance_counter+1; continue;}
                if (i == 1) {instArray[i] = thress; continue;}
                if (i == 4) {instArray[i] = CL4_Average; continue;}
                if (i == 5) {instArray[i] = CL5_Average; continue;}
                if (i == tcResult2.numAttributes()-1) {instArray[i] = 1; continue;}
                instArray[i] = -99;
            }

            tcResult2.add(new Instance(1, instArray));
        }
            tcResult2.add(new Instance(1, attValues)); // adds the point 0,0

           
//            for (int instance_counter = 0; instance_counter < tcEachClass[class_index].numInstances();instance_counter++){
//                tcEachClass[0].add(tcEachClass[class_index].instance(instance_counter));
//            }

//            for (int class_index =0 ; class_index< randData.numClasses();class_index++){
            PlotData2D tempd = new PlotData2D((tcResult2));
//            tempd.addInstanceNumberAttribute();
            boolean[] cp = new boolean[tcResult2.numInstances()];
            for (int n = 1; n<cp.length; n++){
                cp[n] = true;
            }
            tempd.setConnectPoints(cp);
            myPlot2Db.addPlot(tempd);
            myPlot2Db.setXindex(4);
            myPlot2Db.setYindex(5);
//            myPlot2Db.setXindex(1);
//            myPlot2Db.setYindex(2);
//        }

            // Saves the ROC curve to file, and sets the path
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.