Exemple #1
0
from graspy.models import DCSBMEstimator, RDPGEstimator, SBMEstimator
from graspy.plot import heatmap
from src.data import load_right

# Load data
right_adj, right_labels = load_right()

# Fit the models
sbm = SBMEstimator(directed=True, loops=False)
sbm.fit(right_adj, y=right_labels)

dcsbm = DCSBMEstimator(degree_directed=False, directed=True, loops=False)
dcsbm.fit(right_adj, y=right_labels)

rdpg = RDPGEstimator(loops=False, n_components=3)
rdpg.fit(right_adj)

# Plotting
np.random.seed(8888)

cmap = mpl.cm.get_cmap("RdBu_r")
center = 0
vmin = 0
vmax = 1
norm = mpl.colors.Normalize(0, 1)
cc = np.linspace(0.5, 1, 256)
cmap = mpl.colors.ListedColormap(cmap(cc))

heatmap_kws = dict(
    cbar=False,
Exemple #2
0
 def test_RDPG_score(self):
     p_mat = self.p_mat
     graph = self.graph
     estimator = RDPGEstimator()
     _test_score(estimator, p_mat, graph)
Exemple #3
0
        title="DCSBM probability matrix",
        vmin=0,
        vmax=1,
        sort_nodes=True)

plt.savefig("DCSBMProbabilityMatrix", bbox_inches='tight')

heatmap(dcsbme.sample()[0],
        inner_hier_labels=labels,
        title="DCSBM sample",
        font_scale=1.5,
        sort_nodes=True)

plt.savefig("DCSBMSample", bbox_inches='tight')

rdpge = RDPGEstimator(loops=False)
rdpge.fit(adj, y=labels)
heatmap(rdpge.p_mat_,
        inner_hier_labels=labels,
        vmin=0,
        vmax=1,
        font_scale=1.5,
        title="RDPG probability matrix",
        sort_nodes=True
       )

plt.savefig("RDPGProbabilityMatrix", bbox_inches='tight')

heatmap(rdpge.sample()[0],
        inner_hier_labels=labels,
        font_scale=1.5,
Exemple #4
0
    def test_RDPG_intputs(self):
        rdpge = RDPGEstimator()

        with pytest.raises(TypeError):
            RDPGEstimator(loops=6)

        with pytest.raises(ValueError):
            rdpge.fit(self.graph[:, :99])

        with pytest.raises(ValueError):
            rdpge.fit(self.graph[..., np.newaxis])

        with pytest.raises(TypeError):
            RDPGEstimator(ase_kws=5)

        with pytest.raises(TypeError):
            RDPGEstimator(diag_aug_weight="f")

        with pytest.raises(ValueError):
            RDPGEstimator(diag_aug_weight=-1)

        with pytest.raises(TypeError):
            RDPGEstimator(plus_c_weight="F")

        with pytest.raises(ValueError):
            RDPGEstimator(plus_c_weight=-1)