<commit_before>#pragma once

#include <vector>
#include <algorithm>
#include <tuple>

namespace ssmpack {
namespace filter {

template <class TFilter>
class RecursiveBayesianBase {
  public:
  template <class TMeasurement, class... TArgs>
  decltype(auto) step(const TMeasurement &measurement, const TArgs &... args) {
    static_cast<TFilter *>(this)->predict();
    return static_cast<TFilter *>(this)->correct(measurement);
  }

  template <class TMeasurement, class TControl = std::tuple<>>
  decltype(auto)
  filter(const std::vector<TMeasurement> &measurements,
         const std::vector<TControl> &controls = std::vector<std::tuple<>>()) {

    using TState = decltype(step(measurements.at(0)));
    std::vector<TState> state_seq(measurements.size() + 1);
    state_seq[0] = static_cast<TFilter *>(this)->initialize();
    auto pm = measurements.cbegin();

    if (controls.size() == 0) {
      std::generate_n(state_seq.begin() + 1, state_seq.size(),
                      [this, &pm]() { return step(*(pm++)); });
    } else {
      // else what?
    }

    return state_seq;

  }

};

} // namespace filter
} // namespace ssmpack
<commit_msg>resolving out of range issue<commit_after>#pragma once

#include <vector>
#include <algorithm>
#include <tuple>

namespace ssmpack {
namespace filter {

template <class TFilter>
class RecursiveBayesianBase {
  public:
  template <class TMeasurement, class... TArgs>
  decltype(auto) step(const TMeasurement &measurement, const TArgs &... args) {
    static_cast<TFilter *>(this)->predict();
    return static_cast<TFilter *>(this)->correct(measurement);
  }

  template <class TMeasurement, class TControl = std::tuple<>>
  decltype(auto)
  filter(const std::vector<TMeasurement> &measurements,
         const std::vector<TControl> &controls = std::vector<std::tuple<>>()) {

    using TState = decltype(step(measurements.at(0)));
    std::vector<TState> state_seq(measurements.size() + 1);
    state_seq[0] = static_cast<TFilter *>(this)->initialize();
    auto pm = measurements.cbegin();

    if (controls.size() == 0) {
      std::generate_n(state_seq.begin() + 1, state_seq.size()-1,
                      [this, &pm]() { return step(*(pm++)); });
    } else {
      // else what?
    }

    return state_seq;

  }

};

} // namespace filter
} // namespace ssmpack

{'fraction_non_alphanumeric': 0.15884631941455016, 'fraction_numerical': 0.004735256134309083, 'mean_word_length': 3.8215767634854774, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5992717', 'n_tokens_mistral': 759, 'n_tokens_neox': 740, 'n_words': 164}