示例#1
0
  private void calculateActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_calculateActionPerformed
    // TODO add your handling code here:
    DefaultTableModel dtm = (DefaultTableModel) jTResults.getModel();
    dtm.setRowCount(0);

    if (!KnnNo.getText().equals("")) {
      try {
        for (int i = 0; i <= Integer.parseInt(KnnNo.getText()); i++) {
          Results r = this.arrResFinal.get(i);
          Vector fila = new Vector();

          String code = "";

          ArrayList<Feature> arrFea = r.getCode();
          Iterator<Feature> itrFea = arrFea.iterator();
          while (itrFea.hasNext()) {
            code += itrFea.next().getFtr();
          }

          fila.add(code);
          fila.add(r.getAve());
          fila.add(r.getDist());
          fila.add(r.getCoffPro());

          dtm.addRow(fila);

          code = "";
        }
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null, "Please enter a valid Number", "Error", JOptionPane.ERROR_MESSAGE);
      }

    } else {
      JOptionPane.showMessageDialog(
          null, "Please enter a Knn Neighbor(s)", "Error", JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_calculateActionPerformed
示例#2
0
  /** Creates new form NewJFrame */
  public FrmResult(ArrayList<DataReview> dataRvw) {
    this.dataRvw = dataRvw;
    ArrayList<Results> arrRes = new ArrayList<Results>();
    // ArrayList<Results> arrResFinal = new ArrayList<Results>();
    Results resLower = null;
    initComponents();

    Iterator<DataReview> itrDr = this.dataRvw.iterator();
    while (itrDr.hasNext()) {
      DataReview dr = itrDr.next();
      String code = dr.getCode();
      float ave = dr.getAverage();

      //  Data
      Results r = new Results();
      ArrayList<Feature> arrFea = new ArrayList<Feature>(); // Array de Features

      // System.out.println("code: "+code+" ave: "+ave);

      int limit = 1; // Cut String limite
      for (int i = 0; i < code.length() - 1; i++) {
        Feature f = new Feature();
        f.setFtr(Integer.parseInt(code.substring(i, limit)));
        limit += 1;

        arrFea.add(f);
      }

      r.setCode(arrFea);
      r.setAve(ave);

      arrRes.add(r);
    }

    //        Iterator<Results> itrRes = arrRes.iterator();
    //        while (itrRes.hasNext()){
    //            Results res = itrRes.next();
    //            ArrayList<Feature> arrFea2 = res.getCode();
    //            float ave = res.getAve();
    //
    //            System.out.print("ArrayFeatures: ");
    //            Iterator<Feature> itrFea = arrFea2.iterator();
    //            while (itrFea.hasNext()) {
    //                Feature f = itrFea.next();
    //                System.out.print(f.getFtr());
    //            }
    //            System.out.println(" Average: "+res.getAve());
    //        }

    resLower = arrRes.get(0); //  Take teh lower result to get the neighbors.

    Iterator<Results> itrRes = arrRes.iterator();
    while (itrRes.hasNext()) {
      Results res = itrRes.next();
      ArrayList<Feature> arrFeaRes = res.getCode();
      float ave = res.getAve();

      ArrayList<Feature> arrFeaRLower = resLower.getCode();

      int cont = 0;

      for (int i = 0; i < arrFeaRes.size(); i++) {
        if (arrFeaRes.get(i).getFtr() != arrFeaRLower.get(i).getFtr()) {
          // System.out.println("AR: "+arrFeaRes.get(i).getFtr()+" >>
          // "+arrFeaRLower.get(i).getFtr());
          cont += 1;
        }
      }

      // System.out.println("");

      //  Create de Result Final
      Results resFinal = new Results();
      resFinal.setCode(arrFeaRes);
      resFinal.setAve(ave);
      resFinal.setDist(cont);

      if (cont != 0) {
        this.arrResFinal.add(resFinal);
      }
    }

    System.out.println("<< RESULTS >>");
    System.out.print("Lower Node: ");
    Iterator<Feature> itrFeaResLow = resLower.getCode().iterator();
    while (itrFeaResLow.hasNext()) {
      System.out.print(itrFeaResLow.next().getFtr());
    }
    System.out.println("");

    Iterator<Results> itrResFinal = this.arrResFinal.iterator();
    while (itrResFinal.hasNext()) {
      Results r = itrResFinal.next();
      ArrayList<Feature> arrFea = r.getCode();
      float ave = r.getAve();
      int dist = r.getDist();

      System.out.print("Features: ");
      Iterator<Feature> itrArrFea = arrFea.iterator();
      while (itrArrFea.hasNext()) {
        Feature f = itrArrFea.next();
        System.out.print(f.getFtr());
      }
      System.out.println(" Average: " + ave + " Distance: " + dist);
    }

    //  take the first object DataReview cause it's lower.
    for (int i = 0; i < 1; i++) {
      DataReview dr = this.dataRvw.get(i);
      KnnId.setText(dr.getCode());
      KnnAve.setText(String.valueOf(dr.getAverage()));
    }
  }