Package jmt.engine.jwat

Examples of jmt.engine.jwat.MatrixOsservazioni


    String[] regExp = param.getRegularExp();
    String[] separator = param.getSeparator();
    double[] lineValue = new double[param.getNumVarSelected()];
    String[] lineToken = new String[param.getNumVar()];
    String parseToken = null;
    MatrixOsservazioni m;

    //Initialize the input log file.
    try {
      w = new FileWriter(MacroReplacer.replace(LOG_FILE_NAME));
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    try {
      //Init the progress show
      initShow(param.getOptions()[0] + 1);
      countObs = 0;
      totalRaw = 0;
      //Read the first line
      line = reader.readLine();
      while (line != null) {
        //Check if user has pressed the cancel button
        if (isCanceled()) {
          try {
            w.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
          valori = null;
          msg = INPUT_MSG_ABORT;
          return null;
        }
        input.setInput(line);
        totalRaw++;
        countObs++;
        //Update the progress show
        if (totalRaw % getStep() == 0) {
          updateInfos(totalRaw, "<HTML># observations read: " + totalRaw + "<p># errors: " + (totalRaw - countObs) + "</HTML>", false);
        }
        //Legge le stringhe e ne controlla il formato
        for (i = 0; i < param.getNumVar(); i++) {
          //Leggo il token con i separatori (se definiti) qualunque cosa ci sia dentro
          if (separator[i] != null) {
            parseToken = separator[i];
          } else {
            parseToken = regExp[i];
          }

          if (myMatch.contains(input, myComp.compile(parseToken))) {
            if (sel[i]) {
              //Prendo il token
              lineToken[i] = myMatch.getMatch().toString();
              if (separator[i] != null) {
                //  Se il token aveva dei separatori li tolgo
                lineToken[i] = lineToken[i].substring(1, lineToken[i].length() - 1);
                //E prendo quello che mi interessa di cio che rimane
                if (myMatch.contains(lineToken[i], myComp.compile(regExp[i]))) {
                  lineToken[i] = myMatch.getMatch().toString();
                } else {
                  //Wrong row, token dosen't contains required data
                  countObs--;
                  try {
                    w.write("Error in row " + totalRaw + " : Element " + i + " is wrong\n");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  break;
                }
              }
            }
          } else {
            //Wrong raw, element not found
            countObs--;
            try {
              w.write("Error in row " + totalRaw + " : Line doesn't match format (element " + i + " not found)\n");
            } catch (IOException e) {
              e.printStackTrace();
            }
            break;
          }
        }
        int j = 0;
        //Correct raw
        if (i == param.getNumVar()) {
          if (input.endOfInput()) {
            //Parse the string value in their correct formats
            for (i = 0; i < param.getNumVar(); i++) {
              if (sel[i]) {
                if (map[i] == null) {
                  lineValue[j++] = Double.parseDouble(lineToken[i]);
                } else {
                  lineValue[j++] = map[i].addNewValue(lineToken[i]);
                }
              }
            }
            valori.add(new Observation(lineValue, countObs));
          } else {
            //Worong row, the line wasn't processed completely
            countObs--;
            try {
              w.write("Error in row " + totalRaw + " : Too many fields\n");
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }

        line = reader.readLine();
      }
      try {
        w.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      //Wrong format, no element loaded
      if (valori.size() == 0) {
        closeView();
        valori = null;
        msg = INPUT_MSG_ABORT_WRONG_FORMAT;
        return null;
      }
      updateInfos(totalRaw, "Calculating Statistics...", false);
      m = new MatrixOsservazioni(valori.toArray(new Observation[valori.size()]), param.getSelName(), param.getSelType(), map);
      updateInfos(totalRaw + 1, "Done", true);
      return m;

    } catch (Exception e) {
      closeView();
View Full Code Here


  private KMean loadKmeanResult(int numCluster, int varSelLst[], String fileName, ZipFile zf) throws IOException {
    ClusteringInfosKMean curInfo[];
    int i, j, k;
    int curNumCluster;
    MatrixOsservazioni m = waSession.getDataModel().getMatrix();
    int numvars = m.getNumVariables();
    int numoss = m.getNumOfObs();
    DataInputStream dis = new DataInputStream(zf.getInputStream(new ZipEntry(fileName)));
    short asseg[][];

    //init result vector
    curInfo = new ClusteringInfosKMean[numCluster];
View Full Code Here

  private FuzzyKMean loadFuzzyResult(int numCluster, int varSelLst[], String fileName, ZipFile zf) throws IOException {
    ClusteringInfosFuzzy curInfo[];
    int i, j, k;
    int curNumCluster;
    MatrixOsservazioni m = waSession.getDataModel().getMatrix();
    int numvars = m.getNumVariables();
    int numoss = m.getNumOfObs();
    DataInputStream dis = new DataInputStream(zf.getInputStream(new ZipEntry(fileName)));
    double asseg[][];
    double entropy[];
    double error;
    ClusterInfoFuzzy infoCluster[];
View Full Code Here

    String[] regExp = param.getRegularExp();
    String[] separator = param.getSeparator();
    double[] lineValue = new double[param.getNumVarSelected()];
    String[] lineToken = new String[param.getNumVar()];
    String parseToken = null;
    MatrixOsservazioni m = null;

    try {
      w = new FileWriter(MacroReplacer.replace(LOG_FILE_NAME));
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    try {
      initShow(param.getOptions()[1] + 1);
      maxInd = generateRandom(param.getOptions()[0], param.getOptions()[1], catchVal);
      countObs = 0;
      totalRaw = 0;
      line = reader.readLine();

      for (k = 0; k <= maxInd; k++) {
        if (isCanceled()) {
          try {
            w.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
          valori = null;
          msg = INPUT_MSG_ABORT;
          return null;
        }

        if (!catchVal[k]) {
          line = reader.readLine();
          continue;
        }
        input.setInput(line);
        totalRaw++;
        countObs++;
        if (totalRaw % getStep() == 0) {
          updateInfos(totalRaw, "<HTML># observations read: " + totalRaw + "<p># errors: " + (totalRaw - countObs) + "</HTML>", false);
        }
        //Legge le stringhe e ne controlla il formato
        for (i = 0; i < param.getNumVar(); i++) {
          //Leggo il token con i separatori (se definiti) qualunque cosa ci sia dentro
          if (separator[i] != null) {
            parseToken = separator[i];
          } else {
            parseToken = regExp[i];
          }

          if (myMatch.contains(input, myComp.compile(parseToken))) {
            if (sel[i]) {
              //Prendo il token
              lineToken[i] = myMatch.getMatch().toString();
              if (separator[i] != null) {
                //  Se il token aveva dei separatori li tolgo
                lineToken[i] = lineToken[i].substring(1, lineToken[i].length() - 1);
                //E prendo quello che mi interessa di cio che rimane
                if (myMatch.contains(lineToken[i], myComp.compile(regExp[i]))) {
                  lineToken[i] = myMatch.getMatch().toString();
                } else {
                  //Riga sbagliata, decremento il num di oss
                  countObs--;

                  try {
                    w.write("Error in row " + k + " : Element " + i + " is wrong\n");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  break;
                }
              }
            }
          } else {
            //Riga sbagliata, decremento il num di oss
            countObs--;
            try {
              w.write("Error in row " + k + " : Line doesn't match format (element " + i + " not found)\n");
            } catch (IOException e) {
              e.printStackTrace();
            }
            break;

          }
        }
        j = 0;
        //Riga Corretta
        if (i == param.getNumVar()) {
          if (input.endOfInput()) {
            //Converte i valori (stringa) letti
            for (i = 0; i < param.getNumVar(); i++) {
              if (sel[i]) {
                if (map[i] == null) {
                  lineValue[j++] = Double.parseDouble(lineToken[i]);
                } else {
                  lineValue[j++] = map[i].addNewValue(lineToken[i]);
                }
              }
            }
            valori.add(new Observation(lineValue, countObs));
          } else {
            //Riga sbagliata, decremento il num di oss
            countObs--;
            try {
              w.write("Error in row " + k + " : Too many fields\n");
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        line = reader.readLine();
      }
      try {
        w.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
      //Wrong format, no element loaded
      if (valori.size() == 0) {
        closeView();
        valori = null;
        msg = INPUT_MSG_ABORT_WRONG_FORMAT;
        return null;
      }

      updateInfos(totalRaw, "Calculating Statistics...", false);
      m = new MatrixOsservazioni(valori.toArray(new Observation[valori.size()]), param.getSelName(), param.getSelType(), map);
      updateInfos(totalRaw + 1, "Done", true);
      return m;

    } catch (Exception e) {
      closeView();
View Full Code Here

    this.add(mainbox);
    model.addOnSetMatrixObservationListener(new SetMatrixListener() {

      public void onSetMatrixObservation() {
        MatrixOsservazioni m = model.getMatrix();
        String[] varLst = m.getVariableNames();
        varList.setListData(varLst);
        varList.setSelectionModel(new myListSelectionModel(model.getMatrix().getNumVariables()));
      }

      public void onResetMatrixObservation() {
View Full Code Here

    String[] regExp = param.getRegularExp();
    String[] separator = param.getSeparator();
    double[] lineValue = new double[param.getNumVarSelected()];
    String[] lineToken = new String[param.getNumVar()];
    String parseToken = null;
    MatrixOsservazioni m = null;

    try {
      initShow(maxInd - minInd + 1);
      countObs = 0;
      totalRaw = 0;
      line = reader.readLine();

      for (i = 0; line != null && i < (minInd - 1); i++) {
        line = reader.readLine();
      }

      while (totalRaw + minInd <= maxInd) {
        if (isCanceled()) {
          try {
            w.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
          valori = null;
          msg = INPUT_MSG_ABORT;
          return null;
        }
        input.setInput(line);
        totalRaw++;
        countObs++;
        if (totalRaw % getStep() == 0) {
          updateInfos(totalRaw, "<HTML># observations read: " + totalRaw + "<p># errors: " + (totalRaw - countObs) + "</HTML>", false);
        }
        //Legge le stringhe e ne controlla il formato
        for (i = 0; i < param.getNumVar(); i++) {
          //Leggo il token con i separatori (se definiti) qualunque cosa ci sia dentro
          if (separator[i] != null) {
            parseToken = separator[i];
          } else {
            parseToken = regExp[i];
          }

          if (myMatch.contains(input, myComp.compile(parseToken))) {
            if (sel[i]) {
              //Prendo il token
              lineToken[i] = myMatch.getMatch().toString();
              if (separator[i] != null) {
                //  Se il token aveva dei separatori li tolgo
                lineToken[i] = lineToken[i].substring(1, lineToken[i].length() - 1);
                //E prendo quello che mi interessa di cio che rimane
                if (myMatch.contains(lineToken[i], myComp.compile(regExp[i]))) {
                  lineToken[i] = myMatch.getMatch().toString();
                } else {
                  //Riga sbagliata, decremento il num di oss
                  countObs--;

                  try {
                    w.write("Error in row " + (totalRaw + minInd) + " : Element " + i + " is wrong\n");
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                  break;
                }
              }
            }
          } else {
            //Riga sbagliata, decremento il num di oss
            countObs--;
            try {
              w.write("Error in row " + (totalRaw + minInd) + " : Line doesn't match format (element " + i + " not found)\n");
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            break;
          }
        }
        j = 0;
        //Riga Corretta
        if (i == param.getNumVar()) {
          if (input.endOfInput()) {
            //Converte i valori (stringa) letti
            for (i = 0; i < param.getNumVar(); i++) {
              if (sel[i]) {
                if (map[i] == null) {
                  lineValue[j++] = Double.parseDouble(lineToken[i]);
                } else {
                  lineValue[j++] = map[i].addNewValue(lineToken[i]);
                }
              }
            }
            valori.add(new Observation(lineValue, countObs));
          } else {
            //Riga sbagliata, decremento il num di oss
            countObs--;
            try {
              w.write("Error in row " + (totalRaw + minInd) + " : Too many fields\n");
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        }
        line = reader.readLine();
      }
      try {
        w.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      //Wrong format, no element loaded
      if (valori.size() == 0) {
        closeView();
        valori = null;
        msg = INPUT_MSG_ABORT_WRONG_FORMAT;
        return null;
      }

      updateInfos(totalRaw, "Calculating Statistics...", false);
      m = new MatrixOsservazioni(valori.toArray(new Observation[valori.size()]), param.getSelName(), param.getSelType(), map);
      updateInfos(totalRaw + 1, "Done", true);
      return m;
    } catch (Exception e) {
      closeView();
      try {
View Full Code Here

    Observation[] valori;
    String[] selName;
    int[] selType;
    double[] valLst;
    int numObs, numVar, i, j, id;
    MatrixOsservazioni m = null;
    VariableMapping[] map;
    DOMParser domP;
    NodeList tmpNodeLst, resNodeList = null;
    Node tmpNode;
    String tmpVal;
    String curType;
    DataInputStream dis;

    //Extracting zipped files in temp dir
    updateInfos(1, "Reading XML file", false);
    //System.out.println("Entry " + file+JwatSession.XMLext);

    //load xml file
    domP = new DOMParser();
    domP.parse(new InputSource(zis));
    Document doc = domP.getDocument();
    //parse variables
    tmpNodeLst = doc.getElementsByTagName(JwatSession.ROOT);
    curType = tmpNodeLst.item(0).getAttributes().getNamedItem("type").getNodeValue();
    if (JwatSession.WORKLOAD_SAVE.equals(curType)) {
      res = new WorkloadResultLoader();
    } else {
      if (JwatSession.TRAFFIC_SAVE.equals(curType)) {
        res = new WorkloadResultLoader();
      }
    }
    tmpNodeLst = doc.getElementsByTagName("Variables");
    tmpNode = tmpNodeLst.item(0);
    tmpVal = tmpNode.getAttributes().getNamedItem("num").getNodeValue();
    numVar = Integer.parseInt(tmpVal);
    selName = new String[numVar];
    selType = new int[numVar];

    tmpNodeLst = tmpNode.getChildNodes();
    //System.out.println(tmpNodeLst.getLength());
    j = 0;
    updateInfos(2, "Reading Variables", false);
    for (i = 0; i < tmpNodeLst.getLength(); i++) {
      tmpNode = tmpNodeLst.item(i);
      //System.out.println("VARIABLES:");
      if (tmpNode.getNodeType() == Node.ELEMENT_NODE) {
        tmpVal = tmpNode.getAttributes().getNamedItem("name").getNodeValue();
        //System.out.println("NOME " + tmpVal);
        selName[j] = tmpVal;
        tmpVal = tmpNode.getAttributes().getNamedItem("type").getNodeValue();
        //System.out.println("TIPO " + tmpVal);
        selType[j] = Integer.parseInt(tmpVal);
        j++;
      }
    }

    //parse data
    updateInfos(3, "Reading Data", false);
    tmpNodeLst = doc.getElementsByTagName("Data");
    tmpNode = tmpNodeLst.item(0);
    tmpVal = tmpNode.getAttributes().getNamedItem("size").getNodeValue();
    numObs = Integer.parseInt(tmpVal);
    file = tmpNode.getAttributes().getNamedItem("filename").getNodeValue();

    resNodeList = doc.getElementsByTagName("Results");

    valori = new Observation[numObs];
    map = new VariableMapping[numVar];
    valLst = new double[numVar];

    //System.out.println("Reading varaibles mapping");
    updateInfos(3, "Reading Mapping", false);
    for (j = 0; j < numVar; j++) {
      if (selType[j] == JWATConstants.DATE) {
        map[j] = new DataMapping();
      }
      if (selType[j] == JWATConstants.NUMERIC) {
        map[j] = null;
      }
      if (selType[j] == JWATConstants.STRING) {
        map[j] = loadVarMapping(zf, selName[j]);
        //System.out.println(selName[j] + " " + selType[j]);
      }
    }

    //load data file
    zis = zf.getInputStream(new ZipEntry(file));
    //System.out.println("Entry " + file);
    dis = new DataInputStream(zis);

    for (i = 0; i < numObs; i++) {
      id = dis.readInt();
      for (j = 0; j < numVar; j++) {
        valLst[j] = dis.readDouble();
      }
      valori[i] = new Observation(valLst, id);
    }
    //System.out.println("Create matrix");
    updateInfos(5, "Create matrix", false);
    m = new MatrixOsservazioni(valori, selName, selType, map);
    session.getDataModel().setMatrix(m);

    return resNodeList;
  }
View Full Code Here

TOP

Related Classes of jmt.engine.jwat.MatrixOsservazioni

Copyright © 2018 www.massapicom. 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.