예제 #1
0
void MiraFeatureVector::InitSparse(const SparseVector& sparse, size_t ignoreLimit)
{
  vector<size_t> sparseFeats = sparse.feats();
  bool bFirst = true;
  size_t lastFeat = 0;
  m_sparseFeats.reserve(sparseFeats.size());
  m_sparseVals.reserve(sparseFeats.size());
  for(size_t i=0; i<sparseFeats.size(); i++) {
    if (sparseFeats[i] < ignoreLimit) continue;
    size_t feat = m_dense.size() + sparseFeats[i];
    m_sparseFeats.push_back(feat);
    m_sparseVals.push_back(sparse.get(sparseFeats[i]));

    // Check ordered property
    if(bFirst) {
      bFirst = false;
    } else {
      if(lastFeat>=feat) {
        cerr << "Error: Feature indeces must be strictly ascending coming out of SparseVector" << endl;
        exit(1);
      }
    }
    lastFeat = feat;
  }
}
예제 #2
0
MiraFeatureVector::MiraFeatureVector(const SparseVector& sparse, size_t num_dense)
{
  m_dense.resize(num_dense);
  //Assume that features with id [0,num_dense) are the dense features
  for (size_t id = 0; id < num_dense; ++id) {
    m_dense[id] = sparse.get(id);
  }
  InitSparse(sparse,num_dense);
}