Commit c80b9af0 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

CliqueState: fix log-likelihood computation

parent 324b5495
Pipeline #940 failed with stage
in 43 minutes and 9 seconds
......@@ -59,5 +59,4 @@ void export_clique_decomposition()
using namespace boost::python;
def("clique_iter_mh", clique_iter_mh);
def("clique_L_over", L_over);
def("clique_L_sparse", L_sparse);
}
......@@ -25,17 +25,10 @@ using namespace boost;
using namespace std;
double L_sparse(size_t N, size_t d, size_t Ed, size_t D, double E)
{
double lb = lbinom_fast(N, d);
return lgamma_fast(Ed + 1) - (Ed + 1) * log1p(E / (D - 1)) - Ed * lb;
}
double L_over(size_t N, size_t d, size_t Ed, size_t D, double E)
{
double lb = lbinom_fast(N, d);
double mu = -(D - 1) * log(1 + 2 * E / N * (N - 1));
return lgamma_fast(Ed + 1) - (Ed + 1) * log((N - d + 1) / d + 1 / mu) - Ed * lb - log(mu);
return lgamma_fast(Ed + 1) - (Ed + 1) * log1p((D - 1) / E) - Ed * lb - log(E / (D - 1));
}
template <class Graph, class Vxprop, class Vprop, class Cprop, class Vec, class RNG>
......@@ -166,8 +159,8 @@ iter_mh(Graph& g, Vxprop x, Cprop c, Vprop is_fac, Vprop is_max, Vec& Ed, int N,
a -= (x[v] == 0) ? 0 : -log(2);
a += (x[v] + dx == 0) ? 0 : -log(2);
bernoulli_distribution accept(exp(beta * (pa - pb) + a));
if (pa > pb || (!std::isinf(beta) && accept(rng)))
bernoulli_distribution accept(exp(min(beta * (pa - pb) + a, 0.)));
if ((std::isinf(beta) && (pa > pb)) || accept(rng))
{
x[v] += dx;
for (auto u : out_neighbors_range(v, g))
......
......@@ -78,10 +78,12 @@ class CliqueState(object):
array([ 4, 28], dtype=int32) 1
array([ 4, 6, 29], dtype=int32) 1
array([ 4, 30, 31], dtype=int32) 1
array([5, 6, 7], dtype=int32) 1
array([5, 6, 7], dtype=int32) 0
array([ 7, 71], dtype=int32) 1
array([ 7, 14, 58], dtype=int32) 1
array([ 7, 58, 85], dtype=int32) 1
array([ 7, 58, 85], dtype=int32) 0
array([ 7, 30, 58], dtype=int32) 1
array([ 6, 10, 12], dtype=int32) 1
References
----------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment