A counting triangle is used to determine the number of triangles that pass through each vertex in Undirected Graph G. This topic describes the Counting Triangle component provided by Machine Learning Studio.

You can configure the component by using one of the following methods:

Machine Learning Platform for AI console

Tab Parameter Description
Fields Setting Start Vertex The start vertex column in the edge table.
End Vertex The end vertex column in the edge table.
Parameters Setting Largest Vertex Degree If the vertex degree is greater than the value of this parameter, sampling is required. This parameter is optional. Default value: 500.
Tuning Workers The number of vertices for parallel job execution. The parallelism level and framework communication costs increase with the value of this parameter.
Memory Size per Worker (MB) The maximum size of memory that a single job can use. By default, the system allocates 4,096 MB for each job. If the used memory size exceeds the value of this parameter, the OutOfMemory exception is reported.
Data Split Size (MB) The data split size. Default value: 64.

PAI command

PAI -name TriangleCount
    -project algo_public
    -DinputEdgeTableName=TriangleCount_func_test_edge
    -DfromVertexCol=flow_out_id
    -DtoVertexCol=flow_in_id
    -DoutputTableName=TriangleCount_func_test_result;
Parameter Required Description Default value
inputEdgeTableName Yes The name of the input edge table. No default value
inputEdgeTablePartitions No The partitions in the input edge table. Full table
fromVertexCol Yes The start vertex column in the input edge table. No default value
toVertexCol Yes The end vertex column in the input edge table. No default value
outputTableName Yes The name of the output table. No default value
outputTablePartitions No The partitions in the output table. No default value
lifecycle No The lifecycle of the output table. No default value
maxEdgeCnt No If the vertex degree is greater than the value of this parameter, sampling is required. 500
workerNum No The number of vertices for parallel job execution. The parallelism level and framework communication costs increase with the value of this parameter. Not configured
workerMem No The maximum size of memory that a single job can use. By default, the system allocates 4,096 MB for each job. If the used memory size exceeds the value of this parameter, the OutOfMemory exception is reported. 4096
splitSize No The data split size. 64

Examples

  1. Generate training data.
    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 from dual
      union all
      select '1' as flow_out_id,'3' as flow_in_id from dual
      union all
      select '1' as flow_out_id,'4' as flow_in_id from dual
      union all
      select '1' as flow_out_id,'5' as flow_in_id from dual
      union all
      select '1' as flow_out_id,'6' as flow_in_id from dual
      union all
      select '2' as flow_out_id,'3' as flow_in_id from dual
      union all
      select '3' as flow_out_id,'4' as flow_in_id from dual
      union all
      select '4' as flow_out_id,'5' as flow_in_id from dual
      union all
      select '5' as flow_out_id,'6' as flow_in_id from dual
      union all
      select '5' as flow_out_id,'7' as flow_in_id from dual
      union all
      select '6' as flow_out_id,'7' as flow_in_id from dual
    )tmp;
    drop table if exists TriangleCount_func_test_result;
    create table TriangleCount_func_test_result
    (
      node1 string,
      node2 string,
      node3 string
    );
    The following figure shows the structure of the counting triangle.Counting triangle structure
  2. View training results.
    1,2,3
    1,3,4
    1,4,5
    1,5,6
    5,6,7