Package weka.core

Examples of weka.core.FastVector


  /** A simple test involving calling Weka functions directly. */
  @Test
  public void TestCreateInstances1()
  {
    int attributeNumber = 4;
    FastVector vecA = new FastVector(3);vecA.addElement(WekaDataCollector.MINUSONE);vecA.addElement(WekaDataCollector.ZERO);vecA.addElement(WekaDataCollector.ONE);
    FastVector vecBool = new FastVector(2);vecBool.addElement(Boolean.TRUE.toString());vecBool.addElement(Boolean.FALSE.toString());
    Attribute attrA = new Attribute("a", vecA), attrB= new Attribute("b",vecA), attrC=new Attribute("c",vecA),attrClass=new Attribute("class",vecBool);
   
    FastVector attributes = new FastVector(attributeNumber);attributes.addElement(attrA);attributes.addElement(attrB);attributes.addElement(attrC);attributes.addElement(attrClass);
    Instances trainingData = new Instances("trainingdata",attributes,10);// this assigns indices to attributes, without these indices I cannot create instances.
    trainingData.setClassIndex(attrClass.index());
    Instance inst = new Instance(attributeNumber);
    inst.setValue(attrA,0);inst.setValue(attrB, 1);inst.setValue(attrC, 1);inst.setValue(attrClass, 0);
    Assert.assertEquals(4,trainingData.numAttributes());
View Full Code Here


      short samples[][]=new short[totalsamples][features.size()+1];
      for(int i=0;i<totalsamples;i++)
        for(int j=0;j<features.size();j++)
          samples[i][j]=0;
      int i=0;
      FastVector fvClassVal = new FastVector(target.getSenses().size());
      short isense=0;
      for(Sense sense:target.getSenses())
      {
        fvClassVal.addElement(String.valueOf(isense));
        for(ArrayList<String> sample:sense.getParsedSamples())
        {
          for(String word:sample)
          {
            samples[i][Collections.binarySearch(features, word)]++;
          }
          samples[i][features.size()]=isense;
          i++;
        }
        isense++;
      }
      //Build the classifier
      //Generating attributes
      FastVector fvWekaAttributes = new FastVector(features.size()+1);     
      for(String feature:features)
      {
        fvWekaAttributes.addElement(new Attribute(feature));
      }
      fvWekaAttributes.addElement(new Attribute("Sense",fvClassVal));
     
      //Generating the class attribute
       // Create an empty training set
       ins = new Instances(target.getLemma(), fvWekaAttributes,  totalsamples);
      
View Full Code Here

  /**
   * Begins construction of an instance of pair classifier.
   */
  public WekaDataCollector()
  {
    FastVector vecBool = new FastVector(2);vecBool.addElement(Boolean.TRUE.toString());vecBool.addElement(Boolean.FALSE.toString());
    classAttribute = new Attribute("class",vecBool);
  }
View Full Code Here

        throw new IllegalArgumentException("too many attributes per instance");
    }
    instanceLength = (int)instanceLen;

   
    FastVector attributes = new FastVector(instanceLength+1);
    attributesOfAnInstance = new Attribute[instanceLength];
    fillInAttributeNames(attributesOfAnInstance,0,0,1,0,"",0);for(int i=0;i<instanceLength;++i) attributes.addElement(attributesOfAnInstance[i]);
    attributes.addElement(classAttribute);
    trainingData = new Instances(trainingSetName,attributes,capacity);
    trainingData.setClass(classAttribute);
  }
View Full Code Here

      return att;
    }
   
    protected PairRankingSupport(String name, String [] range)
    {
      FastVector vecA = new FastVector(3);
      for(String v:range) vecA.addElement(v);
      att = new Attribute(name,vecA);
    }
View Full Code Here

  /**
   * Begins construction of an instance of pair classifier.
   */
  public WekaDataCollector()
  {
    FastVector vecBool = new FastVector(2);vecBool.addElement(Boolean.TRUE.toString());vecBool.addElement(Boolean.FALSE.toString());
    classAttribute = new Attribute("class",vecBool);
  }
View Full Code Here

        throw new IllegalArgumentException("too many attributes per instance");
    }
    instanceLength = (int)instanceLen;

   
    FastVector attributes = new FastVector(instanceLength+1);
    attributesOfAnInstance = new Attribute[instanceLength];
    fillInAttributeNames(attributesOfAnInstance,0,0,1,0,"",0);for(int i=0;i<instanceLength;++i) attributes.addElement(attributesOfAnInstance[i]);
    attributes.addElement(classAttribute);
    trainingData = new Instances(trainingSetName,attributes,capacity);
    trainingData.setClass(classAttribute);
  }
View Full Code Here

      return att;
    }
   
    protected PairRankingSupport(String name, String [] range)
    {
      FastVector vecA = new FastVector(3);
      for(String v:range) vecA.addElement(v);
      att = new Attribute(name,vecA);
    }
View Full Code Here

  /** A simple test involving calling Weka functions directly. */
  @Test
  public void TestCreateInstances1()
  {
    int attributeNumber = 4;
    FastVector vecA = new FastVector(3);vecA.addElement(WekaDataCollector.MINUSONE);vecA.addElement(WekaDataCollector.ZERO);vecA.addElement(WekaDataCollector.ONE);
    FastVector vecBool = new FastVector(2);vecBool.addElement(Boolean.TRUE.toString());vecBool.addElement(Boolean.FALSE.toString());
    Attribute attrA = new Attribute("a", vecA), attrB= new Attribute("b",vecA), attrC=new Attribute("c",vecA),attrClass=new Attribute("class",vecBool);
   
    FastVector attributes = new FastVector(attributeNumber);attributes.addElement(attrA);attributes.addElement(attrB);attributes.addElement(attrC);attributes.addElement(attrClass);
    Instances trainingData = new Instances("trainingdata",attributes,10);// this assigns indices to attributes, without these indices I cannot create instances.
    trainingData.setClassIndex(attrClass.index());
    Instance inst = new Instance(attributeNumber);
    inst.setValue(attrA,0);inst.setValue(attrB, 1);inst.setValue(attrC, 1);inst.setValue(attrClass, 0);
    Assert.assertEquals(4,trainingData.numAttributes());
View Full Code Here

  /** A simple test involving calling Weka functions directly. */
  @Test
  public void TestCreateInstances1()
  {
    int attributeNumber = 4;
    FastVector vecA = new FastVector(3);vecA.addElement(WekaDataCollector.MINUSONE);vecA.addElement(WekaDataCollector.ZERO);vecA.addElement(WekaDataCollector.ONE);
    FastVector vecBool = new FastVector(2);vecBool.addElement(Boolean.TRUE.toString());vecBool.addElement(Boolean.FALSE.toString());
    Attribute attrA = new Attribute("a", vecA), attrB= new Attribute("b",vecA), attrC=new Attribute("c",vecA),attrClass=new Attribute("class",vecBool);
   
    FastVector attributes = new FastVector(attributeNumber);attributes.addElement(attrA);attributes.addElement(attrB);attributes.addElement(attrC);attributes.addElement(attrClass);
    Instances trainingData = new Instances("trainingdata",attributes,10);// this assigns indices to attributes, without these indices I cannot create instances.
    trainingData.setClassIndex(attrClass.index());
    Instance inst = new Instance(attributeNumber);
    inst.setValue(attrA,0);inst.setValue(attrB, 1);inst.setValue(attrC, 1);inst.setValue(attrClass, 0);
    Assert.assertEquals(4,trainingData.numAttributes());
View Full Code Here

TOP

Related Classes of weka.core.FastVector

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.