Neural network external data distribution detection method based on anomaly detection algorithm

Through the neural network external data distribution detection method based on anomaly detection algorithm, the problem of high computational volume of neural networks, sensitive to data distribution and strong dependence on specific tasks in OOD problems is solved, and efficient and accurate OOD detection in unsupervised scenarios is achieved, which is suitable for a variety of application scenarios.

CN120278220APending Publication Date: 2025-07-08SHANXI SANYOUHUO INTELLIGENCE INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510323108.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-19
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

When facing the problem of external data distribution (OOD), existing neural networks have large amounts of computation, sensitive to data distribution, strong dependence on specific tasks, and are difficult to effectively detect in unsupervised scenarios, resulting in insufficient prediction accuracy and reliability.

Method used

The external data distribution detection method of neural network based on anomaly detection algorithm is adopted, including data preprocessing, feature selection, isolated forest algorithm detection, integrated learning and adaptive threshold setting, and the model parameters are dynamically adjusted to adapt to different scenarios.

Benefits of technology

It reduces model complexity and cost, improves prediction accuracy and reliability, expands the scope of application, and is suitable for unsupervised scenarios, adapts to different data distribution and task requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120278220A_ABST
    Figure CN120278220A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of machine learning and artificial intelligence, and particularly relates to a neural network external data distribution detection method based on an anomaly detection algorithm, and the method comprises the following steps: data preprocessing; feature selection: selecting features suitable for abnormal value detection; carrying out abnormal value detection by using an isolated forest algorithm, training the model and carrying out abnormal value detection on test data; integrating a plurality of abnormal value detection algorithms together; a self-adaptive threshold value is determined according to the distribution characteristics of the training data and used for judging an abnormal value, and misjudgment caused by improper threshold value setting is avoided; and dynamically adjusting. By effectively detecting the input which does not belong to the training data distribution, the prediction accuracy and reliability of the model can be remarkably improved. The invention provides a new thought and direction for the development of the machine learning field. By solving the OOD problem, the method is expected to promote application and development of neural networks and other machine learning models in more fields.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical fields of machine learning and artificial intelligence, and particularly relates to a method for detecting the external data distribution of a neural network based on an anomaly detection algorithm. Background Art

[0002] With the continuous development of deep learning technology, neural networks have achieved remarkable results in many fields. However, when neural networks are applied to practical scenarios, they often encounter problems from external data distributions, namely the so-called OOD (Out-of-Distribution) problems. The OOD problem refers to the situation where the prediction results of neural networks are affected by abnormal inputs that do not belong to the training data distribution. This problem may lead to incorrect predictions or decisions in many cases, thus affecting the performance of the entire system.

[0003] In solving the OOD problem, most of the existing methods need to be specifically designed and trained for specific tasks, which undoubtedly increases the complexity and cost of the model. In addition, these methods usually rely on a large amount of labeled data, which is difficult to achieve in some situations (such as unsupervised learning, semi-supervised learning, etc.). Moreover, some OOD detection methods may not work in unsupervised scenarios, which greatly limits the possibility of their practical applications.

[0004] In the existing technologies, common methods include using specialized OOD detection modules, ensemble learning strategies, or statistical-based methods, etc. Although these methods can solve the OOD problem to a certain extent, they all have more or less problems, such as large computational amounts, sensitivity to data distributions, or strong dependence on specific tasks, etc.

[0005] Therefore, how to design a general, effective and computationally efficient OOD detection method is an important challenge currently faced.

[0006] This part can further discuss the problems in the existing technologies. For example: Dependence on labeled data: Many OOD detection methods require a large amount of labeled data to train the model. This may be a challenge in practical applications, especially in scenarios where data is scarce or the labeling cost is high. High model complexity: To improve the accuracy of OOD detection, some methods will increase the model complexity, resulting in higher computational costs and longer training times. Lack of generalization ability: Some OOD detection methods may be very effective for specific data distributions or tasks, but their performance may drop significantly when facing new and unknown distributions. Limitations in unsupervised scenarios: Many existing OOD detection methods require supervised learning strategies, which means they cannot be directly applied to unsupervised learning scenarios. Summary of the Invention

[0007] In view of the technical problems of the above-mentioned existing methods, such as large computational amount, sensitivity to data distribution, or strong dependence on specific tasks, the present invention provides a method for detecting the external data distribution of a neural network based on an anomaly detection algorithm. The method can work in an unsupervised scenario without specific training or adjustment of the model, and can effectively detect whether the input belongs to the distribution of the training data. By achieving this goal, the present invention will help to solve the challenges of neural networks in the OOD problem, improve the prediction accuracy and reliability of the model, reduce the complexity and cost of the model, and expand its application scope.

[0008] To solve the above technical problems, the technical solution adopted by the present invention is as follows:

[0009] A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm, comprising the following steps:

[0010] S1. Data preprocessing: After the output layer of the neural network, first perform data preprocessing, including regularization, standardization or normalization operations, which helps to improve the effect of subsequent outlier detection;

[0011] S2. Feature selection: Select features suitable for outlier detection, use softmax probability as the feature input into the isolation forest for outlier detection; in addition, other features are also considered, including the statistical characteristics of the input data and the activation values of the network layers, to improve the accuracy of OOD detection;

[0012] S3. Outlier detection: Use the isolation forest algorithm for outlier detection, train the model and perform outlier detection on the test data;

[0013] S4. Ensemble learning: Integrate multiple outlier detection algorithms together; use the bagging or boosting method to integrate multiple isolation forest models together for OOD detection;

[0014] S5. Adaptive threshold setting: Determine an adaptive threshold according to the distribution characteristics of the training data for determining outliers, to avoid misjudgment caused by improper threshold setting;

[0015] S6. Dynamic adjustment: Dynamically adjust the parameters or algorithms of OOD detection according to different application scenarios and data distributions; adjust the parameters of the isolation forest model or select different outlier detection algorithms according to the distribution characteristics of the data or the nature of the task.

[0016] The method of data preprocessing in S1 is as follows:

[0017] S1.1. Data cleaning: Identify and remove outliers through statistical methods to avoid their negative impact on model training; for missing data, mean filling, median filling, or mode filling methods can be used to ensure data integrity;

[0018] S1.2. Extract useful features from the original data, including node attributes and time series features, to reduce dimensions and improve model efficiency;

[0019] S1.3. Scale the data to a specific range, which is [0,1] or [-1,1], so that different features have the same scale, thereby avoiding the impact of numerical differences on model training.

[0020] The method for selecting features suitable for outlier detection in S2 is as follows:

[0021] S2.1. Use a deep neural network DNN or other classifiers to predict the softmax probability distribution of samples, where the softmax probability represents the confidence of the model in each category; use the softmax probability as a feature and input it into the Isolation Forest for outlier detection;

[0022] S2.2. Combine the confidence score and activation value, and optimize the OOD detection performance by adjusting the scaling factor of the softmax probability; use the outlier score of the confidence distribution as a supplementary feature to further improve the accuracy of OOD detection;

[0023] S2.3. Randomly select multiple subsample sets to build multiple Isolation Trees. Each Isolation Tree recursively splits data points until all data points are isolated; set parameter optimization, including the number of trees, subsample size, and maximum depth of the tree, and adjust the parameters through the cross-validation method to reduce the false positive rate and false negative rate.

[0024] The method for using the Isolation Forest algorithm for outlier detection in S3 is as follows:

[0025] S3.1. Use the trained model to call the predict() method on the test data to calculate the outlier score for each sample. The outlier score ranges from [0,1], and the closer the score is to 1, the more likely it is to be an outlier; the outlier score is calculated by the following formula:

[0026]

[0027] where: d(x) is the path length from sample x to the root node, and h is the average path length;

[0028] S3.2. Set a threshold according to the outlier score distribution, and mark the samples above the threshold as outliers. The threshold is set to 0.5 or the optimal threshold is determined through cross-validation;

[0029] S3.3. Mark the outliers as -1 and the normal values as 1, and output the results.

[0030] The method of integrating multiple outlier detection algorithms in S4 is as follows:

[0031] S4.1. Perform random sampling with replacement on the original dataset to generate multiple sub-datasets;

[0032] S4.2. Train an isolation forest model for each sub-dataset. The isolation forest model constructs multiple decision trees by randomly selecting features and cut points, and finally forms an integrated model;

[0033] S4.3. Input the data to be detected into all isolation forest models, calculate the outlier scores of each model, and finally integrate the prediction results of all models by voting or averaging to obtain the final OOD detection result.

[0034] The method of adaptive threshold setting in S5 is as follows:

[0035] S5.1. Update the threshold formula: θ = θ + α(μ - θ), where θ is the current threshold; when the data drift exceeds the threshold, recalculate and update the threshold;

[0036] S5.2. When the data drift exceeds the threshold, recalculate and update the threshold; for complex scenarios, introduce machine learning algorithms for prediction and dynamically adjust the threshold according to the prediction results;

[0037] S5.3. When the drift of a data point exceeds the updated threshold, it is determined as an outlier; continuously optimize the threshold through historical data and real-time monitoring results to ensure its adaptability.

[0038] The method of dynamic adjustment in S6 is as follows:

[0039] S6.1. Use historical data for statistical analysis, dynamically adjust the OOD detection threshold through the percentile method, exponential weighted moving average method, etc. to cope with data fluctuations; combine real-time data streams, use the sliding window technique to calculate the threshold in real-time, and combine real-time monitoring and adjustment mechanisms;

[0040] S6.2. Use time series analysis or machine learning models to predict future trends and dynamically adjust the OOD detection threshold;

[0041] S6.3. Combine the event trigger mechanism and dynamic threshold adjustment to improve the accuracy of OOD detection;

[0042] S6.4. Use the binary search method and adaptive heuristic algorithm to optimize the OOD detection threshold to improve the robustness and adaptability of the system;

[0043] S6.5. Dynamically adjust the OOD detection threshold according to the hardware characteristics and business requirements;

[0044] S6.6. Use an interactive adjustment tool to adjust the OOD detection threshold in real time to optimize resource allocation.

[0045] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0046] 1. The present invention reduces the model complexity and cost: Since the present invention does not require specific training or adjustment, the complexity and cost associated with the model can be significantly reduced. This is particularly important for application scenarios with limited resources or those requiring rapid deployment.

[0047] 2. The present invention improves the prediction accuracy and reliability: By effectively detecting inputs that do not belong to the training data distribution, the present invention can significantly improve the prediction accuracy and reliability of the model. This is crucial for many critical task applications, such as autonomous driving, medical diagnosis, and financial risk assessment.

[0048] 3. The present invention expands the application scope: Due to the universality and flexibility of the present invention, it can be widely applied to various fields and scenarios. This not only expands the application scope of neural networks but also provides a more general and effective solution for solving the OOD problem.

[0049] 4. The present invention promotes the development of the machine learning field: The present invention provides new ideas and directions for the development of the machine learning field. By solving the OOD problem, the present invention is expected to promote the application and development of neural networks and other machine learning models in more fields. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only exemplary, and those of ordinary skill in the art can also obtain other implementation drawings based on the provided drawings without creative efforts.

[0051] The structures, ratios, sizes, etc. illustrated in this specification are only used to cooperate with the content disclosed in the specification for those familiar with this technology to understand and read, and are not used to limit the limiting conditions for the implementation of the present invention. Therefore, they do not have technical substance. Any modification of the structure, change of the proportional relationship, or adjustment of the size should still fall within the scope covered by the technical content disclosed in the present invention without affecting the efficacy and purpose that the present invention can achieve.

[0052] Figure 1 It is a schematic diagram of the neural network structure of the present invention;

[0053] Figure 2 This is the softmax probability distribution graph of the present invention;

[0054] Figure 3 This is the structural diagram of the isolation forest model of the present invention;

[0055] Figure 4 This is the flowchart of the OOD detection algorithm of the present invention. Detailed implementation manners

[0056] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. These descriptions are only for further explaining the features and advantages of the present invention, rather than limiting the claims of the present invention; based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present application.

[0057] The following will further describe in detail the specific implementation manners of the present invention in conjunction with the drawings and embodiments. The following embodiments are used to illustrate the present invention, but are not used to limit the scope of the present invention.

[0058] A neural network external data distribution detection method based on an anomaly detection algorithm, as Figures 1-4 shown, includes the following steps:

[0059] Step 1, data preprocessing: After the output layer of the neural network, first perform data preprocessing, including regularization, standardization or normalization operations, which helps to improve the effect of subsequent outlier detection.

[0060] Step 1.1, data cleaning: Identify and delete outliers through statistical methods to avoid their negative impact on model training. For missing data, mean filling, median filling or mode filling methods can be used to ensure data integrity.

[0061] Step 1.2, extract useful features from the original data, including node attributes and time series features, to reduce the dimension and improve the model efficiency.

[0062] Step 1.3, scale the data to a specific range, and the specific range is [0,1] or [-1,1], so that different features have the same scale, thereby avoiding the influence of numerical differences on model training.

[0063] Step 2. Feature Selection: Select features suitable for outlier detection. Use the softmax probability as the feature input into the Isolation Forest for outlier detection. Additionally, other features are also considered, including the statistical characteristics of the input data and the activation values of the network layers, to improve the accuracy of OOD detection.

[0064] Step 2.1. Use a deep neural network DNN or other classifier to predict the softmax probability distribution of the samples. The softmax probability represents the confidence of the model in each class. Use the softmax probability as the feature input into the Isolation Forest for outlier detection.

[0065] Step 2.2. Combine the confidence score and the activation value, and optimize the OOD detection performance by adjusting the scaling factor of the softmax probability. Use the outlier score of the confidence distribution as a supplementary feature to further improve the accuracy of OOD detection.

[0066] Step 2.3. Randomly select multiple subsample sets to build multiple Isolation Trees. Each Isolation Tree recursively divides the data points until all data points are isolated. Set parameter optimization, including the number of trees, the subsample size, and the maximum depth of the tree. Adjust the parameters through the cross-validation method to reduce the false positive rate and the false negative rate.

[0067] Step 3. Outlier Detection: Use the Isolation Forest algorithm for outlier detection, train the model and perform outlier detection on the test data.

[0068] Step 3.1. Use the trained model to call the predict() method on the test data, calculate the outlier score for each sample. The outlier score ranges from [0, 1], and the closer the score is to 1, the more likely it is to be an outlier. The outlier score is calculated by the following formula:

[0069]

[0070] where: d(x) is the path length of the sample x to the root node, and h is the average path length.

[0071] Step 3.2. Set the threshold according to the outlier score distribution, and mark the samples higher than the threshold as outliers. The threshold is set to 0.5 or the optimal threshold is determined through cross-validation.

[0072] Step 3.3. Mark the outliers as -1 and the normal values as 1, and output the results.

[0073] Step 4. Ensemble Learning: Integrate multiple outlier detection algorithms together. Use the bagging or boosting method to integrate multiple Isolation Forest models for OOD detection.

[0074] Step 4.1: Randomly sample the original dataset with replacement to generate multiple sub-datasets.

[0075] Step 4.2: Train an isolation forest model for each sub-dataset. The isolation forest model constructs multiple decision trees by randomly selecting features and cut points, and finally forms an ensemble model.

[0076] Step 4.3: Input the data to be detected into all isolation forest models, calculate the anomaly score of each model, and finally integrate the prediction results of all models by voting or averaging to obtain the final OOD detection result.

[0077] Step 5: Adaptive threshold setting: Determine an adaptive threshold according to the distribution characteristics of the training data to judge outliers and avoid misjudgment caused by improper threshold setting.

[0078] Step 5.1: Update the threshold formula: θ = θ + α(μ - θ), where θ is the current threshold. When the data drift exceeds the threshold, recalculate and update the threshold.

[0079] Step 5.2: When the data drift exceeds the threshold, recalculate and update the threshold. For complex scenarios, introduce machine learning algorithms for prediction and dynamically adjust the threshold according to the prediction results.

[0080] Step 5.3: When the drift of the data point exceeds the updated threshold, it is judged as an anomaly. Continuously optimize the threshold through historical data and real-time monitoring results to ensure its adaptability.

[0081] Step 6: Dynamic adjustment: Dynamically adjust the parameters or algorithms of OOD detection according to different application scenarios and data distributions. Adjust the parameters of the isolation forest model or select different outlier detection algorithms according to the distribution characteristics of the data or the nature of the task.

[0082] Step 6.1: Use historical data for statistical analysis, and dynamically adjust the OOD detection threshold through methods such as the percentile method and the exponentially weighted moving average method to cope with data fluctuations. Combine real-time data streams, use the sliding window technique to calculate the threshold in real time, and combine real-time monitoring and adjustment mechanisms.

[0083] Step 6.2: Use time series analysis or machine learning models to predict future trends and dynamically adjust the OOD detection threshold.

[0084] Step 6.3: Combine the event trigger mechanism and dynamic threshold adjustment to improve the accuracy of OOD detection.

[0085] Step 6.4: Use the binary search method and adaptive heuristic algorithms to optimize the OOD detection threshold and improve the robustness and adaptability of the system.

[0086] Step 6.5: Dynamically adjust the OOD detection threshold according to the hardware characteristics and business requirements.

[0087] Step 6.6: Use an interactive adjustment tool to adjust the OOD detection threshold in real time to optimize resource allocation.

[0088] Example 1:

[0089] Step 1: Prepare the dataset. Collect the training data and test data, and preprocess the data into a format suitable for input to the neural network.

[0090] Step 2: Build an outlier detection model. Use the Isolation Forest algorithm to build the model, input the softmax probability as a feature into the Isolation Forest for outlier detection.

[0091] Step 3: Train the model. Use the training data to train the model and adjust the model parameters to optimize the OOD detection effect.

[0092] Step 4: Test the model. Use the test data to test the trained model and evaluate metrics such as the accuracy, robustness, and computational efficiency of OOD detection.

[0093] Step 5: Optimize and improve. Optimize and improve the model according to the test results to further improve the performance of OOD detection.

[0094] Example 2:

[0095] Step 1: Prepare the dataset. Collect the training data and test data, and preprocess the data into a format suitable for input to the neural network. In this step, regularization techniques can be used to process the data to reduce the impact of outliers.

[0096] Step 2: Feature selection. In addition to using the softmax probability as a feature for outlier detection, other features can also be selected, such as the statistical characteristics of the input data or the activation values of the network layers. These features can more comprehensively reflect the distribution characteristics of the data and improve the accuracy of OOD detection.

[0097] Step 3: Build an outlier detection model. Use an ensemble learning method to integrate multiple Isolation Forest models for OOD detection. For example, the bagging method can be used to integrate multiple Isolation Forest models to improve the accuracy and robustness of OOD detection.

[0098] Step 4: Adaptive threshold setting. Determine an adaptive threshold according to the distribution characteristics of the training data for determining outliers. Specifically, the mean and standard deviation of the softmax probability of the training data can be calculated, and then these statistics can be used to determine the threshold. This can avoid misjudgments in OOD detection due to improper threshold setting.

[0099] Step 5: Dynamically adjust parameters and algorithms. According to different application scenarios and data distributions, dynamically adjust the parameters or algorithms for OOD detection. For example, the parameters of the Isolation Forest model can be adjusted or different outlier detection algorithms can be selected based on the distribution characteristics of the data or the nature of the task. This can better adapt to different actual situations and improve the performance of OOD detection.

[0100] The above only elaborates in detail on the preferred embodiments of the present invention. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those of ordinary skill in the art, various changes can be made without departing from the gist of the present invention, and all such changes should be included within the protection scope of the present invention.

Claims

1. A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm, characterized in that It includes the following steps: S1. Data preprocessing: After the output layer of the neural network, first preprocess the data, including regularization, standardization or normalization operations, which helps to improve the effect of subsequent outlier detection; S2. Feature selection: Select features suitable for outlier detection, use the softmax probability as the feature input into the isolation forest for outlier detection; in addition, other features are also considered, including the statistical characteristics of the input data and the activation values of the network layers, to improve the accuracy of OOD detection; S3. Outlier detection: Use the isolation forest algorithm for outlier detection, train the model and perform outlier detection on the test data; S4. Ensemble learning: Integrate multiple outlier detection algorithms together; use the bagging or boosting method to integrate multiple isolation forest models for OOD detection; S5. Adaptive threshold setting: Determine an adaptive threshold according to the distribution characteristics of the training data for determining outliers, avoiding misjudgment caused by improper threshold setting; S6. Dynamic adjustment: Dynamically adjust the parameters or algorithms of OOD detection according to different application scenarios and data distributions; adjust the parameters of the isolation forest model or select different outlier detection algorithms according to the distribution characteristics of the data or the nature of the task.

2. The method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, wherein The method of data preprocessing in S1 is as follows: S1.

1. Data cleaning: Identify and delete outliers through statistical methods to avoid their negative impact on model training; for missing data, mean filling, median filling or mode filling methods can be used to ensure data integrity; S1.

2. Extract useful features from the original data, including node attributes and time series features, to reduce the dimension and improve the model efficiency; S1.

3. Scale the data to a specific range, and the specific range is [0,1] or [-1,1], so that different features have the same scale, thus avoiding the impact of numerical differences on model training.

3. A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, characterized in that, The method of selecting features suitable for outlier detection in S2 is as follows: S2.

1. Use a deep neural network DNN or other classifiers to predict the softmax probability distribution of the samples, and the softmax probability represents the confidence of the model in each category; input the softmax probability as a feature into the isolation forest for outlier detection; S2.

2. Combine the confidence score and the activation value, and optimize the OOD detection performance by adjusting the scaling factor of the softmax probability; use the outlier score of the confidence distribution as a supplementary feature to further improve the accuracy of OOD detection; S2.

3. Randomly select multiple subsample sets to construct multiple isolation trees. Each isolation tree recursively divides the data points until all data points are isolated; set parameter optimization, including the number of trees, the subsample size and the maximum depth of the tree, and adjust the parameters through the cross-validation method to reduce the false positive rate and the false negative rate.

4. A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, characterized in that, The method of using the isolation forest algorithm for outlier detection in S3 is as follows: S3.

1. Use the trained model to call the predict() method on the test data to calculate the anomaly score for each sample. The anomaly score ranges from [0, 1], and the closer the score is to 1, the more likely it is to be an anomaly. The anomaly score is calculated by the following formula: where: d(x) is the path length from sample x to the root node, and h is the average path length; S3.

2. Set a threshold according to the anomaly score distribution, and mark the samples with scores higher than the threshold as outliers. The threshold is set to 0.5 or the optimal threshold is determined through cross-validation; S3.

3. Mark the outliers as -1 and the normal values as 1, and output the results.

5. A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, characterized in that, The method of integrating multiple outlier detection algorithms in S4 is as follows: S4.

1. Randomly sample the original dataset with replacement to generate multiple sub-datasets; S4.

2. Train an isolation forest model for each sub-dataset. The isolation forest model constructs multiple decision trees by randomly selecting features and cut points, and finally forms an integrated model; S4.

3. Input the data to be detected into all isolation forest models, calculate the anomaly scores of each model, and finally integrate the prediction results of all models by voting or averaging to obtain the final OOD detection result.

6. The method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, wherein The method of adaptive threshold setting in S5 is as follows: S5.

1. Update the threshold formula: θ = θ + α(μ - θ), where θ is the current threshold; when the data drift exceeds the threshold, recalculate and update the threshold; S5.

2. When the data drift exceeds the threshold, recalculate and update the threshold; for complex scenarios, introduce machine learning algorithms for prediction and dynamically adjust the threshold according to the prediction results; S5.

3. When the drift of the data point exceeds the updated threshold, it is determined as an anomaly; continuously optimize the threshold through historical data and real-time monitoring results to ensure its adaptability.

7. A method for detecting the external data distribution of a neural network based on an anomaly detection algorithm according to claim 1, characterized in that, The method of dynamic adjustment in S6 is as follows: S6.

1. Use historical data for statistical analysis, and dynamically adjust the OOD detection threshold through methods such as the percentile method and the exponentially weighted moving average method to cope with data fluctuations; combine real-time data streams, use the sliding window technique to calculate the threshold in real time, and combine real-time monitoring and adjustment mechanisms; S6.

2. Use time series analysis or machine learning models to predict future trends and dynamically adjust the OOD detection threshold; S6.

3. Combine the event trigger mechanism and dynamic threshold adjustment to improve the accuracy of OOD detection; S6.

4. Use the binary search method and adaptive heuristic algorithms to optimize the OOD detection threshold to improve the robustness and adaptability of the system; S6.

5. Dynamically adjust the OOD detection threshold according to hardware characteristics and business requirements; S6.

6. Use an interactive adjustment tool to adjust the OOD detection threshold in real time to optimize resource allocation.