1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/dom_distiller/core/distillable_page_detector.h"
7 #include "base/logging.h"
9 namespace dom_distiller
{
11 DistillablePageDetector::DistillablePageDetector(
12 scoped_ptr
<AdaBoostProto
> proto
)
13 : proto_(proto
.Pass()), threshold_(0.0) {
14 CHECK(proto_
->num_stumps() == proto_
->stump_size());
15 for (int i
= 0; i
< proto_
->num_stumps(); ++i
) {
16 const StumpProto
& stump
= proto_
->stump(i
);
17 CHECK(stump
.feature_number() >= 0);
18 CHECK(stump
.feature_number() < proto_
->num_features());
19 threshold_
+= stump
.weight() / 2.0;
23 DistillablePageDetector::~DistillablePageDetector() {
26 bool DistillablePageDetector::Classify(
27 const std::vector
<double>& features
) const {
28 return Score(features
) > threshold_
;
31 double DistillablePageDetector::Score(
32 const std::vector
<double>& features
) const {
33 CHECK(features
.size() == size_t(proto_
->num_features()));
35 for (int i
= 0; i
< proto_
->num_stumps(); ++i
) {
36 const StumpProto
& stump
= proto_
->stump(i
);
37 if (features
[stump
.feature_number()] > stump
.split()) {
38 score
+= stump
.weight();
44 double DistillablePageDetector::GetThreshold() const {
48 } // namespace dom_distiller