全部產品
Search
文件中心

Platform For AI:計數三角形

更新時間:Dec 31, 2024

計數三角形演算法是一種用於圖分析的演算法,旨在識別和計算圖中三角形的數量,其中三角形是由三個相互串連的頂點組成的閉合環。該演算法在社交網路分析、網路聚類係數計算和社區檢測等領域具有重要應用。通過計數三角形,可以評估圖的局部密集性和節點之間的緊密串連程度。

配置組件

方法一:可視化方式

在Designer工作流程頁面添加計數三角形組件,並在介面右側配置相關參數:

參數類型

參數

描述

欄位設定

起始節點

邊表的起點所在列。

結束節點

邊表的終點所在列。

參數設定

最大節點度

預設值為500,如果節點度大於該值,則進行抽樣。

執行調優

進程數量

作業並存執行的節點數。數字越大並行度越高,但是架構通訊開銷會增大。

進程記憶體

單個作業可使用的最大記憶體量,單位:MB,預設值為4096。

如果實際使用記憶體超過該值,會拋出OutOfMemory異常。

資料切分大小

資料切分的大小,單位:MB,預設值為64。

方法二:PAI命令方式

使用PAI命令配置計數三角形組件參數。您可以使用SQL指令碼組件進行PAI命令調用,詳情請參見情境4:在SQL指令碼組件中執行PAI命令

PAI -name TriangleCount
    -project algo_public
    -DinputEdgeTableName=TriangleCount_func_test_edge
    -DfromVertexCol=flow_out_id
    -DtoVertexCol=flow_in_id
    -DoutputTableName=TriangleCount_func_test_result;

參數

是否必選

預設值

描述

inputEdgeTableName

輸入邊表名。

inputEdgeTablePartitions

全表讀入

輸入邊表的分區。

fromVertexCol

輸入邊表的起點所在列。

toVertexCol

輸入邊表的終點所在列。

outputTableName

輸出表名。

outputTablePartitions

輸出表的分區。

lifecycle

輸出表的生命週期。

maxEdgeCnt

500

如果節點度大於該值,則進行抽樣。

workerNum

未設定

作業並存執行的節點數。數字越大並行度越高,但是架構通訊開銷會增大。

workerMem

4096

單個作業可使用的最大記憶體量,單位:MB,預設值為4096。

如果實際使用記憶體超過該值,會拋出OutOfMemory異常。

splitSize

64

資料切分的大小,單位:MB。

使用樣本

  1. 添加SQL指令碼組件,去勾選使用Script模式是否由系統添加Create Table語句,並在SQL指令碼中輸入以下SQL語句。

    drop table if exists TriangleCount_func_test_edge;
    create table TriangleCount_func_test_edge as
    select * from
    (
      select '1' as flow_out_id,'2' as flow_in_id
      union all
      select '1' as flow_out_id,'3' as flow_in_id
      union all
      select '1' as flow_out_id,'4' as flow_in_id
      union all
      select '1' as flow_out_id,'5' as flow_in_id
      union all
      select '1' as flow_out_id,'6' as flow_in_id
      union all
      select '2' as flow_out_id,'3' as flow_in_id
      union all
      select '3' as flow_out_id,'4' as flow_in_id
      union all
      select '4' as flow_out_id,'5' as flow_in_id
      union all
      select '5' as flow_out_id,'6' as flow_in_id
      union all
      select '5' as flow_out_id,'7' as flow_in_id
      union all
      select '6' as flow_out_id,'7' as flow_in_id
    )tmp;
    drop table if exists TriangleCount_func_test_result;
    create table TriangleCount_func_test_result
    (
      node1 string,
      node2 string,
      node3 string
    );

    對應的資料結構圖:

    image

  2. 添加SQL指令碼組件,去勾選使用Script模式是否由系統添加Create Table語句,在SQL指令碼中輸入以下PAI命令,並將步驟 1和步驟 2的組件進行連線。

    drop table if exists ${o1};
    PAI -name TriangleCount
        -project algo_public
        -DinputEdgeTableName=TriangleCount_func_test_edge
        -DfromVertexCol=flow_out_id
        -DtoVertexCol=flow_in_id
        -DoutputTableName=${o1};
  3. 單擊左上方image,運行工作流程。

  4. 待運行結束,按右鍵步驟 2的組件,選擇查看資料 > SQL指令碼的輸出,查看訓練結果。

    | node1 | node2 | node3 |
    | ----- | ----- | ----- |
    | 1     | 2     | 3     |
    | 1     | 3     | 4     |
    | 1     | 4     | 5     |
    | 1     | 5     | 6     |
    | 5     | 6     | 7     |