Package weka.core

Examples of weka.core.SparseInstance


  return null;
      }
    }

    if (sparse)
      result = new SparseInstance(weight, vals);
    else
      result = new DenseInstance(weight, vals);
    result.setDataset(data);
     
    return result;
View Full Code Here


          return;
        }
       
        if((m_classIndex >= 0) &&
        (m_data.attribute(m_classIndex).isNominal())) {
          SparseInstance histClassCounts[];
          histClassCounts = new SparseInstance[m_data.attribute(m_attribIndex).numValues()];
                                  //[m_data.attribute(m_classIndex).numValues()+1];
         
          if (m_as.nominalWeights.length > 0) {
            m_maxValue = m_as.nominalWeights[0];
            for(int i=0; i<m_data.attribute(m_attribIndex).numValues(); i++) {
              if(m_as.nominalWeights[i]>m_maxValue)
          m_maxValue = m_as.nominalWeights[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 i=0; i<histClassCounts.length; i++) {
          //int sum=0;
View Full Code Here

                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

      }
      newVals[i] += m_means[i];
    }
   
    if (inst instanceof SparseInstance) {
      return new SparseInstance(inst.weight(), newVals);
    } else {
      return new DenseInstance(inst.weight(), newVals);
    }     
  }
View Full Code Here

      }
    }
   
    if (!m_transBackToOriginal) {
      if (instance instanceof SparseInstance) {
      return new SparseInstance(instance.weight(), newVals);
      } else {
        return new DenseInstance(instance.weight(), newVals);
      }     
    } else {
      if (instance instanceof SparseInstance) {
        return convertInstanceToOriginal(new SparseInstance(instance.weight(),
                                                            newVals));
      } else {
        return convertInstanceToOriginal(new DenseInstance(instance.weight(),
                                                      newVals));
      }
View Full Code Here

      }
    }
   
    // create instance
    if (sparse)
      result = new SparseInstance(weight, values);
    else
      result = new DenseInstance(weight, values);
   
    return result;
  }
View Full Code Here

      }
    }
   
    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());
View Full Code Here

        vals[i] = dest.value(i);
      }
    }
    Instance inst = null;
    if (dest instanceof SparseInstance) {
      inst = new SparseInstance(dest.weight(), vals);
    } else {
      inst = new DenseInstance(dest.weight(), vals);
    }
    inst.setDataset(dest.dataset());
    return inst;
View Full Code Here

      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 DenseInstance(instance.weight(), vals);
    }
    inst.setDataset(getOutputFormat());
    copyValues(inst, false, instance.dataset(), getOutputFormat());
View Full Code Here

      }
      else {
  data = sparse;
      }
     
      result.add(new SparseInstance(1, data));
    }

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

TOP

Related Classes of weka.core.SparseInstance

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.