Commit 7e43294e authored by Tiago Peixoto's avatar Tiago Peixoto

inference.MeasuredBlockState: Reflect missing edge probability

parent 40c76afc
......@@ -161,6 +161,19 @@ struct Measured
return _get_edge<insert>(u, v, _g, _edges);
}
double get_MP(size_t T, size_t M, bool complete = true)
{
double S = 0;
S += lbeta(M - T + _alpha, T + _beta);
S += lbeta(_X - T + _mu, _N - _X - (M - T) + _nu);
if (complete)
{
S -= lbeta(_alpha, _beta);
S -= lbeta(_mu, _nu);
}
return S;
}
double entropy()
{
double S = 0;
......@@ -172,8 +185,7 @@ struct Measured
}
S += (_NP - gE) * lbinom(_n_default, _x_default);
S += lbeta(_T + _alpha, _M - _T + _beta) - lbeta(_alpha, _beta);
S += lbeta(_X - _T + _mu, _N - _X - (_M - _T) + _nu) - lbeta(_mu, _nu);
S+= get_MP(_T, _M);
if (_E_prior)
S += _E * _pe - lgamma_fast(_E + 1) - exp(_pe);
......@@ -183,14 +195,9 @@ struct Measured
double get_dS(int dT, int dM)
{
size_t nT = _T + dT;
size_t nM = _M + dM;
// FIXME: Can be faster!
double Si = (lbeta(_T + _alpha, _M - _T + _beta) +
lbeta(_X - _T + _mu, _N - _X - (_M - _T) + _nu));
double Sf = (lbeta(nT + _alpha, nM - nT + _beta) +
lbeta(_X - nT + _mu, _N - _X - (nM - nT) + _nu));
double Si = get_MP(_T, _M, false);
double Sf = get_MP(_T + dT, _M + dM, false);
return -(Sf - Si);
}
......
......@@ -83,7 +83,7 @@ class UncertainBaseState(object):
self.nbstate = None
self.bstate = bstate
edges = self.u.get_edges()
edges = self.g.get_edges()
edges = numpy.concatenate((edges,
numpy.ones(edges.shape,
dtype=edges.dtype) * (N + 1)))
......@@ -366,8 +366,8 @@ class MeasuredBlockState(UncertainBaseState):
x_default=self.x_default,
fp_params=dict(alpha=self.alpha, beta=self.beta),
fn_params=dict(mu=self.mu, nu=self.nu), phi=self.phi,
bstate=(self.nbstate.copy() if self.nbstate is not None
else self.bstate.copy()), self_loops=self.self_loops)
bstate=(self.nbstate if self.nbstate is not None
else self.bstate), self_loops=self.self_loops)
def __setstate__(self, state):
self.__init__(**state)
......@@ -398,7 +398,7 @@ class MeasuredBlockState(UncertainBaseState):
"""Get gamma distribution parameters for the posterior probability of missing edges."""
T = self._state.get_T()
M = self._state.get_M()
return T + self.alpha, M - T + self.beta
return M - T + self.alpha, M + self.beta
def get_q_posterior(self):
"""Get gamma distribution parameters for the posterior probability of spurious edges."""
......
Markdown is supported
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