

def _create_dense_diagonal_precision(X, graph, n_features, n_features_per_vertex, dtype=np.float32, n_components=None, bias=0, return_covariances=False, verbose=False):
    precision = np.zeros((n_features, n_features), dtype=dtype)
    if return_covariances:
        all_covariances = np.zeros((graph.n_vertices, n_features_per_vertex, n_features_per_vertex), dtype=dtype)
    if verbose:
        print_dynamic('Allocated precision matrix of size {}'.format(bytes_str(precision.nbytes)))
    if verbose:
        vertices = print_progress(range(graph.n_vertices), n_items=graph.n_vertices, prefix='Precision per vertex', end_with_newline=False)
    else:
        vertices = range(graph.n_vertices)
    for v in vertices:
        i_from = (v * n_features_per_vertex)
        i_to = ((v + 1) * n_features_per_vertex)
        covmat = np.cov(X[:, i_from:i_to], rowvar=0, bias=bias)
        if return_covariances:
            all_covariances[v] = covmat
        covmat = _covariance_matrix_inverse(covmat, n_components)
        precision[i_from:i_to, i_from:i_to] = covmat
    if return_covariances:
        return (precision, all_covariances)
    else:
        return precision

dataset/ETHPy150Open menpo/menpo/menpo/model/gmrf.py _create_dense_diagonal_precision/original