随机块模型和隐块模型的稀疏矩阵实现。

sparsebm的Python项目详细描述


SparseBM:一个用于处理带有块模型的稀疏图的python模块

安装

来自pypi:

pip3 install sparsebm

要使用GPU加速:

^{pr2}$

或者

pip3 install sparsebm
pip3 install cupy

随机块体模型实例

生成SBM合成图

  • 生成合成图以使用SBM进行分析:
fromsparsebmimportgenerate_SBM_datasetdataset=generate_SBM_dataset(symmetric=True)graph=dataset["data"]cluster_indicator=dataset["cluster_indicator"]

用sparsebm SBM推断:

  • 使用伯努利随机集团模型:
fromsparsebmimportSBMnumber_of_clusters=cluster_indicator.shape[1]# A number of classes must be specify. Otherwise see model selection.model=SBM(number_of_clusters)model.fit(graph,symmetric=True)print("Labels:",model.labels)

计算性能:

fromsparsebm.utilsimportARIari=ARI(cluster_indicator.argmax(1),model.labels)print("Adjusted Rand index is {:.2f}".format(ari))

要使用GPU加速,需要安装CUPY并将GPU编号替换为所需的GPU索引。在

潜在块体模型实例

生成LBM合成图

  • 生成一个综合图,用LBM分析:
fromsparsebmimportgenerate_LBM_datasetdataset=generate_LBM_dataset()graph=dataset["data"]row_cluster_indicator=dataset["row_cluster_indicator"]column_cluster_indicator=dataset["column_cluster_indicator"]

用sparsebm LBM推断:

  • 使用伯努利潜在集团模型:
fromsparsebmimportLBMnumber_of_row_clusters=row_cluster_indicator.shape[1]number_of_columns_clusters=column_cluster_indicator.shape[1]# A number of classes must be specify. Otherwise see model selection.model=LBM(number_of_row_clusters,number_of_columns_clusters,n_init_total_run=1,)model.fit(graph)print("Row Labels:",model.row_labels)print("Column Labels:",model.column_labels)

计算性能:

fromsparsebm.utilsimportCARIcari=CARI(row_cluster_indicator.argmax(1),column_cluster_indicator.argmax(1),model.row_labels,model.column_labels,)print("Co-Adjusted Rand index is {:.2f}".format(cari))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java@AfterEach注释在Spring测试中被忽略   散列如何使用bouncy castle在Java中创建SHA512摘要字符串?   java无法使用Okhttp获取响应cookie   100个数的java阶乘   多线程如何在Java中实现对象计数器   java我的精灵不显示背景   java如何在com上应用PanelSlideListener。索特里。滑动面板。SlidengUpPanelLayout SlideUp库   java如何在JDBC中使用WHERE EXISTS函数   java Swing:标签前景中的白色被绘制为黑色   获取java的时间戳。util。另一个java的日期对象为(10/7/14)。util。日期对象(2014年10月7日星期二11:21:00)   java如何在Spring/OpenJPA 1中重新创建用于更新行锁定的选择   java在保存另一个maven项目中的类时,有没有办法让eclipse识别对该类的更改?   java如何解决Spring中的Servlet上下文错误?   java在mongodb中删除记录   显示的java片段与当前片段重叠,而不是替换它