本文整理汇总了C++中History::Action方法的典型用法代码示例。如果您正苦于以下问题:C++ History::Action方法的具体用法?C++ History::Action怎么用?C++ History::Action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类History
的用法示例。
在下文中一共展示了History::Action方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: log
vector<State*> Belief::Resample(int num, const vector<State*>& belief,
const DSPOMDP* model, History history, int hstart) {
double unit = 1.0 / num;
double mass = Random::RANDOM.NextDouble(0, unit);
int pos = 0;
double cur = belief[0]->weight;
double reward;
OBS_TYPE obs;
vector<State*> sample;
int count = 0;
double max_wgt = Globals::NEG_INFTY;
int trial = 0;
while (count < num && trial < 200 * num) {
// Pick next particle
while (mass > cur) {
pos++;
if (pos == belief.size())
pos = 0;
cur += belief[pos]->weight;
}
trial++;
mass += unit;
State* particle = model->Copy(belief[pos]);
// Step through history
double log_wgt = 0;
for (int i = hstart; i < history.Size(); i++) {
model->Step(*particle, Random::RANDOM.NextDouble(),
history.Action(i), reward, obs);
double prob = model->ObsProb(history.Observation(i), *particle,
history.Action(i));
if (prob > 0) {
log_wgt += log(prob);
} else {
model->Free(particle);
break;
}
}
// Add to sample if survived
if (particle->IsAllocated()) {
count++;
particle->weight = log_wgt;
sample.push_back(particle);
max_wgt = max(log_wgt, max_wgt);
}
// Remove particles with very small weights
if (count == num) {
for (int i = sample.size() - 1; i >= 0; i--)
if (sample[i]->weight - max_wgt < log(1.0 / num)) {
model->Free(sample[i]);
sample.erase(sample.begin() + i);
count--;
}
}
}
double total_weight = 0;
for (int i = 0; i < sample.size(); i++) {
sample[i]->weight = exp(sample[i]->weight - max_wgt);
total_weight += sample[i]->weight;
}
for (int i = 0; i < sample.size(); i++) {
sample[i]->weight = sample[i]->weight / total_weight;
}
logd << "[Belief::Resample] Resampled " << sample.size() << " particles"
<< endl;
for (int i = 0; i < sample.size(); i++) {
logv << " " << i << " = " << *sample[i] << endl;
}
return sample;
}