# Cognitive Diagnosis Method via Q-Matrix-Embedded Neural Networks
## 2 Materials and Methods
### Q-Matrix Constraint-Based Neural Network
It is essential to emphasize that this is not a strict rule. If full connectivity is desired, this can be achieved by setting the value of each element of the Q-matrix to one, where the calculation of \(\mathbf{M}^{1}\) is shown in Equation (9). \[\mathbf{M}=Relu[\mathbf{X}(\mathbf{Q}\odot\mathbf{W}^{m})+\mathbf{b}^{m}] \tag{9}\]  
where \(\mathbf{M}\in\mathbb{R}^{N\times K}\) denotes the output of the hidden layer in the orange line, \(\mathbf{X}\in\mathbb{R}^{N\times J}\) denotes the response data of the students, \(\mathbf{Q}\in\mathbb{R}^{J\times K}\) is the constraint matrix for this computational flow and derived from Equation (1), and \(\mathbf{W}^{m1}\in\mathbb{R}^{J\times K}\) and \(\mathbf{b}^{m1}\in\mathbb{R}^{K}\) denote the weight and bias, respectively. \(\odot\) is the Hadamard product, which means the element-wise multiplication of two vectors or matrices. As the orange line represents the main effect, the \(Relu(\cdot)\) function is applied as the activation function. The green line calculates the contribution of the interaction between skills to the correct answers, which consists of an input layer and a hidden layer. Similarly to the orange line, the input layer has dimensions \(J\), and the hidden layer has dimensions \(K^{*}\). The green computational line is constrained by the embedded interactive Q-matrix \(\mathbf{Q}^{*}\) (e.g., Equation (4)), which is computed as shown in Equation (10). \[\mathbf{I}=tanh\Big{[}\mathbf{X}(\mathbf{Q}^{*}\odot\mathbf{W}^{i})+\mathbf{b }^{i}\Big{]} \tag{10}\]  
where \(\mathbf{I}\in\mathbb{R}^{J\times K^{*}}\) denotes the output of the hidden layer in the green line, while \(\mathbf{W}^{i}\) and \(\mathbf{b}^{i}\) denote the weights and biases for this line, respectively. The \(tanh(\cdot)\) function was chosen as the activation function of this line because the interaction effects between skills can facilitate or inhibit correct responses. Finally, in the purple calculation flow, a fully connected layer is employed to consolidate the outcomes of the orange line, which signifies the primary effect, and the green line, which signifies the interactive effect between skills, to determine the student's mastery of each knowledge and skill. Finally, in the purple calculation flow, a fully connected layer is employed to consolidate the outcomes of the orange line, which signifies the primary effect, and the green line, which signifies the interactive effect between skills, to determine the student's mastery of each piece of knowledge and skill. The calculation process is shown in Equation (11). \[\mathbf{\hat{A}}=\sigma[(\mathbf{M}\oplus\mathbf{I})\mathbf{W}^{c}+\mathbf{b} ^{c}] \tag{11}\]  
where the symbol \(\oplus\) is used to denote the serial concatenation of two vectors or matrices. \(\mathbf{w}^{c}\) and \(\mathbf{b}^{c}\) denote the weights and biases in this layer. \(\sigma(\cdot)\) denotes the activation function. \(\mathbf{\hat{A}}\) denotes the predicted probability of a student's skill mastery by Dual Q-Net. A threshold can usually be used to determine whether a student has mastered a skill. For example, \(\alpha_{ik}>0.5\) indicates that student \(i\) has mastered skill \(k\). The forward computation process of Dual Q-Net network is thus completed. The loss function of the model is the mean squared error function, as shown in Equation (12). The model parameters are updated by the backward propagation algorithm. \[\mathcal{L}(\mathbf{\theta})=\frac{1}{2N}(\mathbf{\hat{A}}-\mathbf{A})^{T}( \mathbf{\hat{A}}-\mathbf{A}) \tag{12}\]  
where \(\mathbf{\theta}\) denotes the parameters of the model, including the weight and bias of each layer in the network. \(\mathbf{A}\) is the real skill mastering mode of the students, and \(N\) is the number of students participating in the test. To provide a clear understanding of the implementation details and training process of the Dual Q-Net algorithm, we present its pseudocode in Algorithm 1.