Examples of SparseInstance


Examples of weka.core.SparseInstance

          return;
        }
       
        if((m_classIndex >= 0) &&
        (m_data.attribute(m_classIndex).isNominal())) {
          SparseInstance histClassCounts[];
          histClassCounts = new SparseInstance[m_data.attribute(m_attribIndex).numValues()];
          /*int histClassCounts[][];
          histClassCounts=new int[m_data.attribute(m_attribIndex).numValues()]
                                 [m_data.attribute(m_classIndex).numValues()+1]; */
         
          if (m_as.nominalCounts.length > 0) {
            m_maxValue = m_as.nominalCounts[0];
            for(int i=0; i<m_data.attribute(m_attribIndex).numValues(); i++) {
              if(m_as.nominalCounts[i]>m_maxValue)
          m_maxValue = m_as.nominalCounts[i];
            }
          }
          else {
            m_maxValue = 0;
          }
         
          if(m_colorList.size()==0)
            m_colorList.addElement(Color.black);
          for(int i=m_colorList.size();
          i < m_data.attribute(m_classIndex).numValues()+1; i++) {
            Color pc = m_defaultColors[(i-1) % 10];
            int ija =  (i-1) / 10;
            ija *= 2;
           
            for (int j=0;j<ija;j++) {
              pc = pc.darker();
            }
           
            m_colorList.addElement(pc);
          }
         
          // first sort data on attribute values
          m_data.sort(m_attribIndex);
          double[] tempClassCounts = null;
          int tempAttValueIndex = -1;
         
          for(int k=0; k<m_data.numInstances(); k++) {
            //System.out.println("attrib: "+
            //                   m_data.instance(k).value(m_attribIndex)+
            //                   " class: "+
            //                   m_data.instance(k).value(m_classIndex));
            if(!m_data.instance(k).isMissing(m_attribIndex)) {
              // check to see if we need to allocate some space here
              if (m_data.instance(k).value(m_attribIndex) != tempAttValueIndex) {
                if (tempClassCounts != null) {
                  // set up the sparse instance for the previous bar (if any)
                  int numNonZero = 0;
                  for (int z = 0; z < tempClassCounts.length; z++) {
                    if (tempClassCounts[z] > 0) {
                      numNonZero++;
                    }
                  }
                  double[] nonZeroVals = new double[numNonZero];
                  int[] nonZeroIndices = new int[numNonZero];
                  int count = 0;
                  for (int z = 0; z < tempClassCounts.length; z++) {
                    if (tempClassCounts[z] > 0) {
                      nonZeroVals[count] = tempClassCounts[z];
                      nonZeroIndices[count++] = z;
                    }
                  }
                  SparseInstance tempS =
                    new SparseInstance(1.0, nonZeroVals, nonZeroIndices, tempClassCounts.length);
                  histClassCounts[tempAttValueIndex] = tempS;
                }
               
                tempClassCounts = new double[m_data.attribute(m_classIndex).numValues() + 1];
                tempAttValueIndex = (int)m_data.instance(k).value(m_attribIndex);
               
                /* histClassCounts[(int)m_data.instance(k).value(m_attribIndex)] =
                  new double[m_data.attribute(m_classIndex).numValues()+1]; */
              }
              if(m_data.instance(k).isMissing(m_classIndex)) {
                /* histClassCounts[(int)m_data.instance(k).value(m_attribIndex)]
                               [0] += m_data.instance(k).weight(); */
                tempClassCounts[0] += m_data.instance(k).weight();
              } else {
                tempClassCounts[(int)m_data.instance(k).value(m_classIndex)+1]
                                += m_data.instance(k).weight();
               
                /*histClassCounts[(int)m_data.instance(k).value(m_attribIndex)]
                              [(int)m_data.instance(k).value(m_classIndex)+1] += m_data.instance(k).weight();*/
              }
            }
          }
         
          // set up sparse instance for last bar?
          if (tempClassCounts != null) {
            // set up the sparse instance for the previous bar (if any)
            int numNonZero = 0;
            for (int z = 0; z < tempClassCounts.length; z++) {
              if (tempClassCounts[z] > 0) {
                numNonZero++;
              }
            }
            double[] nonZeroVals = new double[numNonZero];
            int[] nonZeroIndices = new int[numNonZero];
            int count = 0;
            for (int z = 0; z < tempClassCounts.length; z++) {
              if (tempClassCounts[z] > 0) {
                nonZeroVals[count] = tempClassCounts[z];
                nonZeroIndices[count++] = z;
              }
            }
            SparseInstance tempS =
              new SparseInstance(1.0, nonZeroVals, nonZeroIndices, tempClassCounts.length);
            histClassCounts[tempAttValueIndex] = tempS;
          }
         
          /*for(int k=0; k<m_data.numInstances(); k++) {
            //System.out.println("attrib: "+
View Full Code Here

Examples of weka.core.SparseInstance

                sparseValues[count] = histClassCounts[i][j];
                sparseIndices[count++] = j;
              }
            }
           
            SparseInstance tempS =
              new SparseInstance(1.0, sparseValues, sparseIndices,
                  histClassCounts[i].length);
            histClassCountsSparse[i] = tempS;
           
          }
         
View Full Code Here

Examples of weka.core.SparseInstance

      int current = m_SelectedAttributes[i];
      vals[i] = instance.value(current);
    }
    Instance inst = null;
    if (instance instanceof SparseInstance)
      inst = new SparseInstance(instance.weight(), vals);
    else
      inst = new Instance(instance.weight(), vals);

    inst.setDataset(getOutputFormat());
    copyValues(inst, false, instance.dataset(), getOutputFormat());
View Full Code Here

Examples of weka.core.SparseInstance

      Double value = (Double)contained.get(index);
      values[i] = value.doubleValue();
      indices[i] = index.intValue();
    }

    Instance inst = new SparseInstance(instance.weight(), values, indices,
  outputFormatPeek().numAttributes());
    inst.setDataset(outputFormatPeek());

    v.addElement(inst);

    return firstCopy;   
  }
View Full Code Here

Examples of weka.core.SparseInstance

  break;
    }

    // create instance
    if (instance instanceof SparseInstance)
      result = new SparseInstance(instance.weight(), newVals);
    else
      result = new Instance(instance.weight(), newVals);
   
    return result;
  }
View Full Code Here

Examples of weka.core.SparseInstance

    m_attributeExpression.evaluateExpression(vals);

    Instance inst = null;
    if (instance instanceof SparseInstance) {
      inst = new SparseInstance(instance.weight(), vals);
    } else {
      inst = new Instance(instance.weight(), vals);
    }

    inst.setDataset(getOutputFormat());
View Full Code Here

Examples of weka.core.SparseInstance

  values[n] = result.attribute(n).indexOfValue(value);
      }
     
      // generate new instance
      if (inst instanceof SparseInstance)
  newInst = new SparseInstance(inst.weight(), values);
      else
  newInst = new Instance(inst.weight(), values);
     
      // copy possible string, relational values
      newInst.setDataset(getOutputFormat());
View Full Code Here

Examples of weka.core.SparseInstance

        newValues[m_outputNumAttributes - 1] = currentInstance.classValue();
      }
      //create new instance with recorded values and add to output dataset
      Instance newInstance;
      if (currentInstance instanceof SparseInstance) {
        newInstance = new SparseInstance(currentInstance.weight(), newValues);
      } else {
        newInstance = new Instance(currentInstance.weight(), newValues);
      }
      output.add(newInstance);
    }
View Full Code Here

Examples of weka.core.SparseInstance

      newValues[i] = instanceVector.get(0, i);
    }
   
    // return newly transformed instance
    if (instance instanceof SparseInstance) {
      return new SparseInstance(instance.weight(), newValues);
    } else {
      return new Instance(instance.weight(), newValues);
    }
  }
View Full Code Here

Examples of weka.core.SparseInstance

       }
      newVals[i] = tempval;
    }
   
    if (inst instanceof SparseInstance) {
      return new SparseInstance(inst.weight(), newVals);
    } else {
      return new Instance(inst.weight(), newVals);
    }     
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.