netrd/reconstruction/correlation_matrix.py
def fit(self, TS, cutoffs=[(-1, 1)]):
        """
        Reconstruct a network from time series data using an unregularized form of
        the precision matrix. After [this tutorial](
        https://github.com/valeria-io/visualising_stocks_correlations/blob/master/corr_matrix_viz.ipynb).

        Params
        ------
        TS (np.ndarray): Array consisting of $L$ observations from $N$ sensors
        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.

        """

        # get the correlation matrix
        cor = np.corrcoef(TS)
        self.results['matrix'] = cor

        # get the mask using the cutoffs
        mask_function = np.vectorize(lambda x: any([x>=cutoff[0] and x<=cutoff[1] for cutoff in cutoffs]))
        mask = mask_function(cor)

        # use the mask to threshold the correlation matrix
        A = 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 an unregularized form of
        the precision matrix. After [this tutorial](
        https://github.com/valeria-io/visualising_stocks_correlations/blob/master/corr_matrix_viz.ipynb).

        Params
        ------
        TS (np.ndarray): Array consisting of $L$ observations from $N$ sensors
        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 an unregularized form of
the precision matrix.

Params

TS (np.ndarray): Array consisting of $L$ observations from $N$ sensors
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 an unregularized form of the precision matrix . Params TS ( np . ndarray ) : Array consisting of $L$ observations from $N$ sensors 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, cutoffs=[(-1, 1)]):
        cor = np.corrcoef(TS)
        self.results['matrix'] = cor
        mask_function = np.vectorize(lambda x: any([x>=cutoff[0] and x<=cutoff[1] for cutoff in cutoffs]))
        mask = mask_function(cor)
        A = cor * mask
        self.results['graph'] = nx.from_numpy_array(A)
        G = self.results['graph']
        return G
def fit ( self , TS , cutoffs = [ ( - 1 , 1 ) ] ) : cor = np . corrcoef ( TS ) self . results [ 'matrix' ] = cor mask_function = np . vectorize ( lambda x : any ( [ x >= cutoff [ 0 ] and x <= cutoff [ 1 ] for cutoff in cutoffs ] ) ) mask = mask_function ( cor ) A = cor * mask self . results [ 'graph' ] = nx . from_numpy_array ( A ) G = self . results [ 'graph' ] return G
Reconstruct a network from time series data using an unregularized form of
the precision matrix.
Reconstruct a network from time series data using an unregularized form of the precision matrix .
"""
        Reconstruct a network from time series data using an unregularized form of
        the precision matrix. After [this tutorial](
        https://github.com/valeria-io/visualising_stocks_correlations/blob/master/corr_matrix_viz.ipynb).

        Params
        ------
        TS (np.ndarray): Array consisting of $L$ observations from $N$ sensors
        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.

        """ # get the correlation matrix # get the mask using the cutoffs # use the mask to threshold the correlation matrix # construct the network
self
TS
cutoffs