A method for constructing smart contract for blockchain data anomaly detection based on transfer learning

Through a transfer learning method, the hypersphere center and projection matrix of the target blockchain are used to construct the hypersphere objective function of the blockchain to be detected, solving the problem of inaccurate detection results when the number of data samples is small, and achieving higher detection accuracy.

CN119311708BActive Publication Date: 2025-03-14JIANGNAN UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411846286.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-16
Publication Date
2025-03-14
Estimated Expiration
2044-12-16

AI Technical Summary

Technical Problem

In the case of a small number of data samples, the existing blockchain data anomaly detection method has insufficient projection matrix and hypersphere decision boundary, which reduces the accuracy of data anomaly detection results.

Method used

Using a transfer learning-based method, the hypersphere objective function of the blockchain to be detected is constructed by obtaining the target blockchain training set, its hypersphere center and projection matrix. The hypersphere objective function of the blockchain to be detected is optimized using the first migration term, the second migration term, the third migration term and the structural loss regular term to optimize the hypersphere radius and projection matrix to improve the accuracy of the detection results.

Benefits of technology

Even with fewer data samples, more accurate projection matrix and hypersphere decision boundaries can be obtained, which improves the accuracy of data detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311708B_ABST
    Figure CN119311708B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of blockchain technology, and relates to a method for constructing a blockchain data anomaly detection smart contract based on transfer learning. A first migration term is constructed based on the distance between the data sample in the blockchain training set to be detected and the center of the hypersphere of the target blockchain training set after being mapped by its projection matrix; a second migration term is constructed based on the distance between the data sample in the target blockchain training set and the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the blockchain training set to be detected; a third migration term is constructed based on the difference between the projection matrix of the target blockchain training set and the projection matrix of the blockchain training set to be detected; a structural loss regularization term is constructed based on the L2 regularization of the projection matrix of the blockchain training set to be detected; a data anomaly detection model is constructed and solved to obtain the hypersphere radius, hypersphere center and projection matrix of the blockchain training set to be detected; knowledge migration is applied to blockchain data anomaly detection, and the accuracy of blockchain data detection results is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method for constructing a blockchain data anomaly detection smart contract based on transfer learning. Background Art

[0002] Blockchain technology is widely used in finance, supply chain management, copyright protection, identity authentication, and sharing economy due to its decentralization, transparency, and immutability. With the rapid development of blockchain technology, more and more application scenarios have begun to focus on data storage and processing. Although blockchain can ensure the immutability of stored data, it lacks an effective data verification mechanism. Before the data is uploaded to the chain, it is impossible to conduct a comprehensive and in-depth analysis and verification of the data, resulting in the writing of abnormal data, erroneous data, or forged data, which affects the overall quality and system performance of blockchain data, and further misleads the decision-making system that relies on blockchain data, thereby affecting the accuracy and efficiency of related applications. For example, in the financial field, erroneous transaction data may lead to erroneous credit assessments; in medical English, inaccurate case data may affect the diagnosis of the disease and the choice of treatment plans. Therefore, how to effectively identify and prevent abnormal data, erroneous data, or forged data from being written into the blockchain is an urgent problem that needs to be solved.

[0003] The existing blockchain data anomaly detection method uses the Support Vector Data Description (SVDD) method to project the data in the training set to a common subspace using a linear projection matrix. After applying a distribution entropy penalty to the data projected to the subspace, a hypersphere decision boundary containing most normal training samples is established. The hypersphere interface is then used to make decisions on unknown samples. After the linear projection matrix is ​​mapped, the data inside and on the surface of the hypersphere is determined as normal data, and the data outside the hypersphere is determined as abnormal data. However, in actual applications, due to the different block sizes of different blockchains, some blockchains have fewer data samples. For blockchains with fewer data samples, if the existing technology is directly used to construct the hypersphere decision boundary, the insufficient number of samples will result in the final hypersphere decision boundary and projection matrix being inaccurate, reducing the accuracy of the data anomaly detection results. For example, a hospital in Province A needs to construct a gastrointestinal case data anomaly detection hypersphere to detect the accuracy of gastrointestinal case data. However, due to the small number of gastrointestinal case data samples in its data set, the characteristics of the gastrointestinal case data cannot be fully captured when constructing the gastrointestinal case data anomaly detection hypersphere, resulting in low accuracy of the constructed hypersphere boundary and projection matrix, which in turn leads to low accuracy of the detection results when using the hypersphere and projection matrix for subsequent data detection.

[0004] In summary, when the existing blockchain data anomaly methods are used to detect blockchains with a small number of data samples, the resulting projection matrix and hypersphere decision boundary are not accurate enough, which reduces the accuracy of data anomaly detection results. Summary of the invention

[0005] To this end, the technical problem to be solved by the present invention is to overcome the problem that when the blockchain data anomaly method in the prior art is used to detect blockchains with a small number of data samples, the projection matrix and hypersphere decision boundary obtained are not accurate enough, thereby reducing the accuracy of the data anomaly detection results.

[0006] In order to solve the above technical problems, the present invention provides a method for constructing a blockchain data anomaly detection smart contract based on transfer learning, comprising:

[0007] Obtain a target blockchain training set, a projection matrix of the target blockchain training set, a hypersphere center, and a blockchain training set to be detected; wherein the data samples in the target blockchain training set and the data samples in the blockchain training set to be detected are of the same data type;

[0008] The first migration term is constructed based on the distance between the data sample in the blockchain training set to be tested and the center of the hypersphere of the target blockchain training set after being mapped by its projection matrix;

[0009] Construct a second migration term based on the distance between the data sample in the target blockchain training set and the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the blockchain training set to be tested;

[0010] Constructing a third migration term based on the difference between the projection matrix of the target blockchain training set and the projection matrix of the blockchain training set to be tested;

[0011] The structural loss regularization term is constructed based on the projection matrix L2 regularization of the blockchain training set to be tested; wherein, the structural loss regularization term is expressed as:

[0012] ,

[0013] in, represents the structural loss regularization term; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; represents transpose;

[0014] Constructing a hypersphere objective function of the blockchain to be detected based on the weighted sum minimization of the square of the hypersphere radius of the blockchain training set to be detected, the distribution entropy penalty term of all data samples in the blockchain training set to be detected, the first migration term, the second migration term, the third migration term and the structural loss regularization term;

[0015] A data anomaly detection model is constructed based on the hypersphere objective function of the blockchain to be detected and the hypersphere constraint function of the blockchain to be detected. The data anomaly detection model is solved to obtain the hypersphere radius, hypersphere center and projection matrix of the blockchain training set to be detected, so as to detect the data to be detected in the blockchain to be detected.

[0016] Preferably, the first migration term is expressed as:

[0017] ,

[0018] in, represents the first migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the blockchain training set to be tested; Represents the center of the hypersphere of the target blockchain training set.

[0019] Preferably, the second migration term is expressed as:

[0020] ,

[0021] in, represents the second migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; represents the target blockchain training set; Represents the center of the hypersphere of the target blockchain training set.

[0022] Preferably, the third migration term is expressed as:

[0023] ,

[0024] in, represents the third migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the projection matrix of the target blockchain training set.

[0025] Preferably, the hypersphere objective function of the blockchain to be detected is expressed as:

[0026] ,

[0027] in, represents the hypersphere objective function of the blockchain to be tested; Represents the hypersphere radius of the blockchain training set to be tested; Represents the weight parameter of the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; represents the first migration item; represents the weight of the first migration item; represents the second migration item; represents the weight of the second migration item; represents the third migration item; represents the weight of the third migration item; represents the structural loss regularization term; Represents the weight of the structural loss regularization term.

[0028] Preferably, the process of constructing the distribution entropy penalty term of all data samples in the blockchain training set to be tested includes:

[0029] Based on the ratio of the distance between each data sample in the blockchain training set to be detected and the global distribution center after being mapped by its projection matrix and the sum of the distances between all data samples in the blockchain training set to be detected and the global distribution center after being mapped by its projection matrix, the distribution entropy of the data sample is obtained;

[0030] The target distribution entropy penalty item of the data sample is obtained based on the product of the distribution entropy of the data sample and the relaxation factor; the distribution entropy penalty item of all data samples in the blockchain training set to be detected is obtained based on the sum of the target distribution entropy penalty items of all data samples in the blockchain training set to be detected.

[0031] Preferably, the distribution entropy of the data sample is expressed as:

[0032] ,

[0033] in, Indicates the first The distribution entropy of data samples; Indicates the first The distance between a data sample and the center of the global distribution after being mapped by its projection matrix; Indicates the number of data samples in the blockchain training set to be tested;

[0034] The distribution entropy penalty term of all data samples in the blockchain training set to be tested is expressed as:

[0035] ,

[0036] in, Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Indicates the first The relaxation factor for each data sample.

[0037] Preferably, the hypersphere constraint function of the blockchain to be detected is expressed as:

[0038] ,

[0039] in, Indicates the first The vector of data samples after being mapped by its projection matrix; Represents the center of the hypersphere of the blockchain training set to be tested; Represents the radius of the hypersphere of the blockchain training set to be tested; Indicates the first relaxation factor for each data sample; Indicates the number of data samples in the blockchain training set to be tested.

[0040] Preferably, the process of obtaining the projection matrix and the center of the hypersphere of the target blockchain training set includes:

[0041] Use the kernel function to map the data samples in the target blockchain training set to obtain the feature representation of the data samples;

[0042] The target blockchain hypersphere objective function is constructed by minimizing the weighted sum of the hypersphere radius squared of the target blockchain training set and the distribution entropy penalty terms of all data samples in the target blockchain training set;

[0043] The target blockchain hypersphere constraint function is constructed based on the Euclidean distance between the feature representation of each data sample in the target blockchain training set and the center of its hypersphere after being mapped by its projection matrix, which is less than or equal to the sum of the square of its hypersphere radius and the relaxation factor of the data sample;

[0044] The target blockchain hypersphere objective function and the target blockchain hypersphere constraint function are solved to obtain the projection matrix and the hypersphere center of the target blockchain training set.

[0045] The blockchain data anomaly detection smart contract construction method based on transfer learning provided in the present application applies the principle of knowledge transfer to blockchain data anomaly detection. When constructing the hypersphere objective function of the blockchain to be detected, a target blockchain training set with the same data type as that in the blockchain training set to be detected and its hypersphere center and projection matrix are obtained. Since the data types in the two blockchain training sets to be detected are the same, they have the same characteristics when performing data anomaly detection. Therefore, the present application uses the hypersphere center and projection matrix of the target blockchain training set to help construct the hypersphere objective function of the blockchain to be detected: a first migration item is constructed based on the data sample in the blockchain training set to be detected that is closer to the hypersphere center of the target blockchain training set after being mapped by its projection matrix; a migration item is constructed based on the data sample in the target blockchain training set mapped by the projection matrix of the blockchain training set to be detected. The second migration term is constructed by minimizing the gap between the projection matrix of the blockchain training set to be detected and the projection matrix of the target blockchain training set. The structural loss regularization term is constructed based on the L2 regularization of the projection matrix of the blockchain training set to be detected. Finally, the hypersphere objective function of the blockchain to be detected is constructed by minimizing the weighted sum of the square of the hypersphere radius of the blockchain training set to be detected, the distribution entropy penalty term of all data samples in the blockchain training set to be detected, the first migration term, the second migration term, the third migration term and the structural loss regularization term. By migrating the knowledge of the target blockchain to the blockchain to be detected, a more accurate projection matrix and hypersphere decision boundary can be obtained even when the data samples of the blockchain to be detected are small, thereby improving the accuracy of the data detection results in the blockchain to be detected. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:

[0047] Figure 1 A flowchart of a method for constructing a blockchain data anomaly detection smart contract based on transfer learning provided in this application;

[0048] Figure 2 Schematic diagram of the data anomaly detection model architecture provided for this application. DETAILED DESCRIPTION

[0049] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0050] See also Figure 1 , Figure 1 The figure shows a flow chart of a method for constructing a blockchain data anomaly detection smart contract based on transfer learning provided by the present application, which specifically includes:

[0051] S10: Obtain a target blockchain training set, a projection matrix of the target blockchain training set, a hypersphere center, and a blockchain training set to be detected; wherein the data samples in the target blockchain training set and the data samples in the blockchain training set to be detected are of the same data type;

[0052] Specifically, the data samples in the target blockchain training set and the data samples in the to-be-tested blockchain training set are of the same data type means that: the data structures and contents of the data samples in the two blockchain training sets are the same; for example, if the data samples in the target blockchain training set are gastrointestinal case data, then the data samples in the to-be-tested blockchain training set are also gastrointestinal case data; if the data samples in the target blockchain training set are transaction data of a certain commodity, then the data samples in the to-be-tested blockchain training set are also transaction data of the commodity;

[0053] S20: constructing a first migration term based on the distance between the data sample in the blockchain training set to be detected and the center of the hypersphere of the target blockchain training set after being mapped by its projection matrix;

[0054] S30: constructing a second migration term based on the distance between the data sample in the target blockchain training set and the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the blockchain training set to be detected;

[0055] S40: constructing a third migration item based on the difference between the projection matrix of the target blockchain training set and the projection matrix of the blockchain training set to be detected;

[0056] S50: constructing a structural loss regularization term based on the projection matrix L2 regularization of the blockchain training set to be tested;

[0057] S60: constructing a hypersphere objective function of the blockchain to be detected based on the weighted sum minimization of the square of the hypersphere radius of the blockchain to be detected training set, the distribution entropy penalty term of all data samples in the blockchain to be detected training set, the first migration term, the second migration term, the third migration term and the structural loss regularization term;

[0058] S70: A data anomaly detection model is constructed based on the hypersphere objective function of the blockchain to be detected and the hypersphere constraint function of the blockchain to be detected, and the data anomaly detection model is solved to obtain the hypersphere radius, hypersphere center and projection matrix of the blockchain training set to be detected, so as to detect the data to be detected in the blockchain to be detected.

[0059] Specifically, since the data samples in the to-be-detected blockchain training set and the target blockchain training set are of the same type, there are some identical features when performing data anomaly detection. For example, the data samples in the target blockchain training set are gastrointestinal case data from a hospital in Province A, and the data samples in the to-be-detected blockchain training set are gastrointestinal case data from a hospital in Province B. Due to differences in geography and eating habits, the data features of the two training sets are not exactly the same. However, since all data samples are gastrointestinal case data, there are some identical features in the data of the two training sets. Based on this, the present application applies the principle of knowledge transfer to blockchain data anomaly detection, and constructs a hypersphere objective function of the to-be-detected blockchain with the help of the hypersphere parameters (i.e., the hypersphere center and the projection matrix) corresponding to the target blockchain training set. The first transfer function is constructed based on the data samples in the to-be-detected blockchain training set that are closer to the hypersphere center of the target blockchain training set after being mapped by its projection matrix. The first migration term is constructed based on the data samples in the target blockchain training set that are closer to the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the blockchain training set to be tested. The third migration term is constructed based on minimizing the gap between the projection matrix of the blockchain training set to be tested and the projection matrix of the target blockchain training set. The structural loss regularization term is constructed based on the L2 regularization of the projection matrix of the blockchain training set to be tested. Finally, the hypersphere objective function of the blockchain to be tested is constructed based on the weighted sum minimization of the square of the hypersphere radius of the blockchain training set to be tested, the distribution entropy penalty term of all data samples in the blockchain training set to be tested, the first migration term, the second migration term, the third migration term and the structural loss regularization term. By migrating the knowledge of the target blockchain to the blockchain to be tested, even when the data samples of the blockchain to be tested are small, a more accurate projection matrix and hypersphere decision boundary can be obtained, thereby improving the accuracy of the data detection results in the blockchain to be tested.

[0060] Specifically, the first migration item is expressed as:

[0061] ,

[0062] in, represents the first migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the blockchain training set to be tested; Represents the center of the hypersphere of the target blockchain training set.

[0063] The second migration term is expressed as:

[0064] ,

[0065] in, represents the second migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; represents the target blockchain training set; Represents the center of the hypersphere of the target blockchain training set.

[0066] The third migration term is expressed as:

[0067] ,

[0068] in, represents the third migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the projection matrix of the target blockchain training set.

[0069] The structural loss regularization term is expressed as:

[0070] ,

[0071] in, represents the structural loss regularization term; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Indicates transpose.

[0072] Furthermore, the hypersphere objective function of the blockchain to be tested is expressed as:

[0073] ,

[0074] in, represents the hypersphere objective function of the blockchain to be tested; Represents the radius of the hypersphere of the blockchain training set to be tested; Represents the weight parameter of the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; represents the first migration item; represents the weight of the first migration item; represents the second migration item; represents the weight of the second migration item; represents the third migration item; represents the weight of the third migration item; represents the structural loss regularization term; Represents the weight of the structural loss regularization term.

[0075] This application uses the first migration item to ensure that the data samples in the training set of the blockchain to be tested are closer to the center of the hypersphere of the target blockchain training set after being mapped by its projection matrix; uses the second migration item to ensure that the data samples in the target blockchain training set are closer to the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the training set of the blockchain to be tested; uses the third migration item to ensure that the difference between the projection matrix of the target blockchain training set and the projection matrix of the training set of the blockchain to be tested is as small as possible, thereby migrating the knowledge of the target blockchain to the blockchain to be tested, so that the projection matrix of the training set of the blockchain to be tested obtained is more accurate.

[0076] In the traditional SVDD algorithm, the geometric meaning of the slack variable is the distance from the sample outside the hypersphere to the surface of the sphere, and the penalty term Indicates that all slack variables use the same trade-off parameter, which means that all slack variables are considered equally important and receive the same penalty. In fact, from the distribution of samples, samples at different positions have different importance, which means that each sample should be punished differently according to its position. In the OCC problem, the distribution of normal samples plays a decisive role in the data structure. Therefore, in this application, the distance metric is defined according to the global distribution structure of normal samples, and the distance metric is used to evaluate the probability that each sample belongs to a normal sample;

[0077] Specifically, we first define the global distribution center of the normal sample in the subspace , and use the Euclidean distance As arrive Therefore, the calculation formula of the distance between the data sample and the global distribution center after being mapped by the projection matrix is:

[0078] ,

[0079] in, Indicates the first The vector of data samples after being mapped by the projection matrix; Represents the mean of the vectors of all data samples in the blockchain training set to be tested after being mapped by the projection matrix; represents the inner product of vectors; Indicates the first The vector of data samples after being mapped by the projection matrix; Indicates the first The vector of data samples mapped by the projection matrix.

[0080] Furthermore, the probability that each data sample belongs to an abnormal sample is defined by the distance metric, namely:

[0081] ,

[0082] Since the probability value of a data sample belonging to an abnormal sample increases with increases with the increase of As the distance between them increases, the distance between the corresponding normal data sample and the boundary first decreases and then increases, and the uncertainty of the corresponding data sample in the classification shows a trend of first increasing and then decreasing. Therefore, in the embodiment of the present application, information entropy is used to fit this uncertainty trend, and a penalty based on information entropy is designed for each data sample.

[0083] In the field of information theory, entropy is a measure of the information carried by a sample, which can evaluate the uncertainty of information and make a discrete random variable Obey probability distribution , then the information entropy can be defined as:

[0084] .

[0085] Based on the above derivation process, the construction process of the distribution entropy penalty term of all data samples in the training set in the embodiment of the present application includes:

[0086] Based on the ratio of the distance between each data sample in the blockchain training set to be tested and the global distribution center after being mapped by its projection matrix and the sum of the distances between all data samples in the blockchain training set to be tested and the global distribution center after being mapped by its projection matrix, the distribution entropy of the data sample is obtained;

[0087] The target distribution entropy penalty item of the data sample is obtained based on the product of the distribution entropy of the data sample and the relaxation factor; the distribution entropy penalty item of all data samples in the blockchain training set to be tested is obtained based on the sum of the target distribution entropy penalty items of all data samples in the blockchain training set to be tested.

[0088] Specifically, the distribution entropy of the data sample is expressed as:

[0089] ,

[0090] in, Indicates the first The distribution entropy of data samples; Indicates the first The distance between a data sample and the center of the global distribution after being mapped by its projection matrix; Indicates the number of data samples in the blockchain training set to be tested;

[0091] The distribution entropy penalty term of all data samples in the blockchain training set to be tested is expressed as:

[0092] ,

[0093] in, Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Indicates the first The relaxation factor for each data sample.

[0094] It can be seen that when the probability that a data sample belongs to an abnormal sample increases, its distribution entropy first increases and then decreases, which is consistent with the uncertainty trend of normal data samples in classification, so it can be better used as a penalty for each data sample to solve the problem that the traditional SVDD algorithm is too sensitive to the trade-off parameters.

[0095] Specifically, in some embodiments of the present application, the hypersphere constraint function of the blockchain to be detected is expressed as:

[0096] ,

[0097] in, Indicates the first The vector of data samples after being mapped by its projection matrix; Represents the center of the hypersphere of the blockchain training set to be tested; Represents the radius of the hypersphere of the blockchain training set to be tested; Indicates the first relaxation factor for each data sample; Indicates the number of data samples in the blockchain training set to be tested.

[0098] Specifically, in some embodiments of the present application, the process of solving the data anomaly detection model includes:

[0099] Convert the data anomaly detection model into a Lagrangian function:

[0100] ,

[0101] For the projection matrix Q of the blockchain training set to be tested, its theoretical formula is as follows:

[0102] ,

[0103] Taking the derivative of the above formula, we can get:

[0104] ,

[0105] By using the identity transformation method to derive the above formula, that is, setting the above formula to 0 and simplifying it, we can get:

[0106] ,

[0107] in, , represents the identity matrix.

[0108] Solving the problem using the identity transformation method can reduce the algorithmic overhead caused by gradient descent, which can not only speed up model deployment but also reduce the risk of the model finding a local optimal solution.

[0109] like Figure 2 The following is a schematic diagram of the data anomaly detection model architecture. Specifically, the detection of the data to be detected in the blockchain includes:

[0110] The projection matrix of the training set of the blockchain to be tested is used to map the data to be tested in the blockchain to be tested, and the vector of the data to be tested is obtained;

[0111] The Euclidean distance between the vector of the data to be detected and the center of the hypersphere of the blockchain training set to be detected is calculated. If the Euclidean distance is less than or equal to the square of the hypersphere radius of the blockchain training set to be detected, the data to be detected is judged to be normal data. If the Euclidean distance is greater than the square of the hypersphere radius of the blockchain training set to be detected, the data to be detected is judged to be abnormal data.

[0112] Specifically, the calculation formula of the Euclidean distance between the vector of the data to be detected and the center of the hypersphere of the blockchain training set to be detected is:

[0113] ,

[0114] in, The Euclidean distance between the vector of the data to be tested and the center of the hypersphere of the blockchain training set to be tested; A vector representing the data to be detected; Represents the center of the hypersphere of the blockchain training set to be tested.

[0115] Optionally, in some embodiments of the present application, the projection matrix and the center of the hypersphere of the target blockchain training set can be directly obtained using the SVDD method, but the data in practical applications usually has the property of being linearly inseparable, that is, a large number of data samples in the training set cannot be segmented by a simple linear decision boundary. Therefore, the data feature representation obtained by directly projecting the data samples using the linear projection matrix still has linear inseparability, resulting in normal data and abnormal data being mixed together, and it is impossible to use a hypersphere to accurately segment the normal data and abnormal data in the training set, so that the constructed hypersphere boundary is not clear enough. When detecting the data in the blockchain, it is also impossible to effectively segment the normal data and abnormal data, reducing the accuracy of the data anomaly detection results.

[0116] Based on this, in the embodiment of the present application, when obtaining the projection matrix and the hypersphere center of the target blockchain, the kernel function is first used to map the data samples in the target blockchain training set to obtain the data feature representation, and then the target blockchain hypersphere constraint function is constructed based on the target feature vector of each data feature representation mapped by the projection matrix of the target blockchain training set and the hypersphere center of the target blockchain training set. The data is mapped to a high-dimensional space by the kernel technique. The kernel function can be used to make the nonlinear data in the original space linearly separable in the high-dimensional space, so that a hypersphere surface can be used to accurately divide normal data and abnormal data. The projection matrix is ​​then used to map the data feature representation in the high-dimensional space back to the low-dimensional space to obtain the target feature vector, effectively reduce the dimension of the data, extract the main features, and reduce the computational complexity and overfitting problems caused by the high-dimensional data feature representation. Finally, the constraint function is constructed based on the Euclidean distance between the target feature vector of the data sample in the target blockchain training set and the hypersphere center of the target blockchain training set, which solves the linear inseparability of the data, so that the constructed hypersphere can accurately distinguish between normal data and abnormal data, thereby improving the accuracy of the data anomaly detection results.

[0117] Specifically, the process of obtaining the projection matrix and the center of the hypersphere of the target blockchain training set includes:

[0118] Use the kernel function to map the data samples in the target blockchain training set to obtain the feature representation of the data samples;

[0119] The target blockchain hypersphere objective function is constructed by minimizing the weighted sum of the hypersphere radius squared of the target blockchain training set and the distribution entropy penalty terms of all data samples in the target blockchain training set;

[0120] The target blockchain hypersphere constraint function is constructed based on the Euclidean distance between the feature representation of each data sample in the target blockchain training set and the center of its hypersphere after being mapped by its projection matrix, which is less than or equal to the sum of the square of its hypersphere radius and the relaxation factor of the data sample;

[0121] The target blockchain hypersphere objective function and the target blockchain hypersphere constraint function are solved to obtain the projection matrix and hypersphere center of the target blockchain training set.

[0122] Specifically, since the data in the real world is linearly indivisible, in order to overcome this problem, this application uses a kernel function to perform nonlinear mapping on the data samples in the target blockchain training set to obtain the feature representation of the data samples. becomes ; For example, concentric circle data on a two-dimensional plane are linearly inseparable, but by mapping them to three-dimensional space through an appropriate kernel function, they may become linearly separable, so that the two types of data can be separated by a plane.

[0123] Specifically, the characteristics of the data sample are expressed as:

[0124] ,

[0125] in, Indicates the target blockchain training set Feature representation of data samples; represents the kernel function; Indicates the target blockchain training set data samples; , Represents the number of data samples in the target blockchain training set.

[0126] Optionally, the inner product in the feature space is calculated by a kernel function, i.e. ,definition is the corresponding kernel matrix:

[0127] ,

[0128] in, represents the Gaussian kernel bandwidth.

[0129] Furthermore, the projection matrix of the target blockchain training set can be constructed by linearly combining the data in the feature space, i.e. , Represents the projection matrix of the target blockchain training set, represents the linear weight matrix, so it can be derived that:

[0130] ,

[0131] in, Represents the kernel matrix No. List; It can be expressed as In the projection direction Based on this, the target blockchain hypersphere constraint function in the embodiment of the present application can also be expressed as:

[0132] .

[0133] Specifically, although using kernel functions to map data to high-dimensional space can handle linear inseparability problems, it also brings computational complexity and overfitting problems. Or S maps the data from a high-dimensional space to a low-dimensional subspace. By reducing the dimension, the dimension of the data can be reduced while maintaining the main information of the data, thereby reducing the computational complexity and reducing the impact of noise and redundant features on the model. At the same time, the low-dimensional subspace representation helps to extract the main features of the data, thereby constructing a compact decision boundary in the subspace. Therefore, the present application comprehensively utilizes the advantages of high-dimensional space and low-dimensional subspace: by first mapping the data to a high-dimensional space, it can ensure that the original nonlinear data is linearly separable in the high-dimensional space; then, by re-mapping the data in the high-dimensional space to a low-dimensional subspace, the dimension can be effectively reduced, the main features can be extracted, and the computational complexity and feature redundancy problems can be reduced, thereby improving the performance and robustness of the model, so that the constructed hypersphere performs well in processing nonlinear data and anomaly detection.

[0134] Specifically, the target blockchain hypersphere objective function is expressed as:

[0135] ,

[0136] in, represents the target blockchain hypersphere objective function; represents the hypersphere radius of the target blockchain training set; Represents the weight parameter of the distribution entropy penalty term of all data samples in the target blockchain training set; Represents the distribution entropy penalty term of all data samples in the target blockchain training set.

[0137] Furthermore, the process of solving the target blockchain hypersphere objective function and the target blockchain hypersphere constraint function includes:

[0138] Convert the target blockchain hypersphere objective function and the target blockchain hypersphere constraint function into Lagrangian functions:

[0139] ,

[0140] For the above Lagrangian function, a two-step alternating iteration method is used to solve it, specifically:

[0141] The first step is to fix S and solve and , when S is fixed, we can get the representation in the subspace ,Right now , and thus calculate the corresponding weight , By transforming the equation Substituting into the following equation, we can obtain:

[0142] ,

[0143] Step 2: Fix and , solve for S:

[0144] ,

[0145] Solution The partial derivative of S is:

[0146] ,

[0147] Use the gradient descent method to solve S, using The decomposition orthogonalizes and normalizes S, and initializes S using PCA.

[0148] Since the data set for training the data anomaly detection model is unbalanced, in order to evaluate the experimental effect of the method provided in this application, the embodiment of this application adopts the classic geometric mean (GM) and average precision (AP) evaluation indicators to eliminate the problem of abnormally high precision deviation for a large number of samples:

[0149] The geometric mean (GM) represents the geometric mean of sensitivity and specificity, and its calculation formula is:

[0150] ,

[0151] in, It is called sensitivity and recall. It is called specificity and precision;

[0152] ,

[0153] ;

[0154] Average precision (AP) represents the arithmetic mean of sensitivity and specificity, and its calculation formula is:

[0155] .

[0156] The experimental environment parameters in the embodiment of the present application are shown in Table 1:

[0157] Table 1

[0158]

[0159] The parameters of the experimental method and the comparison method are shown in Table 2:

[0160] Table 2

[0161]

[0162] The embodiments of the present application use several classic traditional machine learning algorithms as comparison algorithms, including four variants of support vector data description (SVDD), density weighted support vector data description (DW-SVDD), and subspace support vector data (S-SVDD) description.

[0163] Table 3 shows the mean and variance of the GM classification evaluation index of these algorithms after ten-fold cross validation. As can be seen from Table 3, the blockchain data anomaly detection smart contract construction method based on transfer learning (T-IS-SVDD) provided by this application has better classification performance, better generalization performance and more stable robustness than other algorithms, which reflects that the T-IS-SVDD algorithm has higher accuracy and stability in the field of anomaly detection.

[0164] In addition, the embodiment of the present application also provides a nonlinear version of the T-IS-SVDD algorithm T-IS-SVDD N It is compared with traditional nonlinear algorithms, including position-regularized support vector data description (positionSVDD, P-SVDD) and global plus local regularized support vector data description (Global plus Local SVDD, GL-SVDD). Table 4 shows the mean and variance of the GM classification evaluation index of these algorithms after ten-fold cross validation. By comparing the data in Table 3 and Table 4, it can be seen that T-IS-SVDD N The performance is comparable to that of T-IS-SVDD, indicating that the method combining knowledge transfer and nonlinear projection provided in this application has good data anomaly detection performance.

[0165] Table 3

[0166]

[0167] Table 4

[0168]

[0169] In addition, the dataset used by the target blockchain in this experiment comes from the dataset on the UCI public dataset website (https: / / archive.ics.uci.edu / ml). In order to simulate the application scenario of the dataset, the experiment processed and divided the data, as shown in Table 5. In the experiment, the training set and the test set were divided in a ratio of 7:3, and the parameters were determined by ten-fold cross validation. The data features were normalized and mapped to the range of [-1,1].

[0170] Table 5

[0171]

[0172] The above data is used to construct the anomaly detection hypersphere of the target blockchain, obtain its hypersphere center and projection matrix, and then add Gaussian white noise with a signal-to-noise ratio of 20dB to the original data to obtain the blockchain training set to be detected.

[0173] During the formal training of the model, the cross-validation parameter optimization range is continuously adjusted by observing the results of each training to avoid overfitting caused by overly complex parameter models and improve the generalization ability of the model. In practical applications, by deploying T-IS-SVDD on the blockchain in the form of smart contracts, when new data is to be stored on the blockchain, it is first judged as abnormal to determine its legitimacy, which reduces the cost and risk of manual intervention, improves the efficiency and reliability of the blockchain system, and provides a strong guarantee for the application and development of blockchain technology in more fields.

[0174] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0175] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0176] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.

[0177] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0178] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.

Claims

1. A method for constructing a smart contract for blockchain data anomaly detection based on transfer learning, characterized in that: include: Obtain a target blockchain training set, a projection matrix of the target blockchain training set, a hypersphere center, and a blockchain training set to be detected; wherein the data samples in the target blockchain training set and the data samples in the blockchain training set to be detected are of the same data type; The first migration term is constructed based on the distance between the data sample in the blockchain training set to be tested and the center of the hypersphere of the target blockchain training set after being mapped by its projection matrix; Construct a second migration term based on the distance between the data sample in the target blockchain training set and the center of the hypersphere of the target blockchain training set after being mapped by the projection matrix of the blockchain training set to be tested; Constructing a third migration term based on the difference between the projection matrix of the target blockchain training set and the projection matrix of the blockchain training set to be tested; The structural loss regularization term is constructed based on the projection matrix L2 regularization of the blockchain training set to be tested; wherein, the structural loss regularization term is expressed as: , in, represents the structural loss regularization term; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; represents transpose; Constructing a hypersphere objective function of the blockchain to be detected based on the weighted sum minimization of the square of the hypersphere radius of the blockchain training set to be detected, the distribution entropy penalty term of all data samples in the blockchain training set to be detected, the first migration term, the second migration term, the third migration term and the structural loss regularization term; A data anomaly detection model is constructed based on the hypersphere objective function of the blockchain to be detected and the hypersphere constraint function of the blockchain to be detected. The data anomaly detection model is solved to obtain the hypersphere radius, hypersphere center and projection matrix of the blockchain training set to be detected, so as to detect the data to be detected in the blockchain to be detected.

2. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The first migration term is expressed as: , in, represents the first migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the blockchain training set to be tested; Represents the center of the hypersphere of the target blockchain training set.

3. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The second migration term is expressed as: , in, represents the second migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; represents the target blockchain training set; Represents the center of the hypersphere of the target blockchain training set.

4. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The third migration term is expressed as: , in, represents the third migration item; It means finding the trace of a matrix; Represents the projection matrix of the blockchain training set to be tested; Represents the projection matrix of the target blockchain training set.

5. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The hypersphere objective function of the blockchain to be detected is expressed as: , in, represents the hypersphere objective function of the blockchain to be tested; Represents the radius of the hypersphere of the blockchain training set to be tested; Represents the weight parameter of the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; represents the first migration item; represents the weight of the first migration item; represents the second migration item; represents the weight of the second migration item; represents the third migration item; represents the weight of the third migration item; represents the structural loss regularization term; Represents the weight of the structural loss regularization term.

6. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The construction process of the distribution entropy penalty term of all data samples in the blockchain training set to be tested includes: Based on the ratio of the distance between each data sample in the blockchain training set to be detected and the global distribution center after being mapped by its projection matrix and the sum of the distances between all data samples in the blockchain training set to be detected and the global distribution center after being mapped by its projection matrix, the distribution entropy of the data sample is obtained; The target distribution entropy penalty item of the data sample is obtained based on the product of the distribution entropy of the data sample and the relaxation factor; the distribution entropy penalty item of all data samples in the blockchain training set to be detected is obtained based on the sum of the target distribution entropy penalty items of all data samples in the blockchain training set to be detected.

7. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 6 is characterized in that: The distribution entropy of the data sample is expressed as: , in, Indicates the first The distribution entropy of data samples; Indicates the first The distance between a data sample and the center of the global distribution after being mapped by its projection matrix; Indicates the number of data samples in the blockchain training set to be tested; The distribution entropy penalty term of all data samples in the blockchain training set to be tested is expressed as: , in, Represents the distribution entropy penalty term of all data samples in the blockchain training set to be tested; Indicates the first The relaxation factor for each data sample.

8. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The hypersphere constraint function of the blockchain to be tested is expressed as: , in, Indicates the first The vector of data samples after being mapped by its projection matrix; Represents the center of the hypersphere of the blockchain training set to be tested; Represents the radius of the hypersphere of the blockchain training set to be tested; Indicates the first relaxation factor for each data sample; Indicates the number of data samples in the blockchain training set to be tested.

9. The method for constructing a blockchain data anomaly detection smart contract based on transfer learning according to claim 1 is characterized in that: The process of obtaining the projection matrix and the center of the hypersphere of the target blockchain training set includes: Use the kernel function to map the data samples in the target blockchain training set to obtain the feature representation of the data samples; The target blockchain hypersphere objective function is constructed by minimizing the weighted sum of the hypersphere radius squared of the target blockchain training set and the distribution entropy penalty terms of all data samples in the target blockchain training set; The target blockchain hypersphere constraint function is constructed based on the Euclidean distance between the feature representation of each data sample in the target blockchain training set and the center of its hypersphere after being mapped by its projection matrix, which is less than or equal to the sum of the square of its hypersphere radius and the relaxation factor of the data sample; The target blockchain hypersphere objective function and the target blockchain hypersphere constraint function are solved to obtain the projection matrix and the hypersphere center of the target blockchain training set.

Citation Information

Patent Citations

  • Incremental learning distributed computing method, system and node based on block chain

    CN111639368A

  • Block chain multi-modal data anomaly detection method

    CN118468346A