<commit_before>#pragma once

#include <vector>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/vector_property_map.hpp>
#include "properties.hpp"

namespace bp {

template<typename Graph, typename Visitor,
         typename MessagePropertyMap,
         typename BeliefPropertyMap>
void loopy_sum_product(const Graph& graph, Visitor visitor,
                       MessagePropertyMap message_map,
                       BeliefPropertyMap belief_map,
                       std::size_t n_iteration) {
    typedef boost::graph_traits<Graph> Traits;
    typedef typename Traits::vertex_descriptor Vertex;
    typedef typename Traits::edge_descriptor Edge;

    // initialize messages
    visitor.init_messages(message_map, graph);
    visitor.init_beliefs(belief_map, graph);

    // make messages
    std::vector<Edge> in_vector;
    for(std::size_t n=0; n<n_iteration; ++n) {
        typename Traits::edge_iterator ei, ei_end;
        boost::tie(ei, ei_end) = boost::edges(graph);
        for(; ei != ei_end; ++ei) {
            in_vector.clear();
            const Vertex source = boost::source(*ei);
            const Vertex target = boost::target(*ei);
            typename Traits::in_edge_iterator ein, ein_end;
            boost::tie(ein, ein_end) = boost::in_edges(source, graph);
            for(; ein != ein_end; ++ein) {
                if(boost::source(*ein, graph) == target)
                    in_vector.push_back(*ein)
            }
            visitor.make_message(
                *ei,
                in_vector.begin(),
                in_vector.end(),
                message_map,
                graph);
        }
    }

    // make beliefs
    typename Traits::vertex_iterator vi, vi_end;
    boost::tie(vi, vi_end) = boost::vertices(graph);
    for(; vi != vi_end; ++vi) {
        typename Traits::in_edge_iterator ein, ein_end;
        boost::tie(ein, ein_end) = boost::in_edges(*vi, graph);
        visitor.make_belief(
            *vi, ein, ein_end,
            message_map,
            belief_map,
            graph);
    }
}

template<typename Graph, typename Visitor>
void loopy_sum_product(Graph& graph, Visitor visitor,
                       std::size_t n_iteration) {
    loopy_sum_product(
        graph, visitor,
        boost::get(boost::edge_message, graph),
        boost::get(boost::vertex_belief, graph),
        n_iteration);
}<commit_msg>rename to loopy belief propagation<commit_after>#pragma once

#include <vector>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/vector_property_map.hpp>
#include "properties.hpp"

namespace bp {

template<typename Graph, typename Visitor,
         typename MessagePropertyMap,
         typename BeliefPropertyMap>
void apply_loopy_belief_propagation(const Graph& graph, Visitor visitor,
                                    MessagePropertyMap message_map,
                                    BeliefPropertyMap belief_map,
                                    std::size_t n_iteration) {
    typedef boost::graph_traits<Graph> Traits;
    typedef typename Traits::vertex_descriptor Vertex;
    typedef typename Traits::edge_descriptor Edge;

    // initialize messages
    visitor.init_messages(message_map, graph);
    visitor.init_beliefs(belief_map, graph);

    // make messages
    std::vector<Edge> in_vector;
    for(std::size_t n=0; n<n_iteration; ++n) {
        typename Traits::edge_iterator ei, ei_end;
        boost::tie(ei, ei_end) = boost::edges(graph);
        for(; ei != ei_end; ++ei) {
            in_vector.clear();
            const Vertex source = boost::source(*ei);
            const Vertex target = boost::target(*ei);
            typename Traits::in_edge_iterator ein, ein_end;
            boost::tie(ein, ein_end) = boost::in_edges(source, graph);
            for(; ein != ein_end; ++ein) {
                if(boost::source(*ein, graph) == target)
                    in_vector.push_back(*ein)
            }
            visitor.make_message(
                *ei,
                in_vector.begin(),
                in_vector.end(),
                message_map,
                graph);
        }
    }

    // make beliefs
    typename Traits::vertex_iterator vi, vi_end;
    boost::tie(vi, vi_end) = boost::vertices(graph);
    for(; vi != vi_end; ++vi) {
        typename Traits::in_edge_iterator ein, ein_end;
        boost::tie(ein, ein_end) = boost::in_edges(*vi, graph);
        visitor.make_belief(
            *vi, ein, ein_end,
            message_map,
            belief_map,
            graph);
    }
}

template<typename Graph, typename Visitor>
void apply_loopy_belief_propagation(Graph& graph, Visitor visitor,
                                    std::size_t n_iteration) {
    apply_loopy_belief_propagation(
        graph, visitor,
        boost::get(boost::edge_message, graph),
        boost::get(boost::vertex_belief, graph),
        n_iteration);
}
{'fraction_non_alphanumeric': 0.10884631064003261, 'fraction_numerical': 0.00040766408479412964, 'mean_word_length': 2.2735156771180787, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4308989', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1424, 'n_words': 296}