<commit_before>/*************************************************************************
This software allows for filtering in high-dimensional observation and
state spaces, as described in

<NAME>, <NAME>, <NAME>, <NAME>, and <NAME>.
Probabilistic Object Tracking using a Range Camera
IEEE/RSJ Intl Conf on Intelligent Robots and Systems, 2013

In a publication based on this software pleace cite the above reference.


Copyright (C) 2014  <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/

#ifndef FAST_FILTERING_UTILS_HELPER_FUNCTIONS_HPP
#define FAST_FILTERING_UTILS_HELPER_FUNCTIONS_HPP

#include <vector>
#include <algorithm>
#include <iostream>
#include <limits>
#include <Eigen/Dense>
#include <cmath>

#include <ctime>
#include <fstream>



#include <boost/lexical_cast.hpp>
#include <boost/random/lagged_fibonacci.hpp>

#include <fl/util/random_seed.hpp>



// TODO: THIS HAS TO BE CLEANED, POSSIBLY SPLIT INTO SEVERAL FILES

namespace fl
{

namespace hf
{


// use std::min_element & std::max_element instead. better API if split into two functions
template <typename T> int BoundIndex(const std::vector<T> &values, bool bound_type) // bound type 1 for max and 0 for min
{
	int BoundIndex = 0;
	T bound_value = bound_type ? -std::numeric_limits<T>::max() : std::numeric_limits<T>::max();

	for(int i = 0; i < int(values.size()); i++)
		if(bound_type ? (values[i] > bound_value) : (values[i] < bound_value) )
		{
			BoundIndex = i;
			bound_value = values[i];
		}

	return BoundIndex;
}

// use std::min_element & std::max_element instead
template <typename T> T bound_value(const std::vector<T> &values, bool bound_type) // bound type 1 for max and 0 for min
{
	return values[BoundIndex(values, bound_type)];
}

// use std::transform or for_each instead
template <typename Tin, typename Tout>
std::vector<Tout> Apply(const std::vector<Tin> &input, Tout(*f)(Tin))
{
	std::vector<Tout> output(input.size());
	for(size_t i = 0; i < output.size(); i++)
		output[i] = (*f)(input[i]);

	return output;
}

// sampling class >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class DiscreteDistribution
{
public:
    template <typename T> DiscreteDistribution(std::vector<T> log_prob)
    {
        uniform_sampler_.seed(RANDOM_SEED);

        // substract max to avoid numerical issues
        double max = hf::bound_value(log_prob, true);
        for(int i = 0; i < int(log_prob.size()); i++)
            log_prob[i] -= max;

        // compute probabilities
        std::vector<double> prob(log_prob.size());<commit_msg>removed Apply() since it can be replaced by std::for_each or std::transform<commit_after>/*************************************************************************
This software allows for filtering in high-dimensional observation and
state spaces, as described in

M. Wuthrich, <NAME>, <NAME>, <NAME>, and <NAME>.
Probabilistic Object Tracking using a Range Camera
IEEE/RSJ Intl Conf on Intelligent Robots and Systems, 2013

In a publication based on this software pleace cite the above reference.


Copyright (C) 2014  <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*************************************************************************/

#ifndef FAST_FILTERING_UTILS_HELPER_FUNCTIONS_HPP
#define FAST_FILTERING_UTILS_HELPER_FUNCTIONS_HPP

#include <vector>
#include <algorithm>
#include <iostream>
#include <limits>
#include <Eigen/Dense>
#include <cmath>

#include <ctime>
#include <fstream>



#include <boost/lexical_cast.hpp>
#include <boost/random/lagged_fibonacci.hpp>

#include <fl/util/random_seed.hpp>



// TODO: THIS HAS TO BE CLEANED, POSSIBLY SPLIT INTO SEVERAL FILES

namespace fl
{

namespace hf
{


// use std::min_element & std::max_element instead. better API if split into two functions
template <typename T> int BoundIndex(const std::vector<T> &values, bool bound_type) // bound type 1 for max and 0 for min
{
	int BoundIndex = 0;
	T bound_value = bound_type ? -std::numeric_limits<T>::max() : std::numeric_limits<T>::max();

	for(int i = 0; i < int(values.size()); i++)
		if(bound_type ? (values[i] > bound_value) : (values[i] < bound_value) )
		{
			BoundIndex = i;
			bound_value = values[i];
		}

	return BoundIndex;
}

// use std::min_element & std::max_element instead
template <typename T> T bound_value(const std::vector<T> &values, bool bound_type) // bound type 1 for max and 0 for min
{
	return values[BoundIndex(values, bound_type)];
}

// sampling class >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class DiscreteDistribution
{
public:
    template <typename T> DiscreteDistribution(std::vector<T> log_prob)
    {
        uniform_sampler_.seed(RANDOM_SEED);

        // substract max to avoid numerical issues
        double max = hf::bound_value(log_prob, true);
        for(int i = 0; i < int(log_prob.size()); i++)
            log_prob[i] -= max;

        // compute probabilities
        std::vector<double> prob(log_prob.size());
{'fraction_non_alphanumeric': 0.25687011859994213, 'fraction_numerical': 0.004772924501012439, 'mean_word_length': 5.432558139534883, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 950, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2999867', 'n_tokens_mistral': 2331, 'n_tokens_neox': 1985, 'n_words': 647}