Package weka.core

Examples of weka.core.DenseInstance


   * Generate a new Instance entry shaped on the current string dataset structure
   * @param list  list of attribute values of this entry
   * @return
   */
  public Instance newInstance(Object ...list){
    Instance newInstance = new DenseInstance(dataset.numAttributes());
   
    Attribute att;
    for(int i=0; i<list.length; i++){
      att = dataset.attribute(i);
         String listval = list[i].toString();

        //System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){  }
         }
         else{
           try{
             newInstance.setValue(att, list[i].toString() );
           }catch(Exception e){
             e.printStackTrace();
          
         }
    }
View Full Code Here


   * @return
   */
  public Instance createNominalInstance(Object ...list){
   
   
    Instance newInstance = new DenseInstance(dataset.numAttributes());
   
    Attribute att;
    for(int i=0; i<list.length; i++){
      att = dataset.attribute(i);
         String listval = list[i].toString();
         //System.out.println(listval);

        //System.out.println(" ATTR. " + att + " VAL. " + listval);
         if(att.isNumeric()){
           try
             double dval = Double.parseDouble(listval);
             newInstance.setValue(att, dval );
           }catch(Exception ex){ 
             ex.printStackTrace();
           }
         }
         else{
           //att is nominal
           if(att.isNominal() && att.indexOfValue(listval)<0)
             return null//instance not compliant
          
          
           try{
             newInstance.setValue(att, list[i].toString() );
           }catch(Exception e){
             e.printStackTrace();
          
         }
    }
   
   
    newInstance.setDataset(dataset);
    //System.out.println("new instance "+newInstance);
    //System.out.println("dataset class index "+dataset.classIndex() + " "+dataset.classAttribute());

    //System.out.println("instance class index "+newInstance.classIndex() + " "+newInstance.classAttribute());

View Full Code Here

       duration = (endTime - startTime)/1000F;
      
       System.out.println("\nElapsed time: "+(duration)+"sec");
      
      //test on instance
       Instance instance = new DenseInstance(5);
       instance.setValue(data.attribute("Task"), "chickenpox");
       instance.setValue(data.attribute("Ability"), "pediatrician");
       instance.setValue(data.attribute("Disposition"), "distracted");
       instance.setValue(data.attribute("Cross"), "female");
      
       classifier.testInstance(instance);
      
       System.out.println(instance);
       //classifier.getWekaDataset().stringFilter();
View Full Code Here

            Instances dataset,
            Tuple tuple)
        throws ActivityUserException
    {
        int columnCount = dataset.numAttributes();
        Instance instance = new DenseInstance(columnCount);
        instance.setDataset(dataset);
        for (int i=0; i<columnCount; i++)
        {
            Attribute attribute = dataset.attribute(i);
            // we only support numeric and nominal attributes for now
            if (attribute.isDate())
            {
                Object value = tuple.getObject(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
                }
                // timestamp extends date
                else
                {
                    instance.setValue(i, ((Date)value).getTime());
                }
            }
            else if (attribute.isNumeric())
            {
                double value = tuple.getDouble(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
                }
                else
                {
                    instance.setValue(i, value);
                }
            }
            else if (attribute.isNominal() || attribute.isString())
            {
                String value = tuple.getString(i);
                if (tuple.wasNull())
                {
                    instance.setMissing(i);
                }
                else
                {
                    instance.setValue(i, value);
                }
            }
            else
            {
                throw new ActivityUserException(
View Full Code Here

                    _logger.debug("Processed " + count + " records.");
                }
            }
            // add weights according to instance class value
            if (classValue.equals(_config._positiveClassValue)) {
                _data.add(new DenseInstance(_config._positiveClassWeight, _values));
            } else {
                _data.add(new DenseInstance(_config._negativeClassWeight, _values));
            }
            _values = new double[_data.numAttributes()];
            if (_logger.isDebugEnabled()) {
                _logger.debug("Processed " + count + " records.");
            }
View Full Code Here

  @Override
  protected Instance process(Instance inst)
    throws Exception
  {
       Instance newInst = new DenseInstance(inst.numAttributes());
      
       newInst.setValue(0, inst.value(0));

       for(int i = 1; i < inst.numAttributes() - 1; i++)
       {
         double newVal = Math.log(inst.value(i) + 1);        
         newInst.setValue(i, newVal);
       }
      
       newInst.setValue(inst.numAttributes() - 1, inst.value(inst.numAttributes() - 1));
      
       return newInst;
  }
View Full Code Here

  @Override
  protected Instance process(Instance inst)
    throws Exception
  {
       Instance newInst = new DenseInstance(inst.numAttributes());
      
       newInst.setValue(0, inst.value(0));

       for(int i = 1; i < inst.numAttributes() - 1; i++)
       {
         double newVal = Math.log(inst.value(i) + 1);
         // double newVal = inst.value(i);          // Passthrough
        
         newInst.setValue(i, newVal);
       }
      
       newInst.setValue(inst.numAttributes() - 1, inst.value(inst.numAttributes() - 1));
      
       return newInst;
  }
View Full Code Here

  @Override
  protected Instance process(Instance inst)
    throws Exception
  {
       Instance newInst = new DenseInstance(inst.numAttributes());
      
       newInst.setValue(0, inst.value(0));

       for(int i = 1; i < inst.numAttributes() - 1; i++)
       {
         double newVal = Math.log(inst.value(i) + 1);        
         newInst.setValue(i, newVal);
       }
      
       newInst.setValue(inst.numAttributes() - 1, inst.value(inst.numAttributes() - 1));
      
       return newInst;
  }
View Full Code Here

   *
   * @param surfaceFormOccurrence surface form occurrence
   * @return WEKA instance
   */
  protected Instance buildInstance(SurfaceFormOccurrence surfaceFormOccurrence) {
    Instance instance = new DenseInstance(header.numAttributes());
    instance.setDataset(header);
    return instanceBuilder.buildInstance(surfaceFormOccurrence, instance);
  }
View Full Code Here

      m_attsToWeightOn[m_yAttribute] = true;
     
      // generate samples
      m_weightingAttsValues = new double [m_attsToWeightOn.length];
      m_vals = new double[m_trainingData.numAttributes()];
      m_predInst = new DenseInstance(1.0, m_vals);
      m_predInst.setDataset(m_trainingData);

      System.err.println("Executing row number "+m_rowNumber);
      for (int j = 0; j < m_panelWidth; j++) {
  double [] preds = calculateRegionProbs(j, m_rowNumber);
View Full Code Here

TOP

Related Classes of weka.core.DenseInstance

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.