def _run_interface(self, runtime): self._time_series = img_to_signals( self.inputs.in_file, self.inputs.atlas_file, mask_file=self.inputs.mask_file, background_label=self.inputs.background_label, min_n_voxels=self.inputs.min_n_voxels, ) df = pd.DataFrame(self._time_series) self._cov_mat = np.asarray(df.cov()) self._corr_mat = np.asarray(df.corr()) try: self._pcorr_mat = prec_to_partial(np.linalg.inv(self._cov_mat)) except np.linalg.LinAlgError as e: logging.getLogger("pipeline").warning("LinAlgError %s", e) self._pcorr_mat = np.full_like(self._cov_mat, np.nan) return runtime
def test_prec_to_partial(): prec = np.array([[2., -1., 1.], [-1., 2., -1.], [1., -1., 1.]]) partial = np.array([[1., .5, -sqrt(2.) / 2.], [.5, 1., sqrt(2.) / 2.], [-sqrt(2.) / 2., sqrt(2.) / 2., 1.]]) assert_array_almost_equal(prec_to_partial(prec), partial)