Skip to content

Commit

Permalink
Merge pull request imbs-hl#193 from imbs-hl/issue183
Browse files Browse the repository at this point in the history
Divide only once to average probability predictions by tree
  • Loading branch information
mnwright authored May 16, 2017
2 parents 46e2b28 + bb93767 commit e58b61f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ForestProbability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void ForestProbability::predictInternal() {
// For all samples average proportions of trees
for (size_t sample_idx = 0; sample_idx < num_prediction_samples; ++sample_idx) {

// For each sample compute proportions in each tree and average over trees
// For each sample compute proportions in each tree
for (size_t tree_idx = 0; tree_idx < num_trees; ++tree_idx) {
if (predict_all) {
std::vector<double> counts = ((TreeProbability*) trees[tree_idx])->getPrediction(sample_idx);
Expand All @@ -130,10 +130,16 @@ void ForestProbability::predictInternal() {
std::vector<double> counts = ((TreeProbability*) trees[tree_idx])->getPrediction(sample_idx);

for (size_t class_idx = 0; class_idx < counts.size(); ++class_idx) {
predictions[0][sample_idx][class_idx] += counts[class_idx] / num_trees;
predictions[0][sample_idx][class_idx] += counts[class_idx];
}
}
}

// Average over trees
if (!predict_all && prediction_type != TERMINALNODES) {
for (size_t class_idx = 0; class_idx < predictions[0][sample_idx].size(); ++class_idx) {
predictions[0][sample_idx][class_idx] /= num_trees;
}
}
}

Expand Down

0 comments on commit e58b61f

Please sign in to comment.