# Deep Clustering of Student Code Strategies Using Multi-View Code Representation (CMVAE)
## 3 Methodology
### Pre-Training to Learn Code Representations
#### 3.3.2 Extraction of Structural Features  
The generated tree graph is viewed as a network to analyze it structurally using graph theoretic methods. The centrality measures of the nodes are extracted from the graph as features and the relationships between the features and edges of the nodes are mapped to a vectorized representation. Using the graph theory library NetworkX (NetworkX is a Python library for manipulating and analyzing complex networks. Official Documentation: [[https://networkx.org](https://networkx.org)]([https://networkx.org](https://networkx.org)), accessed on 21 July 2024) to compute centrality metrics for each node in each tree graph to obtain feature vectors. ```
1:Input: Source code submitted by students
2:Output: Tree graph g of the source code
3:Function FromSourceCodeToTreeGraph(code)
4:Parse code to generate ast_tree
5:Initialize an empty graph g
6:for each node in ast_tree do
7: Get node type node_type
8: Map node type to corresponding node_id using a node type mapping table
9: Add node_id to graph g with attributes [name: node_type]
10:if the node has a parent then
11: Get parent node type parent_type
12: Map parent type to corresponding parent_id using the node type mapping table
13:if edge (parent_id, node_id) already exists in graph g then
14: Increase the weight of edge (parent_id, node_id)
15:else
16: Add edge (parent_id, node_id) to graph g
17:endif
18:endif
19:for each child node of the current node do
20: Recursively process child node
21:endfor
22:if the node is strategy-related (If, For, While) then
23: Add strategy-related edges in graph g
24:endif
25:endfor
26: Return graph g as output
```  
**Algorithm 1** Conversion from source code to tree graph  
Seven centrality metrics are computed for the graph, and each centrality produces a vector with a length equal to the total number of nodes in the graph.The seven centrality metrics of a graph are computed, each producing a vector whose length matches the total number of nodes in the graph. The calculation proceeds as follows:  
1. **Harmonic Centrality**[28]: This measures the closeness between a node and all other nodes, reflecting the global accessibility of the node. The calculation method is shown in Equation (1): \[C_{H}(v)=\sum_{u\
eq v}\frac{1}{d_{shortest}(u,v)},\] (1) where \(d_{shortest}(u,v)\) is the minimal path distance between nodes \(u\) and \(v\). 2. **Eigenvector Centrality**[29]: This measures the importance of a node, reflecting its importance in logical propagation and dependency relationships. The calculation method is shown in Equation (2): \[C_{E}(v)=\frac{1}{\lambda}\sum_{u\in N(v)}C_{E}(u),\] (2) where \(N(v)\) is the set of neighbors of node \(v\), and \(\lambda\) is the largest eigenvalue of the adjacency matrix. 3. **Closeness Centrality**[30]: This measures the average distance between a node and all other nodes, reflecting the efficiency of node access. The calculation method is shown in Equation (3): \[C_{C}(v)=\frac{1}{\sum_{u\
eq v}d_{shortest}(u,v)},\] (3)where \(d_{shortest}(u,v)\) is the minimal path distance between nodes \(u\) and \(v\). 4. **Betweenness Centrality**[31]: This measures the ability of a node to act as an intermediary in the network, reflecting the node's control over the network. The calculation method is shown in Equation (4): \[C_{B}(v)=\sum_{s\
eq v\
eq t}\frac{\sigma_{st}(v)}{\sigma_{st}},\] (4) where \(\sigma_{st}\) is the overall number of shortest paths between nodes \(s\) and \(t\), and \(\sigma_{st}(v)\) represents the number of shortest paths from \(s\) to \(t\) that pass through node \(v\). 5. **Degree Centrality**[32]: This metric measures the number of connections a node has, reflecting its local importance. The calculation is shown in Equation (5): \[C_{D}(v)=\frac{\text{deg}(v)}{n-1},\] (5) where \(\text{deg}(v)\) is the number of neighbors of the node \(v\), and \(n\) is the total number of nodes. 6. **Katz Centrality**[33]: This metric measures a node's importance, taking into account its connections to other important nodes.