MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RandomSample

Method RandomSample

tensorflow/contrib/tensor_forest/kernels/v4/input_data.cc:121–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121void TensorDataSet::RandomSample(int example,
122 decision_trees::FeatureId* feature_id,
123 float* bias, int* type) const {
124 int32 num_total_features = input_spec_.dense_features_size();
125 int64 sparse_input_start;
126 if (sparse_indices_ != nullptr) {
127 const int32 num_sparse = tensorforest::GetNumSparseFeatures(
128 *sparse_indices_, example, &sparse_input_start);
129 if (sparse_input_start >= 0) {
130 num_total_features += num_sparse;
131 }
132 }
133 int rand_feature = 0;
134 {
135 mutex_lock lock(mu_);
136 rand_feature = rng_->Uniform(num_total_features);
137 }
138 if (rand_feature < available_features_.size()) { // it's dense.
139 *feature_id = available_features_[rand_feature];
140 *type = input_spec_.GetDenseFeatureType(rand_feature);
141 } else {
142 const int32 sparse_index =
143 sparse_input_start + rand_feature - input_spec_.dense_features_size();
144 const int32 saved_index =
145 (*sparse_indices_)(sparse_index, 1) + input_spec_.dense_features_size();
146 *feature_id = decision_trees::FeatureId();
147 feature_id->mutable_id()->set_value(strings::StrCat(saved_index));
148
149 // TODO(gilberth): Remove this shortcut when different sparse types are
150 // allowed.
151 *type = input_spec_.sparse(0).original_type();
152 }
153
154 *bias = GetExampleValue(example, *feature_id);
155}
156
157} // namespace tensorforest
158} // namespace tensorflow

Calls 8

GetNumSparseFeaturesFunction · 0.85
dense_features_sizeMethod · 0.80
UniformMethod · 0.80
GetDenseFeatureTypeMethod · 0.80
original_typeMethod · 0.80
sparseMethod · 0.80
StrCatFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected