本文整理汇总了C++中common::sfv_t类的典型用法代码示例。如果您正苦于以下问题:C++ sfv_t类的具体用法?C++ sfv_t怎么用?C++ sfv_t使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfv_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: similar_row
void recommender_base::complete_row(const common::sfv_t& query,
common::sfv_t& ret) const {
ret.clear();
vector<pair<string, float> > ids;
similar_row(query, ids, complete_row_similar_num_);
if (ids.size() == 0) {
return;
}
size_t exist_row_num = 0;
for (size_t i = 0; i < ids.size(); ++i) {
common::sfv_t row;
orig_.get_row(ids[i].first, row);
if (row.size() == 0) {
continue;
} else {
++exist_row_num;
}
float ratio = ids[i].second;
for (size_t j = 0; j < row.size(); ++j) {
ret.push_back(make_pair(row[j].first, row[j].second * ratio));
}
}
if (exist_row_num == 0) {
return;
}
common::sort_and_merge(ret);
for (size_t i = 0; i < ret.size(); ++i) {
ret[i].second /= exist_row_num;
}
}
示例2: ret
eigen_svec_t eigen_feature_mapper::convertc(const common::sfv_t& src) const {
eigen_svec_t ret(d_);
for (common::sfv_t::const_iterator it = src.begin(); it != src.end(); ++it) {
insertc(*it, ret);
}
return ret;
}
示例3: lk
void confidence_weighted::update(
const common::sfv_t& sfv,
float step_width,
const string& pos_label,
const string& neg_label) {
util::concurrent::scoped_wlock lk(storage_->get_lock());
for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
const string& feature = it->first;
float val = it->second;
storage::feature_val2_t val2;
storage_->get2_nolock(feature, val2);
storage::val2_t pos_val(0.f, 1.f);
storage::val2_t neg_val(0.f, 1.f);
ClassifierUtil::get_two(val2, pos_label, neg_label, pos_val, neg_val);
const float C = config_.regularization_weight;
float covar_pos_step = 2.f * step_width * val * val * C;
float covar_neg_step = 2.f * step_width * val * val * C;
storage_->set2_nolock(
feature,
pos_label,
storage::val2_t(pos_val.v1 + step_width * pos_val.v2 * val,
1.f / (1.f / pos_val.v2 + covar_pos_step)));
if (neg_label != "") {
storage_->set2_nolock(
feature,
neg_label,
storage::val2_t(neg_val.v1 - step_width * neg_val.v2 * val,
1.f / (1.f / neg_val.v2 + covar_neg_step)));
}
}
touch(pos_label);
}
示例4: scalar_dot
common::sfv_t scalar_dot(const common::sfv_t& p, double s) {
common::sfv_t ret;
for (common::sfv_t::const_iterator it = p.begin(); it != p.end(); ++it) {
ret.push_back(make_pair((*it).first, (*it).second*s));
}
return ret;
}
示例5: sum2
double sum2(const common::sfv_t& p) {
double s = 0;
for (common::sfv_t::const_iterator it = p.begin(); it != p.end(); ++it) {
s += std::pow((*it).second, 2);
}
return s;
}
示例6: ret_id
void local_storage::inp(const common::sfv_t& sfv, map_feature_val1_t& ret)
const {
ret.clear();
std::vector<float> ret_id(class2id_.size());
for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
const string& feature = it->first;
const float val = it->second;
id_features3_t::const_iterator it2 = tbl_.find(feature);
if (it2 == tbl_.end()) {
continue;
}
const id_feature_val3_t& m = it2->second;
for (id_feature_val3_t::const_iterator it3 = m.begin(); it3 != m.end();
++it3) {
ret_id[it3->first] += it3->second.v1 * val;
}
}
for (size_t i = 0; i < ret_id.size(); ++i) {
if (ret_id[i] == 0.f) {
continue;
}
ret[class2id_.get_key(i)] = ret_id[i];
}
}
示例7: get_storage
void arow::update(
const common::sfv_t& sfv,
float alpha,
float beta,
const std::string& pos_label,
const std::string& neg_label) {
storage::storage_base* sto = get_storage();
for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
const string& feature = it->first;
float val = it->second;
storage::feature_val2_t ret;
sto->get2(feature, ret);
storage::val2_t pos_val(0.f, 1.f);
storage::val2_t neg_val(0.f, 1.f);
ClassifierUtil::get_two(ret, pos_label, neg_label, pos_val, neg_val);
sto->set2(
feature,
pos_label,
storage::val2_t(
pos_val.v1 + alpha * pos_val.v2 * val,
pos_val.v2 - beta * pos_val.v2 * pos_val.v2 * val * val));
if (neg_label != "") {
sto->set2(
feature,
neg_label,
storage::val2_t(
neg_val.v1 - alpha * neg_val.v2 * val,
neg_val.v2 - beta * neg_val.v2 * neg_val.v2 * val * val));
}
}
}
示例8: lk
void local_storage::inp(const common::sfv_t& sfv, map_feature_val1_t& ret)
const {
ret.clear();
scoped_rlock lk(mutex_);
// Use uin64_t map instead of string map as hash function for string is slow
jubatus::util::data::unordered_map<uint64_t, double> ret_id;
for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
const string& feature = it->first;
const double val = it->second;
id_features3_t::const_iterator it2 = tbl_.find(feature);
if (it2 == tbl_.end()) {
continue;
}
const id_feature_val3_t& m = it2->second;
for (id_feature_val3_t::const_iterator it3 = m.begin(); it3 != m.end();
++it3) {
ret_id[it3->first] += it3->second.v1 * val;
}
}
std::vector<std::string> labels = class2id_.get_all_id2key();
for (size_t i = 0; i < labels.size(); ++i) {
const std::string& label = labels[i];
uint64_t id = class2id_.get_id_const(label);
if (id == common::key_manager::NOTFOUND || ret_id.count(id) == 0) {
ret[label] = 0.0;
} else {
ret[label] = ret_id[id];
}
}
}
示例9: inp
void storage_base::inp(const common::sfv_t& sfv, map_feature_val1_t& ret)
const {
ret.clear();
for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
const string& feature = it->first;
const float val = it->second;
feature_val1_t fval1;
get(feature, fval1);
for (feature_val1_t::const_iterator it2 = fval1.begin(); it2 != fval1.end();
++it2) {
ret[it2->first] += it2->second * val;
}
}
}
示例10: complete_row
void recommender_base::complete_row(const std::string& id,
common::sfv_t& ret) const {
ret.clear();
common::sfv_t sfv;
orig_.get_row(id, sfv);
complete_row(sfv, ret);
}
示例11: sqrt
float recommender_base::calc_l2norm(const common::sfv_t& query) {
float ret = 0.f;
for (size_t i = 0; i < query.size(); ++i) {
ret += query[i].second * query[i].second;
}
return sqrt(ret);
}
示例12: sqrt
float inverted_index_storage::calc_l2norm(const common::sfv_t& sfv) {
float ret = 0.f;
for (size_t i = 0; i < sfv.size(); ++i) {
ret += sfv[i].second * sfv[i].second;
}
return std::sqrt(ret);
}
示例13: calc_scores
void inverted_index_storage::calc_scores(
const common::sfv_t& query,
vector<pair<string, float> >& scores,
size_t ret_num) const {
float query_norm = calc_l2norm(query);
if (query_norm == 0.f) {
return;
}
jubatus::util::data::unordered_map<uint64_t, float> i_scores;
for (size_t i = 0; i < query.size(); ++i) {
const string& fid = query[i].first;
float val = query[i].second;
add_inp_scores(fid, val, i_scores);
}
vector<pair<float, uint64_t> > sorted_scores;
for (jubatus::util::data::unordered_map<uint64_t, float>::
const_iterator it = i_scores.begin(); it != i_scores.end(); ++it) {
float norm = calc_columnl2norm(it->first);
float normed_score = (norm != 0.f) ? it->second / norm / query_norm : 0.f;
sorted_scores.push_back(make_pair(normed_score, it->first));
}
sort(sorted_scores.rbegin(), sorted_scores.rend());
for (size_t i = 0; i < sorted_scores.size() && i < ret_num; ++i) {
scores.push_back(
make_pair(column2id_.get_key(sorted_scores[i].second),
sorted_scores[i].first));
}
}
示例14: add_feature
void add_feature(const std::string& key,
double value,
common::sfv_t& ret_fv) const {
std::stringstream ss;
ss << key << "$" << value;
ret_fv.push_back(std::make_pair(ss.str(), static_cast<float>(1.0)));
}
示例15: squared_norm
float classifier_base::squared_norm(const common::sfv_t& fv) {
float ret = 0.f;
for (size_t i = 0; i < fv.size(); ++i) {
ret += fv[i].second * fv[i].second;
}
return ret;
}