Examples of SparseInstance


Examples of weka.core.SparseInstance

      BagOfWordsData bagOfWordsData) throws IOException {
    for (Map.Entry<Integer, String> entry : bagOfWordsData
        .getDocumentClasses().entrySet()) {
      double[] zeroValues = new double[instances.numAttributes()];
      Arrays.fill(zeroValues, 0.0d);
      SparseInstance wekaInstance = new SparseInstance(1.0d, zeroValues);
      wekaInstance.setDataset(instances);
      // set instance id
      Attribute instanceId = instances.attribute(INSTANCE_ID);
      wekaInstance.setValue(instanceId.index(), entry.getKey()
          .doubleValue());
      // set document class
      Attribute classAttr = instances.attribute(CLASS);
      wekaInstance.setValue(classAttr.index(),
          classAttr.indexOfValue(entry.getValue()));
      // set numeric words
      if (bagOfWordsData.getInstanceNumericWords().get(entry.getKey()) != null) {
        for (Map.Entry<String, Double> word : bagOfWordsData
            .getInstanceNumericWords().get(entry.getKey())
            .entrySet()) {
          Attribute wordAttr = instances.attribute(word.getKey());
          wekaInstance.setValue(wordAttr.index(), word.getValue()
              .doubleValue());
        }
      }
      // set nominal words
      if (bagOfWordsData.getInstanceNominalWords().get(entry.getKey()) != null) {
        for (Map.Entry<String, String> word : bagOfWordsData
            .getInstanceNominalWords().get(entry.getKey())
            .entrySet()) {
          Attribute wordAttr = instances.attribute(word.getKey());
          int valueIndex = wordAttr.indexOfValue(word.getValue());
          if (valueIndex == -1) {
            throw new IOException("oops! " + word);
          }
          wekaInstance.setValue(wordAttr.index(), valueIndex);
        }
      }
      instances.add(wekaInstance);
    }
  }
View Full Code Here

Examples of weka.core.SparseInstance

  start++;
      }

      // create new instance
      if (oldInstance instanceof SparseInstance)
  newInstance = new SparseInstance(oldInstance.weight(), newValues);
      else
  newInstance = new Instance(oldInstance.weight(), newValues);

      // copy string/relational values from input to output
      copyValues(newInstance, false, oldInstance.dataset(), getOutputFormat());
View Full Code Here

Examples of weka.core.SparseInstance

  int current = m_SelectedAttributes[i];
  newVals[i] = instance.value(current);
      }
    }
    if (instance instanceof SparseInstance) {
      push(new SparseInstance(instance.weight(), newVals));
    } else {
      push(new Instance(instance.weight(), newVals));
    }
  }
View Full Code Here

Examples of weka.core.SparseInstance

      }
    }
   
    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

  }
      }
    }
    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

  attSoFar += att.numValues() - 1;
      }
    }
    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

    vals[i - 1] = Instance.missingValue();
  }
      }
      Instance newInst;
      if (m_CreateSparseData) {
  newInst = new SparseInstance(1.0, vals);
      } else {
  newInst = new Instance(1.0, vals);
      }
      instances.addElement(newInst);
      rowCount++;
View Full Code Here

Examples of weka.core.SparseInstance

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

Examples of weka.core.SparseInstance

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

Examples of weka.core.SparseInstance

      }
    }
   
    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
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.