Package weka.core

Examples of weka.core.Instances


   * updates the capabilities filter of the GOE.
   *
   * @param filter  the new filter to use
   */
  protected void updateCapabilitiesFilter(Capabilities filter) {
    Instances     tempInst;
    Capabilities   filterClass;

    if (filter == null) {
      m_ClassifierEditor.setCapabilitiesFilter(new Capabilities(null));
      return;
    }
   
    if (!ExplorerDefaults.getInitGenericObjectEditorFilter())
      tempInst = new Instances(m_Instances, 0);
    else
      tempInst = new Instances(m_Instances);
    tempInst.setClassIndex(m_ClassCombo.getSelectedIndex());

    try {
      filterClass = Capabilities.forInstances(tempInst);
    }
    catch (Exception e) {
View Full Code Here


      jf.setVisible(true);
      if (args.length == 1) {
  System.err.println("Loading instances from " + args[0]);
  java.io.Reader r = new java.io.BufferedReader(
         new java.io.FileReader(args[0]));
  Instances i = new Instances(r);
  sp.setInstances(i);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
View Full Code Here

    public ArffReader(Reader reader, Instances template, int lines, int capacity) throws IOException {
      m_Lines     = lines;
      m_Tokenizer = new StreamTokenizer(reader);
      initTokenizer();

      m_Data = new Instances(template, capacity);
      initBuffers();
    }
View Full Code Here

            }
            break;
          case Attribute.RELATIONAL:
            try {
              ArffReader arff = new ArffReader(new StringReader(m_Tokenizer.sval), m_Data.attribute(m_IndicesBuffer[numValues]).relation(), 0);
              Instances data = arff.getData();
              m_ValueBuffer[numValues] = m_Data.attribute(m_IndicesBuffer[numValues]).addRelation(data);
            }
            catch (Exception e) {
              throw new IOException(e.toString() + " of line " + getLineNo());
            }
View Full Code Here

            }
            break;
          case Attribute.RELATIONAL:
            try {
              ArffReader arff = new ArffReader(new StringReader(m_Tokenizer.sval), m_Data.attribute(i).relation(), 0);
              Instances data = arff.getData();
              instance[i] = m_Data.attribute(i).addRelation(data);
            }
            catch (Exception e) {
              throw new IOException(e.toString() + " of line " + getLineNo());
            }
View Full Code Here

      // Check if any attributes have been declared.
      if (attributes.size() == 0) {
        errorMessage("no attributes declared");
      }
     
      m_Data = new Instances(relationName, attributes, capacity);
    }
View Full Code Here

                    " must be terminated by " + "@end " + attributeName);
            }
          } while (true);
         
          // Make relation and restore original set of attributes
          Instances relation = new Instances(attributeName, attributes, 0);
          attributes = atts;
          attributes.add(new Attribute(attributeName, relation, attributes.size()));
        } else {
          errorMessage("no valid attribute type or invalid "+
                "enumeration");
View Full Code Here

     * Returns the header format
     *
     * @return      the header format
     */
    public Instances getStructure() {
      return new Instances(m_Data, 0);
    }
View Full Code Here

    String relationName;
    if (m_sourceFile != null)
      relationName = (m_sourceFile.getName()).replaceAll("\\.[cC][sS][vV]$","");
    else
      relationName = "stream";
    Instances dataSet = new Instances(relationName,
              atts,
              m_cumulativeInstances.size());

    for (int i = 0; i < m_cumulativeInstances.size(); i++) {
      current = m_cumulativeInstances.get(i);
      double [] vals = new double[dataSet.numAttributes()];
      for (int j = 0; j < current.size(); j++) {
  Object cval = current.get(j);
  if (cval instanceof String) {
    if (((String)cval).compareTo(m_MissingValue) == 0) {
      vals[j] = Utils.missingValue();
    } else {
      if (dataSet.attribute(j).isString()) {
        vals[j] = dataSet.attribute(j).addStringValue((String) cval);
      }
      else if (dataSet.attribute(j).isNominal()) {
        // find correct index
        Hashtable<Object,Integer> lookup = m_cumulativeStructure.get(j);
        int index = ((Integer)lookup.get(cval)).intValue();
        vals[j] = index;
      }
      else {
        throw new IllegalStateException("Wrong attribute type at position " + (i+1) + "!!!");
      }
    }
  } else if (dataSet.attribute(j).isNominal()) {
    // find correct index
    Hashtable<Object,Integer> lookup = m_cumulativeStructure.get(j);
    int index = ((Integer)lookup.get(cval)).intValue();
    vals[j] = index;
  } else if (dataSet.attribute(j).isString()) {
    vals[j] = dataSet.attribute(j).addStringValue("" + cval);
  } else {
    vals[j] = ((Double)cval).doubleValue();
  }
      }
      dataSet.add(new DenseInstance(1.0, vals));
    }
    m_structure = new Instances(dataSet, 0);
    setRetrieval(BATCH);
    m_cumulativeStructure = null; // conserve memory
   
    // close the stream
    m_sourceReader.close();
View Full Code Here

    String relationName;
    if (m_sourceFile != null)
      relationName = (m_sourceFile.getName()).replaceAll("\\.[cC][sS][vV]$","");
    else
      relationName = "stream";
    m_structure = new Instances(relationName, attribNames, 0);
  }
View Full Code Here

TOP

Related Classes of weka.core.Instances

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.