36 BowVector::iterator vit = this->lower_bound(
id);
38 if(vit != this->end() && !(this->key_comp()(
id, vit->first)))
44 this->insert(vit, BowVector::value_type(
id, v));
52 BowVector::iterator vit = this->lower_bound(
id);
54 if(vit == this->end() || (this->key_comp()(
id, vit->first)))
56 this->insert(vit, BowVector::value_type(
id, v));
65 BowVector::iterator it;
69 for(it = begin(); it != end(); ++it)
70 norm += fabs(it->second);
74 for(it = begin(); it != end(); ++it)
75 norm += it->second * it->second;
81 for(it = begin(); it != end(); ++it)
90 BowVector::const_iterator vit;
91 std::vector<unsigned int>::const_iterator iit;
93 const unsigned int N = v.size();
94 for(vit = v.begin(); vit != v.end(); ++vit, ++i)
96 out <<
"<" << vit->first <<
", " << vit->second <<
">";
98 if(i < N-1) out <<
", ";
107 std::fstream
f(filename.c_str(), std::ios::out);
110 BowVector::const_iterator bit;
111 for(bit = this->begin(); bit != this->end(); ++bit)
113 for(; last < bit->first; ++last)
117 f << bit->second <<
" ";
119 last = bit->first + 1;
121 for(; last < (
WordId)W; ++last)
void addWeight(WordId id, WordValue v)
void saveM(const std::string &filename, size_t W) const
friend std::ostream & operator<<(std::ostream &out, const BowVector &v)
void normalize(LNorm norm_type)
LNorm
L-norms for normalization.
Vector of words to represent images.
double WordValue
Value of a word.
unsigned int WordId
Id of words.
void addIfNotExist(WordId id, WordValue v)