def get_phi(self, params, cliques=False):
phis = [signalcollection.get_phi(params) for
signalcollection in self._signalcollections]
# if we found common signals, we'll return a big phivec matrix,
# otherwise a list of phivec vectors (some of which possibly None)
if self._commonsignals:
if np.any([phi.ndim == 2 for phi in phis if phi is not None]):
# if we have any dense matrices,
Phi = sl.block_diag(*[np.diag(phi) if phi.ndim == 1 else phi
for phi in phis
if phi is not None])
else:
Phi = np.diag(np.concatenate([phi for phi in phis
if phi is not None]))
# get a dictionary of slices locating each pulsar in Phi matrix
slices = self._get_slices(phis)
# self._cliques is a vector of the same size as the Phi matrix
# for each Phi index i, self._cliques[i] is -1 if row/column
# belong to no clique, or it gives the clique number otherwise
if cliques:
self._resetcliques(Phi.shape[0])
self._setpulsarcliques(slices, phis)
# iterate over all common signal classes
for csclass, csdict in self._commonsignals.items():
# first figure out which indices are used in this common signal
# and update the clique index
if cliques:
self._setcliques(slices, csdict)
# now iterate over all pairs of common signal instances
pairs = itertools.combinations(csdict.items(),2)
for (cs1, csc1), (cs2, csc2) in pairs:
crossdiag = csclass.get_phicross(cs1, cs2, params)
block1, idx1 = slices[csc1], csc1._idx[cs1]
block2, idx2 = slices[csc2], csc2._idx[cs2]
Phi[block1,block2][idx1,idx2] += crossdiag
Phi[block2,block1][idx2,idx1] += crossdiag
return Phi
else:
return phis
评论列表
文章目录