burst_result::burst_result( const input_window& input, double scaling_param, double gamma, double costcut_threshold, const burst_result& prev_result, int max_reuse_batches) { const std::vector<batch_input>& input_batches = input.get_batches(); const size_t n = input.get_batch_size(); const int max_reuse = (std::min)(max_reuse_batches, static_cast<int>(n)); // make vectors for engine std::vector<uint32_t> d_vec, r_vec; std::vector<double> burst_weights; d_vec.reserve(n); r_vec.reserve(n); burst_weights.reserve(n); for (size_t i = 0; i < n; ++i) { d_vec.push_back(input_batches[i].d); r_vec.push_back(input_batches[i].r); burst_weights.push_back(-1); // uncalculated } // reuse batch weights if (prev_result.p_) { const result_window& prev = *prev_result.p_; if (prev.get_start_pos() <= input.get_start_pos()) { const std::pair<int, int> intersection = get_intersection(prev, input); const std::vector<batch_result>& prev_results = prev.get_batches(); for (int i = 0, j = intersection.first; i < max_reuse && j < intersection.second; ++i, ++j) { burst_weights[i] = prev_results[j].burst_weight; } } } // doit burst::burst_detect(d_vec, r_vec, burst_weights, scaling_param, gamma, costcut_threshold); // store result p_.reset(new result_window(input, burst_weights)); }
input_window make_new_window_(double pos, const input_window& prev) const { double prev_start_pos = prev.get_start_pos(); int i = static_cast<int>( std::floor((pos - prev_start_pos) / batch_interval_)); int j = i - window_batch_size_/2; double new_start_pos = prev_start_pos + batch_interval_ * j; input_window new_window( new_start_pos, batch_interval_, window_batch_size_); // fill new_window's d&r vector std::pair<int, int> intersection = get_intersection(prev, new_window); for (int i = 0, j = intersection.first; j < intersection.second; ++i, ++j) { JUBATUS_ASSERT_LT(i, window_batch_size_, ""); new_window.get_batch_by_index(i) = prev.get_batch_by_index(j); } return new_window; // NRVO }