Package weka.core

Examples of weka.core.FastVector$FastVectorEnumeration


    }
   
    public void testBuildAndClassifyJ48() throws Exception
    {
        Classifier classifier = new J48();
        FastVector attributes = new FastVector();
        FastVector values = new FastVector();
        values.addElement("sunny");
        values.addElement("overcast");
        values.addElement("rain");
        attributes.addElement(new Attribute("outlook", values));
        values = new FastVector();
        values.addElement("false");
        values.addElement("true");
        attributes.addElement(new Attribute("windy", values));
        attributes.addElement(new Attribute("humidity"));
        attributes.addElement(new Attribute("temperature"));
        values = new FastVector();
        values.addElement("yes");
        values.addElement("no");
        attributes.addElement(new Attribute("play", values));
        Instances dataset = new Instances("", attributes, 15);
        dataset.add(createInstance(dataset, "sunny", "false", 85, 85, "no"));
        dataset.add(createInstance(dataset, "sunny", "true", 80, 90, "no"));
        dataset.add(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
View Full Code Here


public class ARFFTest {

  public static void testbedARFF() throws Exception
  {
    //header
    FastVector attributes = new FastVector();
   
    Attribute groupID = new Attribute("groupID");
   
    Attribute agentID = new Attribute("agentID");

    FastVector strategyAttributes = new FastVector();
    Attribute feedbackMean = new Attribute("feedbackMean");
    Attribute feedbackStdDev = new Attribute("feedbackStdDev");
    Attribute targetGroupdID = new Attribute("targetGroupID");
    strategyAttributes.addElement(feedbackMean);
    strategyAttributes.addElement(feedbackStdDev);
    strategyAttributes.addElement(targetGroupdID);
    Instances temp = new Instances("strategy", strategyAttributes, 3);
   
    Attribute strategy = new Attribute("strategy", temp);
   
    attributes.addElement(groupID);
View Full Code Here

  }
 
  public static void sampleFromWeka() throws Exception
  {

    FastVector      atts;
       FastVector      attsRel;
       FastVector      attVals;
       FastVector      attValsRel;
       Instances       data;
       Instances       dataRel;
       double[]        vals;
       double[]        valsRel;
       int             i;
  
       // 1. set up attributes
       atts = new FastVector();
       // - numeric
       atts.addElement(new Attribute("att1"));
       // - nominal
       attVals = new FastVector();
       for (i = 0; i < 5; i++)
         attVals.addElement("val" + (i+1));
       atts.addElement(new Attribute("att2", attVals));
       // - string
       atts.addElement(new Attribute("att3", (FastVector) null));
       // - date
       atts.addElement(new Attribute("att4", "yyyy-MM-dd"));
       // - relational
       attsRel = new FastVector();
       // -- numeric
       attsRel.addElement(new Attribute("att5.1"));
       // -- nominal
       attValsRel = new FastVector();
       for (i = 0; i < 5; i++)
         attValsRel.addElement("val5." + (i+1));
       attsRel.addElement(new Attribute("att5.2", attValsRel));
       dataRel = new Instances("att5", attsRel, 0);
       atts.addElement(new Attribute("att5", dataRel, 0));
  
       // 2. create Instances object
       data = new Instances("MyRelation", atts, 0);
  
       // 3. fill with data
       // first instance
       vals = new double[data.numAttributes()];
       // - numeric
       vals[0] = Math.PI;
       // - nominal
       vals[1] = attVals.indexOf("val3");
       // - string
       vals[2] = data.attribute(2).addStringValue("This is a string!");
       // - date
       vals[3] = data.attribute(3).parseDate("2001-11-09");
       // - relational
       dataRel = new Instances(data.attribute(4).relation(), 0);
       // -- first instance
       valsRel = new double[2];
       valsRel[0] = Math.PI + 1;
       valsRel[1] = attValsRel.indexOf("val5.3");
       dataRel.add(new Instance(1.0, valsRel));
       // -- second instance
       valsRel = new double[2];
       valsRel[0] = Math.PI + 2;
       valsRel[1] = attValsRel.indexOf("val5.2");
       dataRel.add(new Instance(1.0, valsRel));
       vals[4] = data.attribute(4).addRelation(dataRel);
       // add
       data.add(new Instance(1.0, vals));
  
       // second instance
       vals = new double[data.numAttributes()]// important: needs NEW array!
       // - numeric
       vals[0] = Math.E;
       // - nominal
       vals[1] = attVals.indexOf("val1");
       // - string
       //vals[2] = data.attribute(2).addStringValue("And another one!");
       vals[2] = Instance.missingValue();
      
      
       // - date
       vals[3] = data.attribute(3).parseDate("2000-12-01");
       // - relational
       dataRel = new Instances(data.attribute(4).relation(), 0);
       // -- first instance
       valsRel = new double[2];
       valsRel[0] = Math.E + 1;
       valsRel[1] = attValsRel.indexOf("val5.4");
       dataRel.add(new Instance(1.0, valsRel));
       // -- second instance
       valsRel = new double[2];
       valsRel[0] = Math.E + 2;
       valsRel[1] = attValsRel.indexOf("val5.1");
       dataRel.add(new Instance(1.0, valsRel));
       vals[4] = data.attribute(4).addRelation(dataRel);
       // add
       Instance inst = new Instance(1.0, vals);
       inst.setMissing(2);
View Full Code Here

  }
 
  public static void writeToArff(ArrayList<Feedback> feedbacks, String fileName) throws Exception
  {
    //header
    FastVector attributes = new FastVector();
    Attribute assessorID = new Attribute("assessorID");
    Attribute assesseeID = new Attribute("assesseeID");
    Attribute feedbackValue = new Attribute("feedbackValue");
    attributes.addElement(assessorID);
    attributes.addElement(assesseeID);
    attributes.addElement(feedbackValue);
   
    Instances data = new Instances("mydataset", attributes, 0);
    for(Feedback f : feedbacks)
    {
      //instances
View Full Code Here

     *            if true, add a dummy attribute as the first attribute
     *            value in the list of potential attribute values.
     */
    private void addNominalAttribute(String attributeName,
        SortedSet<String> attributeValues, boolean addDummy0) {
      FastVector wordValues = new FastVector(attributeValues.size()
          + (addDummy0 ? 1 : 0));
      if (addDummy0) {
        String dummyName;
        if (!attributeValues.contains("null"))
          dummyName = "null";
        else if (!attributeValues.contains("0"))
          dummyName = "0";
        else
          dummyName = Long.toString(System.currentTimeMillis());
        wordValues.addElement(dummyName);
      }
      for (String wordValue : attributeValues) {
        wordValues.addElement(wordValue);
      }
      Attribute attribute = new Attribute(attributeName, wordValues);
      wekaAttributes.addElement(attribute);
    }
View Full Code Here

     * @param bagOfWordsData
     * @param classNames
     */
    protected void initializeAttributes(SparseData bagOfWordsData,
        SortedSet<String> classNames) {
      wekaAttributes = new FastVector(bagOfWordsData.getNumericWords()
          .size()
          + bagOfWordsData.getNominalWordValueMap().size()
          + 2);
      // add instance id attribute
      wekaAttributes.addElement(new Attribute(INSTANCE_ID));
View Full Code Here

   * @param docLengthMap
   * @return
   */
  protected Instances initializeInstances(String arffRelation,
      BagOfWordsData bagOfWordsData, BagOfWordsDecorator bDecorator) {
    FastVector wekaAttributes = new FastVector(bagOfWordsData
        .getNumericWords().size()
        + bagOfWordsData.getNominalWordValueMap().size() + 2);
    // add instance id attribute
    wekaAttributes.addElement(new Attribute(INSTANCE_ID));
    // add numeric word attributes
    for (String word : bagOfWordsData.getNumericWords()) {
      Attribute attribute = new Attribute(word);
      wekaAttributes.addElement(attribute);
    }
    // add nominal word attributes
    for (Map.Entry<String, SortedSet<String>> nominalWordEntry : bagOfWordsData
        .getNominalWordValueMap().entrySet()) {
      FastVector wordValues = new FastVector(nominalWordEntry.getValue()
          .size());
      for (String wordValue : nominalWordEntry.getValue()) {
        wordValues.addElement(wordValue);
      }
      Attribute attribute = new Attribute(nominalWordEntry.getKey(),
          wordValues);
      wekaAttributes.addElement(attribute);
    }
    // add class attribute
    FastVector wekaClassLabels = new FastVector(bagOfWordsData.getClasses()
        .size());
    for (String classLabel : bagOfWordsData.getClasses()) {
      wekaClassLabels.addElement(classLabel);
    }
    wekaAttributes.addElement(new Attribute(CLASS, wekaClassLabels));
    Instances instances = new Instances(arffRelation, wekaAttributes, 0);
    instances.setClassIndex(instances.numAttributes() - 1);
    return instances;
View Full Code Here

    // Check whether there is actually any data
    if (stems.size() == 0) {
      throw new Exception("Couldn't find any data!");
    }
   
    FastVector atts = new FastVector(2);
    atts.addElement(new Attribute("doc", (FastVector) null));
    atts.addElement(new Attribute("keyphrases", (FastVector) null));
    Instances data = new Instances("keyphrase_training_data", atts, 0);
   
    // Build model
    m_KEAFilter = new KEAFilter(stopwords);
   
View Full Code Here

      m_KEAFilter.m_NODEfeature = false;
    } else {
      m_KEAFilter.loadThesaurus(m_Stemmer, m_Stopwords);
    }

    FastVector atts = new FastVector(3);
    atts.addElement(new Attribute("doc", (FastVector) null));
    atts.addElement(new Attribute("keyphrases", (FastVector) null));
    atts.addElement(new Attribute("filename", (String) null));
    Instances data = new Instances("keyphrase_training_data", atts, 0);

    if (m_KEAFilter.m_Dictionary == null) {
      buildGlobalDictionaries(stems);
    }
View Full Code Here

        Graphics g = NodePanel.this.getGraphics();
        int x = e.getX();
        int y = e.getY();
        int w = NodePanel.this.getWidth();
        int h = NodePanel.this.getHeight();
        FastVector tmp = new FastVector(4);
        for (int noa = 0; noa < m_numAttributes; noa++) {
    if (m_inputs[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_inputs[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , true);
      return;
    }
        }
        for (int noa = 0; noa < m_numClasses; noa++) {
    if (m_outputs[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_outputs[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , true);
      return;
    }
        }
        for (int noa = 0; noa < m_neuralNodes.length; noa++) {
    if (m_neuralNodes[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_neuralNodes[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , true);
      return;
    }

        }
        NeuralNode temp = new NeuralNode(String.valueOf(m_nextId),
                 m_random, m_sigmoidUnit);
        m_nextId++;
        temp.setX((double)e.getX() / w);
        temp.setY((double)e.getY() / h);
        tmp.addElement(temp);
        addNode(temp);
        selection(tmp, (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
      , true);
      }
      else {
        //then right click
        Graphics g = NodePanel.this.getGraphics();
        int x = e.getX();
        int y = e.getY();
        int w = NodePanel.this.getWidth();
        int h = NodePanel.this.getHeight();
        FastVector tmp = new FastVector(4);
        for (int noa = 0; noa < m_numAttributes; noa++) {
    if (m_inputs[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_inputs[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , false);
      return;
    }
   
   
        }
        for (int noa = 0; noa < m_numClasses; noa++) {
    if (m_outputs[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_outputs[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , false);
      return;
    }
        }
        for (int noa = 0; noa < m_neuralNodes.length; noa++) {
    if (m_neuralNodes[noa].onUnit(g, x, y, w, h)) {
      tmp.addElement(m_neuralNodes[noa]);
      selection(tmp,
          (e.getModifiers() & MouseEvent.CTRL_MASK) == MouseEvent.CTRL_MASK
          , false);
      return;
    }
View Full Code Here

TOP

Related Classes of weka.core.FastVector$FastVectorEnumeration

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.