Package weka.core

Examples of weka.core.Instance


          break;
  default:
    vals[i - 1] = Utils.missingValue();
  }
      }
      Instance newInst;
      if (m_CreateSparseData) {
  newInst = new SparseInstance(1.0, vals);
      } else {
  newInst = new DenseInstance(1.0, vals);
      }
View Full Code Here


   */
  public void setValueAt(Object aValue, int rowIndex, int columnIndex, boolean notify) {
    int            type;
    int            index;
    String         tmp;
    Instance       inst;
    Attribute      att;
    Object         oldValue;
   
    if (!m_IgnoreChanges)
      addUndoPoint();
   
    oldValue = getValueAt(rowIndex, columnIndex);
    type     = getType(rowIndex, columnIndex);
    index    = columnIndex - 1;
    inst     = m_Data.instance(rowIndex);
    att      = inst.attribute(index);
   
    // missing?
    if (aValue == null) {
      inst.setValue(index, Utils.missingValue());
    }
    else {
      tmp = aValue.toString();
     
      switch (type) {
        case Attribute.DATE:
          try {
            att.parseDate(tmp);
            inst.setValue(index, att.parseDate(tmp));
          }
          catch (Exception e) {
            // ignore
          }
          break;
     
        case Attribute.NOMINAL:
          if (att.indexOfValue(tmp) > -1)
            inst.setValue(index, att.indexOfValue(tmp));
          break;
     
        case Attribute.STRING:
          inst.setValue(index, tmp);
          break;
     
        case Attribute.NUMERIC:
          try {
            Double.parseDouble(tmp);
            inst.setValue(index, Double.parseDouble(tmp));
          }
          catch (Exception e) {
            // ignore
          }
          break;
         
        case Attribute.RELATIONAL:
          try {
            inst.setValue(index, inst.attribute(index).addRelation((Instances) aValue));
          }
          catch (Exception e) {
            // ignore
          }
          break;
View Full Code Here

        // in accordance with what the embeded classifier was trained with
        Instances mappedClassifierDataset =
          ((weka.classifiers.misc.InputMappedClassifier)classifier).
          getModelHeader(new Instances(mappedClassifierHeader, 0));
        for (int zz = 0; zz < inst.numInstances(); zz++) {
          Instance mapped = ((weka.classifiers.misc.InputMappedClassifier)classifier).
          constructMappedInstance(inst.instance(zz));
          mappedClassifierDataset.add(mapped);
        }
       
        eval.setPriors(mappedClassifierDataset);
View Full Code Here

      m_visual.setAnimated();
      /*
      m_eval.evaluateModel(ce.getClassifier(),
      ce.getTestSet().getDataSet()); */
      for (int i = 0; i < ce.getTestSet().getDataSet().numInstances(); i++) {
        Instance temp = ce.getTestSet().getDataSet().instance(i);
        m_PlotInstances.process(temp, ce.getClassifier(), m_eval);
      }
     
      m_setsComplete++;
    }
View Full Code Here

   * @param inst  the JSON object to turn into an Instance
   * @param data  the data so far (only used for header information)
   * @return    the Instance, null in case of an error
   */
  protected static Instance toInstance(JSONNode inst, Instances data) {
    Instance  result;
    boolean  sparse;
    double  weight;
    JSONNode  values;
    int    i;
    int    index;
    int    pos;
    String  value;
    double[]  vals;

    sparse = (Boolean) inst.getChild(SPARSE).getValue(new Boolean(false));
    weight = (Double) inst.getChild(WEIGHT).getValue(new Double(1.0));
    values = inst.getChild(VALUES);
    vals   = new double[data.numAttributes()];
    for (i = 0; i < values.getChildCount(); i++) {
      if (sparse) {
  value = "" + ((JSONNode) values.getChildAt(i)).getValue();
  pos   = value.indexOf(SPARSE_SEPARATOR);
  index = Integer.parseInt(value.substring(0, pos));
  value = value.substring(pos + 1);
      }
      else {
  index = i;
  value = "" + ((JSONNode) values.getChildAt(i)).getValue();
      }
     
      try {
  if (data.attribute(index).isNumeric()) {
    vals[index] = Double.parseDouble(value);
  }
  else if (data.attribute(index).isNominal()) {
    vals[index] = data.attribute(index).indexOfValue(value);
    if ((vals[index] == -1) && value.startsWith("'") && value.endsWith("'"))
      vals[index] = data.attribute(index).indexOfValue(Utils.unquote(value));
    if (vals[index] == -1) {
      System.err.println("Unknown label '" + value + "' for attribute #" + (index+1) + "!");
      return null;
    }
  }
  else if (data.attribute(index).isDate()) {
    vals[index] = data.attribute(index).parseDate(value);
  }
  else if (data.attribute(index).isString()) {
    vals[index] = data.attribute(index).addStringValue(value);
  }
  else {
    System.err.println("Unhandled attribute type '" + Attribute.typeToString(data.attribute(index).type()) + "'!");
    return null;
  }
      }
      catch (Exception e) {
  System.err.println("Error parsing value #" + (index+1) + ": " + e.toString());
  return null;
      }
    }

    result = new DenseInstance(weight, vals);
    result.setDataset(data);
     
    return result;
  }
View Full Code Here

    JSONNode  header;
    JSONNode  attributes;
    JSONNode  data;
    ArrayList<Attribute>  atts;
    Attribute  att;
    Instance  inst;
    int    i;
    int    classIndex;
    boolean[]  classAtt;
   
    header = json.getChild(HEADER);
View Full Code Here

  }
      }
    }
    if (isNominal()) {
      if (m_Values.isInRange((int)instance.value(m_AttIndex.getIndex()))) {
  Instance temp = (Instance)instance.copy();
  if (getModifyHeader()) {
    temp.setValue(m_AttIndex.getIndex(),
      m_NominalMapping[(int)instance.value(m_AttIndex.getIndex())]);
  }
  push(temp);
  return true;
      }
View Full Code Here

  }

  if (instanceGeneration) {
          m_state = INCREMENTAL_LOADING;
    //    boolean start = true;
    Instance nextInstance = null;
    // load and pass on the structure first
    Instances structure = null;
    try {
            m_Loader.reset();
            //      System.err.println("NOTIFYING STRUCTURE AVAIL");
      structure = m_Loader.getStructure();
      notifyStructureAvailable(structure);
    } catch (IOException e) {
      if (m_log != null) {
        m_log.statusMessage(statusMessagePrefix()
            +"ERROR (See log for details");
        m_log.logMessage("[Loader] " + statusMessagePrefix()
            + " " + e.getMessage());
      }
      e.printStackTrace();
    }
    try {
      nextInstance = m_Loader.getNextInstance(structure);
    } catch (IOException e) {
      if (m_log != null) {
        m_log.statusMessage(statusMessagePrefix()
            +"ERROR (See log for details");
        m_log.logMessage("[Loader] " + statusMessagePrefix()
            + " " + e.getMessage());
      }
      e.printStackTrace();
    }
    int z = 0;
    while (nextInstance != null) {
      if (m_stopped) {
        break;
      }
      nextInstance.setDataset(structure);
      //      format.add(nextInstance);
      /*      InstanceEvent ie = (start)
        ? new InstanceEvent(m_DP, nextInstance,
          InstanceEvent.FORMAT_AVAILABLE)
    : new InstanceEvent(m_DP, nextInstance,
View Full Code Here

          break;
  default:
    vals[i - 1] = Utils.missingValue();
  }
      }
      Instance newInst;
      newInst = new DenseInstance(1.0, vals);
      instances.add(newInst);
    }  
   
    // Create the header and add the instances to the dataset
View Full Code Here

          break;
  default:
    vals[i - 1] = Utils.missingValue();
  }
      }
       Instance inst = new DenseInstance(1.0, vals);
       //get rid of m_idColumn
       if(m_DataBaseConnection.getUpperCase())
              m_idColumn = m_idColumn.toUpperCase();
       if(m_structure.attribute(0).name().equals(m_idColumn)){
            inst.deleteAttributeAt(0);
            m_oldStructure.add(inst);
            inst = m_oldStructure.instance(0);
            m_oldStructure.delete(0);
       }
       else{
View Full Code Here

TOP

Related Classes of weka.core.Instance

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.