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

inference.MeasuredBlockState: Reflect missing edge probability

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