29 #ifdef MHF_MEASURE_TIME 34 #define DEBUG_INFO(_msg, ...) 43 tree_height_(0), num_max_hyps_(num_max_hyps), max_min_prob_ratio_(max_min_prob_ratio) {
49 leafs_.push_back(empty_hyp);
64 DEBUG_INFO(
"HypothesesTree::processMeasurements\n");
66 if (ev_set.
size() == 0) {
70 #ifdef MHF_MEASURE_TIME 71 timespec t_start_total, t_end_total;
72 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_start_total);
96 DEBUG_INFO(
"*** Free memory: assignment matrices ***\n");
100 #ifdef MHF_MEASURE_TIME 101 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_end_total);
102 printf(
"Total update took %f seconds.\n", (t_end_total.tv_sec - t_start_total.tv_sec) +
double(t_end_total.tv_nsec - t_start_total.tv_nsec) / 1e9);
105 DEBUG_INFO(
"HypothesesTree::processMeasurements - end\n");
123 DEBUG_INFO(
" materializing hyp %p, with parent %p\n", (*it), (*it)->getParent());
124 (*it)->applyAssignments();
136 std::list<Assignment*> new_assignments;
137 std::list<Assignment*> clutter_assignments;
146 #ifdef MHF_MEASURE_TIME 147 timespec t_start, t_end;
148 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_start);
153 std::priority_queue<AssignmentSet*, std::vector<AssignmentSet*>,
compareAssignmentSets > assignment_sets;
155 DEBUG_INFO(
" - Create assignment matrices and assignment sets\n");
177 assignment_sets.push(ass_set);
186 (*it_hyp)->setInactive();
191 int n_iterations = 0;
194 while(!assignment_sets.empty() &&
leafs_.size() <
num_max_hyps_ && assignment_sets.top()->getProbability() > min_prob) {
199 DEBUG_INFO(
" #assignment sets = %i\n", (
int)assignment_sets.size());
202 DEBUG_INFO(
" inspecting assignment set %p with probability %.16f\n", ass_set, ass_set->getProbability());
205 assignment_sets.pop();
208 if (ass_set->isValid()) {
231 leafs_.push_back(hyp_child);
232 DEBUG_INFO(
" #leafs = %i, #old leafs = %i\n", (
int)
leafs_.size(), n_old_leafs);
237 std::list<AssignmentSet*> child_assignment_sets;
238 ass_set->expand(child_assignment_sets);
240 assignment_sets.push(*it_child);
245 DEBUG_INFO(
" - Free memory (remaining assignment sets)\n");
247 assert(
leafs_.size() > 0);
250 while(!assignment_sets.empty()) {
251 delete assignment_sets.top();
252 assignment_sets.pop();
261 #ifdef MHF_MEASURE_TIME 262 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_end);
263 printf(
"Expansion of hypotheses took %f seconds.\n", (t_end.tv_sec - t_start.tv_sec) +
double(t_end.tv_nsec - t_start.tv_nsec) / 1e9);
273 p_total += (*it_hyp)->getProbability();
278 (*it_hyp)->setProbability((*it_hyp)->getProbability() / p_total);
294 DEBUG_INFO(
" - determine best leaf per branch\n");
298 double prob_ratios[] = {1e-8, 1e-7, 1e-6, 1e-5, 1e-5, 1e-4, 1};
300 std::list<Hypothesis*> hyp_stack;
301 hyp_stack.push_back(
root_);
303 while(!hyp_stack.empty()) {
305 hyp_stack.pop_front();
308 if (!children.empty()) {
313 if ((*it_child)->getProbability() > best_child->
getProbability()) {
314 best_child = *it_child;
319 double prob_ratio = 0;
324 prob_ratio = prob_ratios[hyp->
getHeight()];
330 bool prune_child =
false;
332 if (*it_child != best_child) {
333 if ((*it_child)->getProbability() == 0) {
337 double similarity = 1;
342 prune_child = (similarity > 0.5);
343 }
else if ((*it_child)->getProbability() < min_prob) {
350 (*it_child)->deleteChildren();
352 it_child = children.erase(it_child);
354 hyp_stack.push_front(*it_child);
401 std::cout <<
" Number of hypotheses = " <<
leafs_.size() << std::endl;
403 std::cout <<
" Tree height = " <<
tree_height_ << std::endl;
AssignmentMatrix * getAssignmentMatrix() const
Hypothesis * determineBestLeaf()
HypothesisTree(int num_max_hyps, double max_min_prob_ratio)
bool operator()(const AssignmentSet *a1, const AssignmentSet *a2) const
static ObjectStorage & getInstance()
std::list< Hypothesis * > leafs_
const Hypothesis * getBestLeaf() const
double getProbability() const
Hypothesis * MAP_hypothesis_
std::vector< Evidence * >::const_iterator end() const
std::vector< Evidence * >::const_iterator begin() const
double max_min_prob_ratio_
virtual ~HypothesisTree()
double getProbability() const
void setAssignments(AssignmentSet *assignments)
static KnowledgeDatabase & getInstance()
iterator(field< oT > &in_M, const bool at_end=false)
void addEvidence(const EvidenceSet &ev_set)
const Hypothesis & getMAPHypothesis() const
std::vector< Evidence * >::const_iterator const_iterator
void expandTree(const EvidenceSet &ev_set)
unsigned int size() const
Returns the number of evidence items in the set.
A set of Evidence items which all originate from the same point int time.
const Time & getTimestamp() const
Returns the time from which all evidence in the set originates.
const_iterator(const field< oT > &in_M, const bool at_end=false)
void normalizeProbabilities()
void match(const Evidence &ev)
#define DEBUG_INFO(_msg,...)
double calculateBranchProbabilities()
unsigned int num_max_hyps_
void findActiveLeafs(std::list< Hypothesis * > &active_leafs)
const std::list< SemanticObject * > & getMAPObjects() const
Hypothesis * deleteSinglePaths()
std::list< Hypothesis * > & getChildHypotheses()
void addPotentialAssignment(Assignment *assignment)
const std::list< SemanticObject * > & getObjects() const
void addChildHypothesis(Hypothesis *h)
const std::list< Hypothesis * > & getHypotheses() const
void pruneTree(const Time ×tamp)