Package weka.core

Examples of weka.core.DenseInstance


    }
    Instance inst = null;
    if (instance instanceof SparseInstance) {
      inst = new SparseInstance(instance.weight(), vals);
    } else {
      inst = new DenseInstance(instance.weight(), vals);
    }
    inst.setDataset(getOutputFormat());
    copyValues(inst, false, instance.dataset(), getOutputFormat());
    inst.setDataset(getOutputFormat());
    push(inst);
View Full Code Here


    System.arraycopy(tempvals, 0, instanceVals, 0, tempvals.length);
    if (instance.classIndex() >= 0) {
      instanceVals[instanceVals.length - 1] = instance.classValue();
    }
   
    push(new DenseInstance(instance.weight(), instanceVals));
  }
View Full Code Here

  k[j] = v;
      }
      k[k.length - 1] = classes[i];

      // create new instance
      Instance in = new DenseInstance(1.0, k);
      result.add(in);   
    }

    if (!isFirstBatchDone())
      setOutputFormat(result);
View Full Code Here

      if (clusterAssignments[i] < 0) {
        values[j] = Utils.missingValue();
      } else {
        values[j] = clusterAssignments[i];
      }
      m_PlotInstances.add(new DenseInstance(1.0, values));
      if (m_PlotShapes != null) {
        if (clusterAssignments[i] >= 0) {
          if ((int) m_Instances.instance(i).classValue() != classAssignments[(int) clusterAssignments[i]])
            m_PlotShapes[i] = Plot2D.ERROR_SHAPE;
        } else {
View Full Code Here

  continue;
      data = new double[row.size()];
      for (n = 0; n < row.size(); n++)
  data[n] = row.get(n);
     
      result.add(new DenseInstance(1.0, data));
    }

    // close the stream
    try {
      m_sourceReader.close();
View Full Code Here

      }
    }
    for(int j=0, numInsts=instList.length; j<attrVals.length; j++) {
      attrVals[j] /= numInsts;
    }
    temp = new DenseInstance(1.0, attrVals);
    return temp;
  }
View Full Code Here

    }
    for(int j=0, numInsts=end-start+1; j<attrVals.length; j++) {
      attrVals[j] /= numInsts;
    }
   
    temp = new DenseInstance(1.0, attrVals);   
    return temp;
  }
View Full Code Here

      attrVals[j] += p1.value(j);
      attrVals[j] += p2.value(j);
      attrVals[j] /= 2D;
    }
   
    p1 = new DenseInstance(1.0, attrVals);
    return p1;
  }
View Full Code Here

    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
   
View Full Code Here

          double[] vals = new double[newInsts.numAttributes()];
          for (int j = 0; j < predictedI.numAttributes(); j++) {
            vals[j] = predictedI.instance(i).value(j);
          }
          vals[vals.length - 1] = 2; // default shape size
          Instance ni = new DenseInstance(1.0, vals);
          newInsts.add(ni);
        }
       
        // predicted class attribute is always actualClassIndex - 1
        Instances[] classes = new Instances[newInsts.numClasses()];
        for (int i = 0; i < newInsts.numClasses(); i++) {
          classes[i] = new Instances(newInsts, 0);
          classes[i].setRelationName(newInsts.classAttribute().value(i));
        }
        Instances errors = new Instances(newInsts, 0);
        int actualClass = newInsts.classIndex();
        for (int i = 0; i < newInsts.numInstances(); i++) {
          Instance current = newInsts.instance(i);
          classes[(int)current.classValue()].add((Instance)current.copy());
         
          if (current.value(actualClass) != current.value(actualClass - 1)) {
            Instance toAdd = (Instance)current.copy();
           
            // larger shape for an error
            toAdd.setValue(toAdd.numAttributes() - 1, 5);
           
            // swap predicted and actual class value so
            // that the color plotted for the error series
            // is that of the predicted class
            double actualClassV = toAdd.value(actualClass);
            double predictedClassV = toAdd.value(actualClass - 1);
            toAdd.setValue(actualClass, predictedClassV);
            toAdd.setValue(actualClass - 1, actualClassV);
             
            errors.add(toAdd);           
          }
        }
       
        errors.setRelationName("Errors");
        m_offscreenPlotData.add(errors);
       
        for (int i = 0; i < classes.length; i++) {
          m_offscreenPlotData.add(classes[i]);
        }
 
      } else {
        // numeric class - have to make a new set of instances
        // with the point sizes added as an additional attribute
        FastVector atts = new FastVector();
        for (int i = 0; i < predictedI.numAttributes(); i++) {
          atts.add(predictedI.attribute(i).copy());
        }
        atts.add(new Attribute("@@size@@"));
        Instances newInsts = new Instances(predictedI.relationName(),
            atts, predictedI.numInstances());

        int[] shapeSizes = e.getDataSet().getShapeSize();

        for (int i = 0; i < predictedI.numInstances(); i++) {
          double[] vals = new double[newInsts.numAttributes()];
          for (int j = 0; j < predictedI.numAttributes(); j++) {
            vals[j] = predictedI.instance(i).value(j);
          }
          vals[vals.length - 1] = shapeSizes[i];
          Instance ni = new DenseInstance(1.0, vals);
          newInsts.add(ni);
        }
        newInsts.setRelationName(predictedI.classAttribute().name());
        m_offscreenPlotData.add(newInsts);
      }
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.