graph_blockmodel_layers_util.hh 1.85 KB
Newer Older
1 2
// graph-tool -- a general graph modification and manipulation thingy
//
Tiago Peixoto's avatar
Tiago Peixoto committed
3
// Copyright (C) 2006-2020 Tiago de Paula Peixoto <tiago@skewed.de>
4
//
5 6 7 8
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.
9
//
10 11 12 13
// 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 Lesser General Public License for more
// details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16 17 18 19 20 21 22 23 24 25 26 27 28
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef GRAPH_BLOCKMODEL_LAYERS_UTIL_HH
#define GRAPH_BLOCKMODEL_LAYERS_UTIL_HH

#include "config.h"

namespace graph_tool
{
using namespace boost;
using namespace std;

template <class State, class MEntries>
29
double virtual_move_covariate(size_t v, size_t r, size_t s, State& state,
30 31 32
                              MEntries& m_entries, bool reset)
{
    if (reset)
33
        state.get_move_entries(v, r, s, m_entries);
34 35

    double dS = 0;
36
    entries_op(m_entries, state._emat,
37
               [&](auto, auto, auto& me, auto d)
38 39 40 41 42 43 44
               {
                   int ers = (me != state._emat.get_null_edge()) ?
                       state._mrs[me] : 0;
                   assert(ers + d >= 0);
                   dS -= -lgamma_fast(ers + 1);
                   dS += -lgamma_fast(ers + d + 1);
               });
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    return dS;
}

template <class Graph, class EMap>
double covariate_entropy(Graph& bg, EMap& mrs)
{
    double S = 0;
    for (auto e : edges_range(bg))
        S -= lgamma_fast(mrs[e] + 1);
    return S;
}

} // graph_tool namespace

#endif //GRAPH_BLOCKMODEL_LAYERS_UTIL_HH