A method for constructing equivalent equation group model of single-layer BP neural network

By constructing the equivalent equation system model of a single-layer Bp neural network, the problem in the existing technology that it is difficult to write programs to solve optimization problems under linear constraints is solved, and efficient identification under constraints is achieved, which is suitable for modern management and engineering. application.

CN114298248BInactive Publication Date: 2024-09-03CHONGQING MEDICAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210089537.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-25
Publication Date
2024-09-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When the existing Bp neural network handles optimization problems with linear constraints, it is difficult to write clear programs for gradient solution, especially under complex constraints, which leads to the difficulty of optimizing the coefficient matrix.

Method used

This paper proposes a method to construct an equivalent system of equations model for a single-layer Bp neural network. By preprocessing data, constructing an equivalent system of equations model under unconstrained and linear constraints, and solving it using the gradient descent iterative method, the program writing process is simplified. , conveniently adding constraints to the system of equations.

Benefits of technology

It realizes the convenient solution of optimization problems under constrained conditions, provides new ideas for solving linear constrained black box optimization problems, is suitable for modern management and engineering applications, and improves the generalizability and identification accuracy of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114298248B
    Figure CN114298248B
Patent Text Reader

Abstract

This invention discloses a method for constructing an equivalent equation system model for a single-layer Bp neural network, comprising the following steps: preprocessing the dataset; loading the training set; reading the neural network structure; constructing an equivalent equation system model under unconstrained conditions and solving it, then verifying the equivalence between the unconstrained equivalent equation system model and the single-layer Bp neural network; constructing an equivalent equation system model under linear constraints and solving it; and testing the solution of the equation system with linear constraints using a test set. Under unconstrained conditions, this model achieves a recognition rate almost identical to that of a single-layer Bp neural network; under complex linear constraints, the model can clearly express the constraints, solving optimization problems that are difficult to solve using programs written for single-layer Bp neural networks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of artificial neural networks, and in particular relates to a method for constructing an equivalent equation group model of a single-layer Bp neural network. Background Art

[0002] The existing Bp neural network uses the Bp algorithm to optimize the coefficient matrix to achieve the purpose of learning the training set samples. If you want the neural network to optimize the coefficient matrix under certain constraints, you must add constraints after the constructed loss function. There are two approaches to the existing model. One is to add regularization terms, and the other is to redesign the loss function using the Lagrange multiplier method. Regularization has several types of L0 norms, L1 norms, and L2 norms. Adding regularization terms as constraints can solve the problem of neural network overfitting. However, since the program requires the use of matrix form to express the coefficient matrix update formula, if you encounter a more complex optimization problem with linear constraints, it is difficult to use a simple and clear program to express the process of finding the gradient in the Bp algorithm. Redesigning the loss function using the Lagrange multiplier method will also encounter the problem that it is mathematically feasible, but it is difficult to optimize the coefficient matrix in the program. The problem of difficult program writing cannot be avoided when constructing a loss function through the Bp algorithm to solve optimization problems with linear constraints.

[0003] Therefore, it is necessary to provide a new method for constructing an equivalent set of equations model of a single-layer BP neural network. Summary of the invention

[0004] In view of this, the present invention aims at the problem that it is difficult to write a descent gradient program in a single-layer Bp neural network Bp algorithm program with constraints, and provides a method for constructing an equivalent set of equations model of a single-layer Bp neural network. The present invention utilizes the equivalent set of equations model, and the user can easily add constraints to the set of equations, and the method can be used to extremely conveniently solve the set of equations using a program.

[0005] In order to solve the above technical problems, the present invention discloses a method for constructing an equivalent equation group model of a single-layer Bp neural network, comprising the following steps:

[0006] Step 1: Preprocess the data set;

[0007] Step 2: Load the training set;

[0008] Step 3: Read the neural network structure;

[0009] Step 4: construct an equivalent set of equations model under unconstrained conditions, solve it, and then verify the equivalence of the equivalent set of equations model under unconstrained conditions and the single-layer BP neural network;

[0010] Step 5: construct an equivalent set of equations model under linear constraints and solve it;

[0011] Step 6: Use the test set to test the solution of the system of equations with linear constraints.

[0012] Optionally, the preprocessing of the data set in step 1 is specifically as follows: the image data in the training set and the test set of the data set are transformed into row vectors, and then stored in columns; after the above preprocessing, the image samples of the training set and the test set are respectively named "F_train" and "F_test"; the training set and the test set label sets corresponding to the image sample sets are respectively named "B_train" and "B_test", and the pictures and labels of the test set are independently packaged; the data set is the MNIST data set; it contains 60,000 training set pictures and their corresponding labels and 10,000 test set pictures and their corresponding labels.

[0013] Optionally, loading the training set in step 2 specifically includes: loading the training set, the test set image set and the label set into the software workspace.

[0014] Optionally, the neural network structure read in step 3 is specifically as follows: the number of neurons in the input layer is equal to the total number of pixels in the training set image; the number of neurons in the output layer is the number of classification categories.

[0015] Optionally, the equivalent system of equations model under unconstrained conditions is constructed in step 4, and solved, and then the equivalence of the equivalent system of equations model under unconstrained conditions and the single-layer Bp neural network is verified, specifically:

[0016] Step 4.1: Under unconstrained conditions, according to the linear non-homogeneous equations: AX = B, use the input image and label value corresponding to the single-layer Bp neural network to write a program to solve the equations model, specifically:

[0017] The digits 0 to 9 are divided into ten categories, and the label values ​​are encoded in one-hot format. Due to the one-hot encoding format, each bit of the code corresponds to the B term on the right side of an equation, so one picture corresponds to ten equations.

[0018] By transforming the coefficient matrix W into a column vector X, given that the equation system is in the form of AX=B, the column vector X is 7840-dimensional, and the column vector B is 10-dimensional, it can be inferred from matrix multiplication that the size of the matrix A is 10 rows and 7840 columns, thereby constructing a specific equation system model of AX=B;

[0019] Step 4.2, using the gradient descent iteration method to solve the system of equations to solve the equivalent system of equations model under unconstrained conditions;

[0020] Step 4.3: Verify the equivalence between the system of equations model under unconstrained conditions and the single-layer BP neural network.

[0021] Optionally, the step 4.2 uses the gradient descent iteration method to solve the system of equations to solve the equivalent system of equations model under unconstrained conditions, specifically:

[0022] Step 4.2.1, by initializing the unknown number vector X to any random number that obeys uniform distribution, the initial iteration point X is determined, given the convergence accuracy T = 0.2 and the learning rate α = 0.005, the initialization matrix row number i = 1, and the number of training epoches = 0;

[0023] Step 4.2.2, determine whether i is greater than 600000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first equation. If it is still less than 600000, continue to step 4.2.3;

[0024] Step 4.2.3, select the i-th row of the training set A matrix and the i-th row of the label column vector B. This actually selects the i-th equation in the system of equations;

[0025] Step 4.2.4: Calculate the value of B when the i-th equation is at point X. i The first partial derivative with respect to X

[0026] Step 4.2.5: According to the gradient descent formula Find the value of the new unknown number X, α is the learning rate, For B i The first partial derivative with respect to X;

[0027] Step 4.2.6, calculate the mean square error (MSE) between the output of the equation system after updating X and the expected output.

[0028]

[0029] Where N is the number of equations in the equation group, which is 600,000 in the handwritten digit recognition task. i represents the i-th row in matrix A, X is the value of the unknown number, B i represents the i-th row in column vector B;

[0030] Step 4.2.7, determine whether the MSE meets the set convergence accuracy T, if so, go to step 4.2.8, if not, execute i=i+1 and then go to step 4.2.2;

[0031] Step 4.2.8, output the trained unknown number series vector X, transform the unknown number series vector X back to the Bp neural network coefficient matrix W1, using MATLAB software as an example to use the reshape function and execute W1=reshape(X,

[78410] ).

[0032] Optionally, the verification of the equivalence of the system of equations model under unconstrained conditions and the single-layer Bp neural network in step 4.3 is specifically as follows:

[0033] Step 4.3.1, bring the weight coefficient matrix W1 obtained by transforming the unknown number series vector X into the single-layer Bp neural network for testing, calculate the actual output Z=F_test*W1 of the single-layer Bp neural network, and the final Z matrix size is 10000*10;

[0034] Step 4.3.2, since each column in the output of the Bp neural network represents the output result of a picture, the row number of the maximum value of each column in the actual output and its corresponding label is extracted in sequence by using the max function, and compared. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by one; thus, the accuracy of the single-layer Bp neural network composed of the weight coefficient matrix W1 obtained by solving the deformation of the equation group model for classifying 10,000 test set pictures is counted;

[0035] Step 4.3.3, directly use the training set images to train the single-layer Bp neural network coefficient matrix W2;

[0036] Step 4.3.4, use the Bp neural network weight coefficient matrix W2 to calculate the actual output Z = F_test * W2 of the single-layer Bp neural network, and use the max function to extract the row number of the maximum value of each column in the actual output and its corresponding label in order, and compare them. If they are the same, it proves that the image is correctly identified, and the number of correctly identified images is increased by one; thus, the accuracy of the single-layer Bp neural network composed of the weight coefficient matrix W2 for classifying 10,000 test set images can be counted;

[0037] Step 4.3.5, compare whether the classification accuracy of the two single-layer BP neural networks composed of the weight coefficient matrix W1 and the weight coefficient matrix W2 for the 10,000 test set images is similar; thereby verifying that the solution of the equation system obtained by optimizing the gradient descent method is equivalent to the coefficient matrix obtained by the single-layer BP neural network.

[0038] Optionally, the coefficient matrix W2 of the single-layer Bp neural network directly trained using the training set images in step 4.3.3 is specifically:

[0039] Step 4.3.3.1, initialize the coefficient matrix W2 to an arbitrary random number matrix that obeys a uniform distribution, give the convergence accuracy T = 0.2 and the learning rate α = 0.1, initialize the matrix row number i = 1, and the number of training epoches = 0;

[0040] Step 4.3.3.2, determine whether i is greater than 60000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first image. If it is still less than 60000, continue with step 4.3.3.3;

[0041] Step 4.3.3.3, assign the i-th row of F_train and B_train to the I variable and the O variable respectively, where the I variable represents the neural network input and the O variable represents the expected output of the neural network;

[0042] Step 4.3.3.4: According to the formula Calculate the actual output Z of the neural network, the I variable represents the neural network input, and W2 is the neural network coefficient matrix;

[0043] Step 4.3.3.5: According to the Bp algorithm formula and ΔW2=I T *δ calculates the change in the weight matrix of this iteration ΔW2; where O is the data set label and also the expected output of the neural network, Z is the actual output of the neural network, S L is the number of neurons in the output layer, which is 10 in the handwritten digit recognition task; δ is an intermediate variable, indicating the impact of the output of this layer on the loss function; I T Indicates converting the neural network input into a row vector;

[0044] Step 4.3.3.6: Update the weight matrix W2 according to the weight matrix update formula.

[0045] W2=W2-α*ΔW2 (2);

[0046] Step 4.3.3.7. Calculate the mean square error (MSE) between the actual output and the expected output of the updated neural network, where M is the number of images in the training set, which is 60,000, and S is L is the number of neurons in the output layer, I i represents the i-th picture, O i The label of the i-th image is the expected output;

[0047]

[0048] Step 4.3.3.8, determine whether the MSE is less than the convergence accuracy T=0.2. If it is satisfied, stop the loop and output the coefficient matrix W2. If it is not satisfied, execute i=i+1 and go to step 4.3.3.2.

[0049] Optionally, the step 5 of constructing an equivalent set of equations model under linear constraints and solving the equations is as follows:

[0050] Step 5.1: Add constraint condition ∑w to the equivalent equation model in step 4 ij =0, where w represents the element in matrix W3, w ij represents the element in the i-th row and j-th column of matrix W3; the meaning of this equation is that the sum of all elements in matrix W3 is 0, and after expressing it as column vector X, the coefficients are all 1; so all the values ​​in the new row of matrix A are assigned to 1, and the corresponding new row of label B column vector is assigned to 0;

[0051] Step 5.2, solve the linear constraint conditional equations model: use the gradient descent iteration method to solve the equations, and also output the trained unknown sequence vector X, and transform the unknown sequence vector X back to the Bp neural network coefficient matrix W3.

[0052] Optionally, the step 6 of using a test set to test the solution of the system of equations with linear constraints is specifically:

[0053] Step 6.1, transform the solution of the linear constraint equation group as the Bp neural network weight coefficient matrix W3 to calculate the actual output of the Bp neural network Z = F_test * W3, and the final Z matrix size is 10000 * 10;

[0054] Step 6.2, since each column in the Bp neural network output represents the output result of a picture, the actual output and the row number of the maximum value of each column in the corresponding label are extracted in sequence by using the max function, and compared. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by one; thus, the accuracy of the equation group model for classifying 10,000 test set pictures is calculated. The solution of the equation group with linear constraint condition is tested using the test set in step 6, specifically:

[0055] Step 6.1, transform the solution of the linear constraint equation group as the Bp neural network weight coefficient matrix W3 to calculate the actual output Z = F_test*W3 of the single-layer Bp neural network, and the final Z matrix size is 10000*10;

[0056] Step 6.2, since each column in the Bp neural network output represents the output result of a picture, the actual output and the row number of the maximum value of each column in its corresponding label are extracted in sequence by using the max function, and compared. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by one; thus, the accuracy of the equation group model in classifying 10,000 test set pictures is calculated. Compared with the prior art, the present invention can obtain the following technical effects:

[0057] The present invention proposes an equivalent system of equations model with a single-layer BP neural network under unconstrained conditions, which is generalizable, and the present invention can easily add linear constraints to the system of equations, and the system of equations can be solved using a simple program. A new idea and method is provided for solving such black box optimization problems with linear constraints, which is applicable to the design optimization and process optimization fields with linear constraints that can be attributed to black box optimization problems in modern management and engineering applications.

[0058] Of course, any product implementing the present invention does not necessarily need to achieve all of the above-mentioned technical effects at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0060] Figure 1 It is a flow chart of the method for constructing an equivalent set of equations model of a single-layer Bp neural network of the present invention;

[0061] Figure 2 The MNIST handwritten digit data set used in the present invention is an example;

[0062] Figure 3 It is a schematic diagram of data set preprocessing according to the present invention;

[0063] Figure 4 It is a schematic diagram of a method for constructing a single-layer Bp neural network equivalent equation group model of the present invention;

[0064] Figure 5 It is the curve of the test set recognition accuracy rate changing with Epoches after the single-layer Bp neural network learning optimization of the present invention;

[0065] Figure 6 It is the curve of the test set recognition accuracy changing with Epoches after the equation group model of the present invention is solved;

[0066] Figure 7 It is a schematic diagram of the construction of a single-layer Bp neural network equivalent equation group model of Example 1 with linear constraints of the present invention. DETAILED DESCRIPTION

[0067] The following will describe the implementation methods of the present invention in detail with reference to the embodiments, so that the implementation process of how the present invention applies technical means to solve technical problems and achieve technical effects can be fully understood and implemented accordingly.

[0068] The present invention discloses a method for constructing an equivalent equation group model of a single-layer BP neural network, such as Figure 1 As shown, the following steps are included:

[0069] Step 1: Preprocess the data set:

[0070] Taking the task of handwritten character recognition as an example, the MNIST dataset is required. The MNIST dataset is an entry-level computer vision dataset that contains 60,000 training images and their corresponding labels and 10,000 test set images and their corresponding labels. The image dataset contains Figure 2 Pictures of various handwritten digits shown.

[0071] The label dataset contains the label values ​​in the form of one-hot encoding that correspond to the images in the image dataset. For example, the label of the number 0 is 100000000. Since the handwritten numbers in the MNIST dataset are stored in the image format of 28*28 pixels, if we want to perform matrix multiplication, we need to preprocess the dataset. Figure 3 As shown, the image data F in the training set and the test set are 28×28 Transformed into a row vector F 1×784 Then store them in columns.

[0072] After the above preprocessing, the training set and test set image samples are named "F_train" and "F_test" respectively. The F_train dataset is a 784×60000 matrix, and the F_test dataset is a 784×10000 matrix. The training set and test set label sets corresponding to the image sample sets are named "B_train" and "B_test" respectively, where the B_train dataset is a 10×60000 matrix, and the B_test dataset is a 10×10000 matrix. It is necessary to encapsulate the pictures and labels of the test set separately, because in machine learning, an independent test dataset is required to evaluate the performance of the model, and to test the model's ability to generalize and generalize by identifying unseen pictures.

[0073] Step 2: Load the training set;

[0074] Taking MATLAB simulation software as an example, using the Load function, inputting commands such as Load('F_train.mat') can load the training set, test set image set and label set into the software workspace.

[0075] Step 3: Read the neural network structure;

[0076] The network structure of a single-layer BP neural network is directly determined by the specific task. Taking handwritten digit recognition as an example, the number of input layer neurons is determined by the amount of input image data. In the previous step, the image is converted into a 784-dimensional row vector, so the number of input layer neurons is 784. The label corresponding to the image is encoded using One-hot. In order to express different types of handwritten digits from 0 to 9, the number of output layer neurons is 10.

[0077] Step 4: Construct an equivalent equation group model, which is implemented by following the steps below:

[0078] Under unconstrained conditions, according to the form of linear non-homogeneous equations: AX = B, using the input image and label value corresponding to the single-layer Bp neural network, write a program to solve the equation model; verify that the solution of the equation is equivalent to the coefficient matrix obtained by optimizing the single-layer Bp neural network using the gradient descent method, specifically,

[0079] Step 4.1, the digit images from 0 to 9 are divided into ten categories, and the label values ​​are encoded in one-hot format, so the label of the digit 0 is 100000000; due to the one-hot encoding format, each bit of the code corresponds to the B term on the right side of an equation, so one image corresponds to ten equations;

[0080] W is the coefficient matrix in the Bp neural network. Usually when using the Bp neural network to train a task, the input image and the corresponding classification label are known, and the size of the coefficient matrix is ​​already determined. By transforming the coefficient matrix W into a column vector X, when the equation system is known to be AX=B, the column vector X is 7840-dimensional, and the column vector B is 10-dimensional, it can be inferred from matrix multiplication that the size of the matrix A is 10 rows and 7840 columns, thereby constructing a specific equation system model of AX=B;

[0081] In the following steps, after numerical iteration, the column vector X is transformed back into the coefficient matrix W using the reshape function, so as to achieve the purpose of solving the coefficient matrix W in the original single-layer Bp neural network with the equivalent equation group model.

[0082] Step 4.2: Use the gradient descent iteration method to solve the system of equations to solve the equivalent system of equations model under unconstrained conditions, which specifically includes the following steps:

[0083] Step 4.2.1. Initialize the unknown number vector X to any random number that obeys a uniform distribution to determine the initial iteration point X. Given the convergence accuracy T = 0.2 and the learning rate α = 0.005, initialize the matrix row number i = 1, and the number of training epoches = 0.

[0084] Step 4.2.2, determine whether i is greater than 600000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first equation. If it is still less than 600000, continue to step 4.2.3;

[0085] Step 4.2.3, select the i-th row of the training set A matrix and the i-th row of the label column vector B. This step actually selects the i-th equation in the system of equations;

[0086] Step 4.2.4: Calculate the value of B when the i-th equation is at point X. i The first partial derivative with respect to X

[0087] Step 4.2.5: According to the gradient descent formula Find the value of the new unknown number X, α is the learning rate, For B i The first partial derivative with respect to X;

[0088] Step 4.2.6, calculate the mean square error (MSE) between the output of the equation system after updating X and the expected output.

[0089]

[0090] Where N is the number of equations in the equation group, which is 600,000 in the handwritten digit recognition task. i represents the i-th row in matrix A, X is the value of the unknown number, B i Represents the i-th row in column vector B.

[0091] Step 4.2.7, determine whether the MSE meets the set convergence accuracy T, if so, go to step 4.2.8, if not, execute i=i+1 and then go to step 4.2.2;

[0092] Step 4.2.8, output the unknown number sequence vector X after training, and transform the unknown number sequence vector X back to the form of the Bp neural network weight coefficient matrix, named W1, that is, the weight coefficient matrix W1 of the solution X of the equivalent equation model under unconstrained conditions after being processed by the reshape function. Take MATLAB software as an example to use the reshape function and execute W1=reshape(X,

[78410] );

[0093] Step 4.3: Verify the equivalence between the system of equations model under unconstrained conditions and the single-layer BP neural network:

[0094] Comparing the recognition accuracy of the network weight coefficient matrix W1 formed by the solution of the conditional equation group under no constraints and the weight matrix W2 trained by the single-layer Bp neural network in the test set, specifically includes the following steps:

[0095] Step 4.3.1, bring the weight coefficient matrix W1 obtained by transforming the unknown number series vector X into the single-layer Bp neural network for testing, calculate the actual output of the single-layer Bp neural network Z = F_test*W1, and the final Z matrix size is 10000*10.

[0096] Step 4.3.2, since each column in the output of the Bp neural network represents the output result of a picture, the max function is used to sequentially extract the row number of the maximum value of each column in the actual output and its corresponding label, and compare them. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by 1. In this way, the accuracy of the single-layer Bp neural network composed of the weight coefficient matrix W1 obtained by solving the deformation of the equation group model for classifying 10,000 test set pictures can be counted.

[0097] Step 4.3.3: Use the training set images to train the single-layer Bp neural network weight coefficient matrix W2 directly:

[0098] Step 4.3.3.1. Initialize the coefficient matrix W2 to an arbitrary random number matrix that obeys a uniform distribution. Given the convergence accuracy T = 0.2 and the learning rate α = 0.1, initialize the matrix row number i = 1, and the number of training epoches = 0.

[0099] Step 4.3.3.2, determine whether i is greater than 60000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first image. If it is still less than 60000, continue with step 4.3.3.3;

[0100] Step 4.3.3.3. Assign the i-th row of F_train and B_train to the I variable and O variable respectively, where the I variable represents the neural network input and the O variable represents the expected output of the neural network.

[0101] Step 4.3.3.4: According to the formula Calculate the actual output Z of the neural network, the I variable represents the neural network input, and W2 is the neural network coefficient matrix.

[0102] Step 4.3.3.5: According to the Bp algorithm formula and ΔW2=I T*δ calculates the change in the weight matrix for this iteration ΔW2. Where O is the data set label and also the expected output of the neural network, Z is the actual output of the neural network, S L is the number of neurons in the output layer, which is 10 in the handwritten digit recognition task. δ is an intermediate variable, which indicates the impact of the output of this layer on the loss function. T Indicates converting the neural network input into a row vector.

[0103] Step 4.3.3.6: Update the weight matrix W2 according to the weight matrix update formula.

[0104] W2=W2-α*ΔW2 (2);

[0105] Step 4.3.3.7. Calculate the mean square error (MSE) between the actual output and the expected output of the updated neural network, where M is the number of images in the training set, which is 60,000, and S is L is the number of neurons in the output layer, I i represents the i-th picture, O i The label of the i-th image is the expected output.

[0106]

[0107] Step 4.3.3.8, determine whether the MSE is less than the convergence accuracy T = 0.2. If it is satisfied, stop the loop and output the coefficient matrix W2. If it is not satisfied, execute i = i + 1 and go to step 4.3.3.2;

[0108] Step 4.3.4, use the Bp neural network weight coefficient matrix W2 to calculate the actual output Z = F_test * W2 of the single-layer Bp neural network, and use the max function to extract the row number of the maximum value of each column in the actual output and its corresponding label in sequence, and compare them. If they are the same, it proves that the image is correctly identified, and the number of correctly identified images is increased by one; thus, the accuracy of the single-layer Bp neural network composed of the weight coefficient matrix W2 in classifying 10,000 test set images can be counted.

[0109] Step 4.3.5: Compare whether the classification accuracy of the two single-layer BP neural networks composed of the weight coefficient matrix W1 and the weight coefficient matrix W2 for the 10,000 test set images is similar. This verifies that the solution of the equation system obtained by the gradient descent method is equivalent to the coefficient matrix obtained by the single-layer BP neural network.

[0110] Step 5: construct an equivalent set of equations model under linear constraints and solve it;

[0111] Step 5.1: Add constraint condition ∑w to the equivalent equation model in step 4 ij=0, where w represents the element in matrix W3, w ij Represents the element in the i-th row and j-th column of matrix W3. The meaning of this equation is that the sum of all elements in matrix W3 is 0, and after expressing it as the column vector X, the coefficients are all 1; so all the new rows of matrix A are assigned 1, and the new row of the corresponding label column vector B is assigned 0;

[0112] Step 5.2: Solve the linear constraint conditional equation model.

[0113] The specific implementation is equivalent to the solution method of step 4.2, using the gradient descent iteration method to solve the equation group, and also outputting the trained unknown sequence vector X, and transforming the unknown sequence vector X back to the Bp neural network coefficient matrix W3;

[0114] Step 6: Use the test set to test the solution of the system of equations with linear constraints. The specific implementation is as follows:

[0115] Step 6.1. Transform the solution of the linear constraint equation group and use it as the Bp neural network weight coefficient matrix W3 to calculate the actual output of the single-layer Bp network Z = F_test*W3. The final Z matrix size is 10000*10.

[0116] Step 6.2: Since each column in the output of the Bp neural network represents the output result of a picture, the max function is used to sequentially extract the row number of the maximum value of each column in the actual output and its corresponding label, and compare them. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by 1. In this way, the accuracy of the equation group model in classifying 10,000 test set pictures can be calculated.

[0117] Example 1

[0118] The construction method is explained by taking the single-layer BP neural network model for recognizing handwritten digits as an example, and the equivalence of the model is illustrated.

[0119] The system of equations is expressed in the form of a matrix: AX = B;

[0120] First, the digits 0 to 9 are divided into ten categories, and the label values ​​are encoded in one-hot format, so the label of the digit 0 is 100000000. Due to the one-hot encoding format, each bit of the encoding corresponds to the B term on the right side of an equation, so one picture corresponds to ten equations; X in the equation system is an unknown number vector, corresponding to the neural network coefficient matrix W. In the construction, this method needs to transform the coefficient matrix W, such as Figure 4As shown, we need to reconstruct W into new column vectors one by one. At the same time, because the column vector X is 7840-dimensional, we can infer from matrix multiplication that the size of matrix A is 10 rows and 7840 columns. To complete the construction of the equation system without changing the learning content of the neural network, we need to fill the matrix A with 0 appropriately. For the specific content of matrix A, please refer to Figure 4 , where A has values ​​only on the diagonal, and F is actually the row vector of the input image reconstructed by columns.

[0121] It should be noted that when Figure 4 The matrix A is filled with 0 except for the position where the row vector F is located. Take the first equation of the system of equations A1X=B1 as an example, where A1 represents the first row of the matrix A and B1 represents the first row of the column vector B. The matrix multiplication of the first row of the matrix A and the unknown column vector X can be divided into two parts. The first part is the multiplication of the row vector F in the first row of the matrix A by the X1 part of the unknown column vector, which is actually equivalent to the multiplication of the row vector input to the neural network and the first column of the neural network coefficient matrix; the second part is the multiplication of the remaining 0 elements in the first row of the matrix A by the other elements in the unknown column vector, and the result must be 0, and then the two parts are summed. Obviously, the other columns do not affect the result of the first equation, and the calculation content of the system of equations model is consistent with the calculation content of the neural network. Such operations ensure the equivalence of the system of equations model and the feedforward neural network.

[0122] After experiments, Figure 5 is the recognition rate of the test set by the single-layer Bp neural network composed of the weight coefficient matrix W2, Figure 6 It is the recognition rate of the single-layer BP neural network for the test set, which is formed by solving X and then deforming the coefficient matrix W1 obtained by the equation group model. The recognition rates of the two are similar, which can prove that the equation group model is a practical and reliable equivalent model of the single-layer BP neural network.

[0123] On this basis, we only need to convert the constraints into a form expressed by the unknown column vector X, convert the coefficient row vector of each constraint into a new row in the matrix A, and put the constraint constant term into a new row in the column vector where the label is located to form a complete set of equations. The remaining work is to solve the system of equations.

[0124] Example 2

[0125] The model of the system of equations with constraints is further illustrated by taking handwritten numbers as an example and adding the linear constraint condition ∑w ij = 0. This example proves that after adding linear constraints, the equation model can still be solved and the solution satisfies the linear constraints.

[0126] The corresponding reference diagram is as follows Figure 7 , the constraint condition ∑w ij=0, after expressing it as column vector X, all coefficients are 1. Therefore, all new rows of matrix A are assigned values ​​of 1, and the new row of the corresponding label B column vector is assigned values ​​of 0.

[0127] Table 1 shows the experimental results of the solution classification of handwritten digits by the equation model after adding linear constraints, and Table 2 shows the experimental results of the solution classification of handwritten digits by the equation model under unconstrained conditions. In the five experiments of the equation model with linear constraints in Table 1, the recognition accuracy of the trained weight coefficient matrix W3 is only slightly lower than the recognition accuracy of the trained weight coefficient matrix W1 under unconstrained conditions in Table 2. However, ∑w in Table 1 ij Approximately close to 0, the weight coefficient matrix optimization in Table 2 is unconstrained, ∑w ij This proves that the single-layer BP neural network equivalent equation group model disclosed in the present invention can conveniently add various linear constraints through the iteration method, is easy to program, and can successfully solve the solution that meets the constraints.

[0128] Table 1 Solution results of the equation set model with constraints

[0129] Experiment No. <![CDATA[∑w ij ]]> Test set accuracy 1 -0.172189566747734 0.8832 2 -0.168805776560580 0.8688 3 -0.144421182230185 0.8755 4 -0.120846124851583 0.8797 5 -0.148417994116522 0.8860

[0130] Table 2 Solution results of the unconstrained equation model

[0131] Experiment No. <![CDATA[∑w ij ]]> Test set accuracy 1 -23.5554061321719 0.9155 2 -23.9626962305931 0.9160 3 -24.3687443706352 0.9161 4 -25.8854278311782 0.9157 5 -30.0647073235074 0.9154

[0132] The present invention proposes a method for constructing a single-layer BP neural network equivalent equation group model. Under unconstrained conditions, the model can achieve a recognition rate almost the same as that of a single-layer BP neural network; under complex linear constraints, the model can clearly express the constraints and solve optimization problems that are difficult to be solved by programming a single-layer BP neural network.

[0133] The above description shows and describes several preferred embodiments of the invention, but as mentioned above, it should be understood that the invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the invention concept described herein through the above teachings or the technology or knowledge of the relevant field. Changes and modifications made by those skilled in the art should be within the scope of protection of the claims attached to the invention without departing from the spirit and scope of the invention.

Claims

1. A method for constructing an equivalent set of equations model of a single-layer BP neural network. It is characterized in that The following steps are involved: Step 1: Preprocess the data set; Step 2: Load the training set; Step 3: Read the neural network structure; Step 4: construct an equivalent set of equations model under unconstrained conditions, solve it, and then verify the equivalence of the equivalent set of equations model under unconstrained conditions and the single-layer BP neural network; Step 5: construct an equivalent set of equations model under linear constraints and solve it; Step 6: Use the test set to test the solution of the system of equations with linear constraints; The preprocessing of the data set in step 1 is specifically as follows: transforming the image data in the training set and the test set of the data set into row vectors and then storing them by column; after the above preprocessing, the image samples of the training set and the test set are named "F_train" and "F_test" respectively; the training set and the test set label sets corresponding to the image sample sets are named "B_train" and "B_test" respectively, and the pictures and labels of the test set are independently packaged; the data set is the MNIST data set; it contains 60,000 training set pictures and their corresponding labels and 10,000 test set pictures and their corresponding labels; The step 2 of loading the training set specifically includes: loading the training set, the test set image set and the label set into the software workspace; The specific structure of the neural network read in step 3 is: the number of neurons in the input layer is equal to the number of pixels in the training set image; the number of neurons in the output layer is the number of categories of the training set image; The step 4 constructs an equivalent set of equations model under unconstrained conditions, solves it, and then verifies the equivalence of the equivalent set of equations model under unconstrained conditions and the single-layer Bp neural network, specifically: Step 4.1: Under unconstrained conditions, according to the linear non-homogeneous equations: AX = B, use the input image and label value corresponding to the single-layer Bp neural network to write a program to solve the equations model, specifically: The digits 0 to 9 are divided into ten categories, and the label values ​​are encoded in one-hot format. Due to the one-hot encoding format, each bit of the code corresponds to the B term on the right side of an equation, so one picture corresponds to ten equations. By transforming the coefficient matrix W into a column vector X, given that the equation system is in the form of AX=B, the column vector X is 7840-dimensional, and the column vector B is 10-dimensional, it can be inferred from matrix multiplication that the size of the matrix A is 10 rows and 7840 columns, thereby constructing a specific equation system model of AX=B; Step 4.2, using the gradient descent iteration method to solve the system of equations to solve the equivalent system of equations model under unconstrained conditions; Step 4.3, verify the equivalence between the system of equations model under unconstrained conditions and the single-layer BP neural network; The step 4.2 uses the gradient descent iteration method to solve the equations to solve the equivalent equation model under unconstrained conditions, specifically: Step 4.2.1, by initializing the unknown number vector X to any random number that obeys uniform distribution, the initial iteration point X is determined, given the convergence accuracy T = 0.2 and the learning rate α = 0.005, the initialization matrix row number i = 1, and the number of training epoches = 0; Step 4.2.2, determine whether i is greater than 600000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first equation. If it is still less than 600000, continue to step 4.2.3; Step 4.2.3, select the i-th row of the training set A matrix and the i-th row of the label column vector B. This actually selects the i-th equation in the system of equations; Step 4.2.4: Calculate the value of B when the i-th equation is at point X. i The first partial derivative with respect to X Step 4.2.5: According to the gradient descent formula Find the value of the new unknown number X, α is the learning rate, For B i The first partial derivative with respect to X; Step 4.2.6, calculate the mean square error (MSE) between the output of the equation system after updating X and the expected output. Where N is the number of equations in the equation group, which is 600,000 in the handwritten digit recognition task. i represents the i-th row in matrix A, X is the value of the unknown number, B i represents the i-th row in column vector B; Step 4.2.7, determine whether the MSE meets the set convergence accuracy T, if so, go to step 4.2.8, if not, execute i=i+1 and then go to step 4.2.2; Step 4.2.8: Output the trained unknown sequence vector X, and transform the unknown sequence vector X back to the Bp neural network coefficient matrix W 1 , using MATLAB software as an example, use the reshape function to execute W 1 = reshape(X,[784 10]); The verification of the equivalence of the system of equations model under unconstrained conditions and the single-layer Bp neural network in step 4.3 is specifically as follows: Step 4.3.1: Transform the weight coefficient matrix W obtained by the unknown number vector X 1 Bring in a single-layer Bp neural network for testing and calculate the actual output of the single-layer Bp network Z = F_test*W 1 ,The final Z matrix size is 10000*10; Step 4.3.2, since each column in the output of the Bp neural network represents the output result of a picture, the max function is used to sequentially extract the row number of the maximum value of each column in the actual output and its corresponding label, and compare them. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by one; thus, the weight coefficient matrix W obtained by solving the deformation of the equation group model is statistically calculated. 1 The accuracy of the single-layer BP neural network in classifying 10,000 test set images; Step 4.3.3: Directly use the training set images to train the single-layer Bp neural network coefficient matrix W 2 ; Step 4.3.4: Use the Bp neural network weight coefficient matrix W 2 Calculate the actual output of a single-layer Bp neural network Z = F_test*W 2 ,By using the max function to sequentially extract the row number of the maximum value of each column in the actual output and its corresponding label, and compare them, if they are the same, it proves that the image is correctly identified, and the number of correctly identified images is increased by one; thus, the weight coefficient matrix W can be counted 2 The accuracy of the single-layer BP neural network in classifying 10,000 test set images; Step 4.3.5: Compare the weight coefficient matrix W 1 and the weight coefficient matrix W 2 Whether the accuracy of classification of 10,000 test set images by two single-layer BP neural networks composed of them is similar; thereby verifying that the solution of the equation group obtained by gradient descent optimization is equivalent to the coefficient matrix obtained by the single-layer BP neural network.

2. The method according to claim 1, It is characterized in that The single-layer Bp neural network coefficient matrix W is trained directly using the training set images in step 4.3.3 2 Specifically: Step 4.3.3.

1. Initialize the coefficient matrix W 2 is an arbitrary random number matrix that obeys uniform distribution, given convergence accuracy T = 0.2 and learning rate α = 0.1, initialization matrix row number i = 1, training times epoches = 0; Step 4.3.3.2, determine whether i is greater than 60000. If so, loop through the entire training set, epoches = epoches + 1, set i = 1, and iterate again from the first image. If it is still less than 60000, continue with step 4.3.3.3; Step 4.3.3.3, assign the i-th row of F_train and B_train to the I variable and the O variable respectively, where the I variable represents the neural network input and the O variable represents the expected output of the neural network; Step 4.3.3.4: According to the formula Calculate the actual output Z of the neural network, I variable represents the neural network input, W 2 is the neural network coefficient matrix; Step 4.3.3.5: According to the Bp algorithm formula and ΔW 2 =I T *δCalculate the change ΔW of the weight matrix for this iteration 2 ; O is the dataset label and also the expected output of the neural network, Z is the actual output of the neural network, S L is the number of neurons in the output layer, which is 10 in the handwritten digit recognition task; δ is an intermediate variable, which indicates the impact of the output of this layer on the loss function; I T Indicates converting the neural network input into a row vector; Step 4.3.3.6: Update the weight matrix W according to the weight matrix update formula 2 , IN 2 =In 2 -α*ΔW 2 (2); Step 4.3.3.

7. Calculate the mean square error (MSE) between the actual output and the expected output of the updated neural network, where M is the number of images in the training set, which is 60,000, and S is L is the number of neurons in the output layer, I i represents the i-th picture, O i The label of the i-th image is the expected output; Step 4.3.3.8: Determine whether the MSE is less than the convergence precision T = 0.

2. If so, stop the loop and output the coefficient matrix W. 2 If it does not satisfy the condition, execute i=i+1 and go to step 4.3.3.

2.

3. The method according to claim 2, It is characterized in that The step 5 of constructing an equivalent set of equations model under linear constraints and solving the equations is as follows: Step 5.1: Add constraint condition ∑w to the equivalent equation model in step 4 ij =0, where w represents the matrix W 3 The elements in w ij Represents the matrix W 3 The element in the i-th row and j-th column; the meaning of this equation is to transform the matrix W 3 All elements in the matrix add up to 0. When expressed as the column vector of X, the coefficients are all 1. Therefore, all new rows of the matrix A are assigned 1, and the corresponding new row of the label B column vector is assigned 0. Step 5.2, solve the linear constraint conditional equations model: use the gradient descent iteration method to solve the equations, and also output the trained unknown sequence vector X, and transform the unknown sequence vector X back to the Bp neural network coefficient matrix W 3 .

4. The method according to claim 3, It is characterized in that The method of using the test set in step 6 to test the solution of the system of equations with linear constraints is as follows: Step 6.1: Transform the solution of the linear constraint equations into the Bp neural network weight coefficient matrix W 3 Calculate the actual output of a single-layer Bp neural network Z = F_test*W 3 ,The final Z matrix size is 10000*10; Step 6.2: Since each column in the Bp neural network output represents the output result of a picture, the max function is used to sequentially extract the row number of the maximum value of each column in the actual output and its corresponding label, and compare them. If they are the same, it proves that the picture is correctly identified, and the number of correctly identified pictures is increased by one; thus, the accuracy of the equation group model in classifying the 10,000 test set pictures is calculated.