Commit 9e2e55c0 authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

Update default host model features to be the unknown value.

This change sets the default value for host model features to be an value
that the prediction model can interpret as unknown (-1 in this case). This
will improve the model accuracy when host model features are unvailable
for the current navigation.

Bug: 1036025
Change-Id: Iff7dab042829a540c06854f9ea7e84e187dbc7ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1977189Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726627}
parent 03dfdf62
...@@ -335,7 +335,7 @@ base::flat_map<std::string, float> PredictionManager::BuildFeatureMap( ...@@ -335,7 +335,7 @@ base::flat_map<std::string, float> PredictionManager::BuildFeatureMap(
continue; continue;
} }
if (!host_model_features || !host_model_features->contains(model_feature)) { if (!host_model_features || !host_model_features->contains(model_feature)) {
feature_map[model_feature] = 0.0; feature_map[model_feature] = -1.0;
continue; continue;
} }
feature_map[model_feature] = feature_map[model_feature] =
......
...@@ -62,6 +62,8 @@ std::unique_ptr<proto::PredictionModel> CreatePredictionModel() { ...@@ -62,6 +62,8 @@ std::unique_ptr<proto::PredictionModel> CreatePredictionModel() {
model_info->set_version(1); model_info->set_version(1);
model_info->add_supported_model_features( model_info->add_supported_model_features(
proto::CLIENT_MODEL_FEATURE_EFFECTIVE_CONNECTION_TYPE); proto::CLIENT_MODEL_FEATURE_EFFECTIVE_CONNECTION_TYPE);
prediction_model->mutable_model_info()->add_supported_host_model_features(
"host_feat1");
model_info->set_optimization_target( model_info->set_optimization_target(
proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD); proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD);
model_info->add_supported_model_types( model_info->add_supported_model_types(
...@@ -91,6 +93,8 @@ std::unique_ptr<proto::GetModelsResponse> BuildGetModelsResponse( ...@@ -91,6 +93,8 @@ std::unique_ptr<proto::GetModelsResponse> BuildGetModelsResponse(
prediction_model->mutable_model_info()->add_supported_model_features( prediction_model->mutable_model_info()->add_supported_model_features(
client_model_feature); client_model_feature);
} }
prediction_model->mutable_model_info()->add_supported_host_model_features(
"host_feat1");
prediction_model->mutable_model_info()->set_version(2); prediction_model->mutable_model_info()->set_version(2);
*get_models_response->add_models() = *prediction_model.get(); *get_models_response->add_models() = *prediction_model.get();
...@@ -115,6 +119,8 @@ class TestPredictionModel : public PredictionModel { ...@@ -115,6 +119,8 @@ class TestPredictionModel : public PredictionModel {
} }
*prediction_score = 0.6; *prediction_score = 0.6;
model_evaluated_ = true; model_evaluated_ = true;
last_evaluated_features_ =
base::flat_map<std::string, float>(model_features);
return OptimizationTargetDecision::kPageLoadMatches; return OptimizationTargetDecision::kPageLoadMatches;
} }
...@@ -122,10 +128,15 @@ class TestPredictionModel : public PredictionModel { ...@@ -122,10 +128,15 @@ class TestPredictionModel : public PredictionModel {
void ResetModelEvaluationState() { model_evaluated_ = false; } void ResetModelEvaluationState() { model_evaluated_ = false; }
base::flat_map<std::string, float> last_evaluated_features() {
return last_evaluated_features_;
}
private: private:
bool ValidatePredictionModel() const override { return true; } bool ValidatePredictionModel() const override { return true; }
bool model_evaluated_ = false; bool model_evaluated_ = false;
base::flat_map<std::string, float> last_evaluated_features_;
}; };
// A mock class implementation of TopHostProvider. // A mock class implementation of TopHostProvider.
...@@ -1198,6 +1209,7 @@ TEST_F(PredictionManagerTest, NoHostModelFeaturesForHost) { ...@@ -1198,6 +1209,7 @@ TEST_F(PredictionManagerTest, NoHostModelFeaturesForHost) {
"OptimizationGuide.PredictionManager." "OptimizationGuide.PredictionManager."
"HasHostModelFeaturesForHost", "HasHostModelFeaturesForHost",
false, 1); false, 1);
EXPECT_LT(test_prediction_model->last_evaluated_features()["host_feat1"], 0);
EXPECT_FALSE(prediction_manager()->GetHostModelFeaturesForTesting().contains( EXPECT_FALSE(prediction_manager()->GetHostModelFeaturesForTesting().contains(
"bar.com")); "bar.com"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment