The Network Action Set

Example 16.6 Calculating the Core Decomposition of a Simple Undirected Graph

Calculating the Core Decomposition of a Simple Undirected Graph

This section contains PROC CAS code.

Note: Input data must be in a CAS table that is accessible in your CAS session. This table has a two-level name; the first level is your CAS engine libref and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 3: Shared Concepts in SAS Visual Data Mining and Machine Learning 8.3: Procedures Guide. For more information about PROC CAS and programming in CASL, see Getting Started with CASL, SAS Cloud Analytic Services: CAS Procedure Programming Guide and Reference, and SAS Viya: System Programming Guide.

This example illustrates the use of the core decomposition algorithm on the simple undirected graph G shown in Figure 16.6.

Figure 6: A Simple Undirected Graph

A Simple Undirected Graph


The undirected graph G can be represented using the following nodes data set, NodeSetIn, and links data set, LinkSetIn:

data NodeSetIn;
   input node $ @@;
   datalines;
v1    v2   v3   v4   v5
v6    v7   v8   v9  v10
v11  v12  v13  v14  v15
v16  v17  v18  v19
;

data LinkSetIn;
   input from $ to $ @@;
   datalines;
v1   v2   v5  v6   v6  v7   v7  v8  v10 v11
v2   v3   v3  v4   v2  v4   v8  v9   v9 v10
v8  v18  v10 v12  v13 v14  v13 v15  v13 v16
v13 v17  v14 v15  v14 v16  v14 v17  v15 v16
v15 v17  v16 v17  v18 v13  v18 v17  v18 v16
v12 v14  v12 v15  v12 v16
;

The following DATA steps load the NodeSetIn and LinkSetIn data sets into CAS data tables named mycas.NodeSetIn and mycas.LinkSetIn. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.NodeSetIn;
   set NodeSetIn;
run;
data mycas.LinkSetIn;
   set LinkSetIn;
run;

The following statements calculate the core decomposition and output the results in the data table NodeSetOut:

proc cas;
   loadactionset "network";
   action network.core result=r status=s /
      links    = {name = "LinkSetIn"}
      nodes    = {name = "NodeSetIn"}
      outNodes = {name = "NodeSetOut", replace=true};
   run;
   print r.ProblemSummary; run;
   print r.SolutionSummary; run;
   action table.fetch / table = "NodeSetOut" sortBy = "core_out"; run;
quit;

The problem summary output from this action is presented in Output 16.6.1.

Output 16.6.1: Problem Summary

Problem Summary
Number of Nodes19
Number of Links28
Graph DirectionUndirected


The solution summary output from this action is presented in Output 16.6.2.

Output 16.6.2: Solution Summary

Solution Summary
Problem TypeCore Decomposition
Solution StatusOK
CPU Time0.00
Real Time0.00


The nodes output data table NodeSetOut contains the core number (variable core_out) for each node, as shown in Output 16.6.3.

Output 16.6.3: Core Decomposition of a Simple Undirected Graph

Selected Rows from Table NODESETOUT
_Index_nodecore_out
1v190
2v51
3v11
4v111
5v61
6v71
7v42
8v32
9v22
10v92
11v102
12v82
13v183
14v123
15v154
16v144
17v134
18v174
19v164


Figure 16.7 shows the graph layered by its core number.

Figure 7: Core Decomposition

Core Decomposition


Calculating the Core Decomposition of a Simple Undirected Graph

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be loaded into CAS. One way to do this is to convert the NodeSetIn data to the comma-separated-value (CSV) file NodeSetIn.csv, convert the LinkSetIn data to the CSV file LinkSetIn.csv, and then use the following code to load the CSV files into CAS:

   s:loadtable{casLib="casuser", path="NodeSetIn.csv"}
   s:loadtable{casLib="casuser", path="LinkSetIn.csv"}

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

The following statements calculate the core decomposition and output the results in the data table NodeSetOut:

s:network_core{
    links    = {name = "LinkSetIn"},
    nodes    = {name = "NodeSetIn"},
    outNodes = {name = "NodeSetOut", replace=true}}

Calculating the Core Decomposition of a Simple Undirected Graph

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be loaded into CAS. One way to do this is to convert the NodeSetIn data to the comma-separated-value (CSV) file NodeSetIn.csv, convert the LinkSetIn data to the CSV file LinkSetIn.csv, and then use the following code to load the CSV files into CAS:

   s.upload_file('NodeSetIn.csv')
   s.upload_file('LinkSetIn.csv')
  

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following statements calculate the core decomposition and output the results in the data table NodeSetOut:

s.network.core(
    links    = {"name": "LinkSetIn"},
    nodes    = {"name": "NodeSetIn"},
    outNodes = {"name": "NodeSetOut", "replace":True})

Calculating the Core Decomposition of a Simple Undirected Graph

This example is not available for the R programming language.

Last updated: June 07, 2018