netrd/reconstruction/partial_correlation_matrix.py
def fit(self,
            TS,
            index=None,
            drop_index=True,
            of_residuals=False,
            cutoffs=[(-1, 1)]):
        """
        Reconstruct a network from time series data using a regularized
        form of the precision matrix. After [this tutorial](
        https://bwlewis.github.io/correlation-regularization/) in R.

        Params
        ------
        index (int, array of ints, or None): Take the partial correlations of
        each pair of elements holding constant an index variable or set of
        index variables. If None, take the partial correlations of the
        variables holding constant all other variables.
        drop_index (bool): If True, drop the index variables after calculating
        the partial correlations.
        of_residuals (bool): If True, after calculating the partial correlations (
        presumably using a dropped index variable), recalculate the partial
        correlations between each variable, holding constant all other variables.
        cutoffs (list of tuples): When thresholding, include only edges whose
        correlations fall within a given range or set of ranges. The lower
        value must come first.

        Returns
        -------
        G: a reconstructed graph.

        """

        p_cor = partial_corr(TS, index=index)

        if drop_index and index is not None:
            p_cor = np.delete(p_cor, index, axis=0)
            p_cor = np.delete(p_cor, index, axis=1)

        if of_residuals:
            p_cor = partial_corr(p_cor, index=None)

        self.results['matrix'] = p_cor

        mask_function = np.vectorize(lambda x: any([x>=cutoff[0] and x<=cutoff[1] for cutoff in cutoffs]))
        mask = mask_function(p_cor)

        # use the mask to threshold the correlation matrix
        A = p_cor * mask

        # construct the network
        self.results['graph'] = nx.from_numpy_array(A)
        G = self.results['graph']

        return G

        Reconstruct a network from time series data using a regularized
        form of the precision matrix. After [this tutorial](
        https://bwlewis.github.io/correlation-regularization/) in R.

        Params
        ------
        index (int, array of ints, or None): Take the partial correlations of
        each pair of elements holding constant an index variable or set of
        index variables. If None, take the partial correlations of the
        variables holding constant all other variables.
        drop_index (bool): If True, drop the index variables after calculating
        the partial correlations.
        of_residuals (bool): If True, after calculating the partial correlations (
        presumably using a dropped index variable), recalculate the partial
        correlations between each variable, holding constant all other variables.
        cutoffs (list of tuples): When thresholding, include only edges whose
        correlations fall within a given range or set of ranges. The lower
        value must come first.

        Returns
        -------
        G: a reconstructed graph.

        
Reconstruct a network from time series data using a regularized
form of the precision matrix.

Params

index (int, array of ints, or None): Take the partial correlations of
each pair of elements holding constant an index variable or set of
index variables. If None, take the partial correlations of the
variables holding constant all other variables.
drop_index (bool): If True, drop the index variables after calculating
the partial correlations.
of_residuals (bool): If True, after calculating the partial correlations (
presumably using a dropped index variable), recalculate the partial
correlations between each variable, holding constant all other variables.
cutoffs (list of tuples): When thresholding, include only edges whose
correlations fall within a given range or set of ranges. The lower
value must come first.

Returns

a reconstructed graph.
Reconstruct a network from time series data using a regularized form of the precision matrix . Params index ( int array of ints or None ) : Take the partial correlations of each pair of elements holding constant an index variable or set of index variables . If None take the partial correlations of the variables holding constant all other variables . drop_index ( bool ) : If True drop the index variables after calculating the partial correlations . of_residuals ( bool ) : If True after calculating the partial correlations ( presumably using a dropped index variable ) recalculate the partial correlations between each variable holding constant all other variables . cutoffs ( list of tuples ) : When thresholding include only edges whose correlations fall within a given range or set of ranges . The lower value must come first . Returns a reconstructed graph .
def fit(self,
            TS,
            index=None,
            drop_index=True,
            of_residuals=False,
            cutoffs=[(-1, 1)]):
        p_cor = partial_corr(TS, index=index)
        if drop_index and index is not None:
            p_cor = np.delete(p_cor, index, axis=0)
            p_cor = np.delete(p_cor, index, axis=1)
        if of_residuals:
            p_cor = partial_corr(p_cor, index=None)
        self.results['matrix'] = p_cor
        mask_function = np.vectorize(lambda x: any([x>=cutoff[0] and x<=cutoff[1] for cutoff in cutoffs]))
        mask = mask_function(p_cor)
        A = p_cor * mask
        self.results['graph'] = nx.from_numpy_array(A)
        G = self.results['graph']
        return G
def fit ( self , TS , index = None , drop_index = True , of_residuals = False , cutoffs = [ ( - 1 , 1 ) ] ) : p_cor = partial_corr ( TS , index = index ) if drop_index and index is not None : p_cor = np . delete ( p_cor , index , axis = 0 ) p_cor = np . delete ( p_cor , index , axis = 1 ) if of_residuals : p_cor = partial_corr ( p_cor , index = None ) self . results [ 'matrix' ] = p_cor mask_function = np . vectorize ( lambda x : any ( [ x >= cutoff [ 0 ] and x <= cutoff [ 1 ] for cutoff in cutoffs ] ) ) mask = mask_function ( p_cor ) A = p_cor * mask self . results [ 'graph' ] = nx . from_numpy_array ( A ) G = self . results [ 'graph' ] return G
Reconstruct a network from time series data using a regularized
form of the precision matrix.
Reconstruct a network from time series data using a regularized form of the precision matrix .
"""
        Reconstruct a network from time series data using a regularized
        form of the precision matrix. After [this tutorial](
        https://bwlewis.github.io/correlation-regularization/) in R.

        Params
        ------
        index (int, array of ints, or None): Take the partial correlations of
        each pair of elements holding constant an index variable or set of
        index variables. If None, take the partial correlations of the
        variables holding constant all other variables.
        drop_index (bool): If True, drop the index variables after calculating
        the partial correlations.
        of_residuals (bool): If True, after calculating the partial correlations (
        presumably using a dropped index variable), recalculate the partial
        correlations between each variable, holding constant all other variables.
        cutoffs (list of tuples): When thresholding, include only edges whose
        correlations fall within a given range or set of ranges. The lower
        value must come first.

        Returns
        -------
        G: a reconstructed graph.

        """ # use the mask to threshold the correlation matrix # construct the network
self
TS
index
drop_index
of_residuals
cutoffs