Detection method and device for electricity larceny behavior and electronic equipment
An improved residual network, employing multi-scale feature extraction, spatiotemporal feature modeling, and lightweight design, combined with Bayesian optimization and loss function optimization, addresses the accuracy and adaptability issues in electricity theft detection, achieving efficient and accurate detection of electricity theft.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- STATE GRID HEBEI ELECTRIC POWER CO LTD
- Filing Date
- 2025-10-22
- Publication Date
- 2026-04-21
AI Technical Summary
Existing electricity theft detection methods lack accuracy in high-frequency, long-term time-series load data, are difficult to adapt to various load scenarios and anomaly types, and rely on manual feature engineering and hyperparameter tuning, which are inefficient and lack transparency and interpretability.
We employ multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design, and construct a combined loss function by combining weighted cross-entropy loss and focus loss. We also improve the residual network through Bayesian optimization to establish an electricity theft detection model. Finally, we establish an index system using confusion matrix and electricity theft detection threshold.
It improves the accuracy and robustness of electricity theft detection, adapts to different load conditions and anomaly types, provides interpretable and efficient basis for judging detection results, and is suitable for electricity theft detection in smart grids.
Smart Images

Figure CN121903408A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of power grid management technology, and in particular to a method, device, and electronic equipment for detecting electricity theft. Background Technology
[0002] With the rapid development of smart grids and the digital transformation of power systems, the collection and management of electricity consumption data have been significantly improved. However, electricity theft still poses a serious threat to the economic efficiency and reliability of power systems. Electricity theft not only causes huge economic losses to power companies but also seriously affects grid stability and energy equity. Electricity theft is highly concealed and complex, often involving techniques such as tampering with smart meters, interfering with communication signals, or manipulating load characteristics, allowing criminals to evade traditional detection mechanisms. Furthermore, the diverse manifestations of electricity theft under different user profiles, regional conditions, and load scenarios increase the difficulty of detection. Traditional detection methods typically rely on manual detection, rule-based matching, or simple statistical models, which are inefficient and difficult to meet the needs of large-scale, real-time power data processing. Especially in the high-frequency, long-term time-series load data generated by smart grids, electricity theft often manifests as subtle load disturbances or periodic anomalies, posing a greater challenge to the accuracy and sensitivity of existing detection methods. Therefore, developing an efficient, intelligent, and adaptable electricity theft detection method has become a common goal of academia and industry.
[0003] In recent years, the rapid development of machine learning and deep learning technologies has led to significant progress in electricity theft detection. Commonly used machine learning methods include support vector machines and random forests, which utilize supervised learning to extract electricity theft features from historical data, thereby enabling classification or prediction of new datasets. Deep learning models such as convolutional neural networks and long short-term memory networks can automatically extract high-dimensional features from large-scale time-series data, thus reducing reliance on manual feature engineering. While these deep learning methods have improved detection accuracy, they still face some challenges. Patent document CN116432085A discloses a scheme for simultaneously identifying electricity thieves and detecting their theft periods based on a multi-task deep residual network model. This scheme constructs a multi-task adaptive loss based on task uncertainty to balance the tasks of electricity thief identification and theft period detection, improving the accuracy of theft period detection. The deep model built based on multi-task learning and residual networks simplifies the parameters and scale of the electricity thief identification and time period detection models. However, the key feature extraction capability is limited, and the accuracy of electricity theft detection needs further improvement. Summary of the Invention
[0004] This invention provides a method, apparatus, and electronic device for detecting electricity theft, in order to address the problem of how to improve the accuracy of electricity theft detection.
[0005] In a first aspect, embodiments of the present invention provide a method for detecting electricity theft, comprising: We employ multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design to construct a multi-dimensional aggregation structure optimization model, and construct a combined loss function based on weighted cross-entropy loss and focus loss. An improved residual network is obtained based on the structural optimization model and the combined loss function, and the hyperparameters of the improved residual network are tuned using the Bayesian optimization method to obtain an electricity theft detection model. An index system is established based on a confusion matrix and an electricity theft detection threshold, and the detection result of electricity theft behavior is determined according to the electricity theft behavior detection model and the index system.
[0006] In one possible implementation, the multi-scale feature extraction includes: The input feature map is determined as follows X ∈ R H×W×C ,in, H Indicates the channel height. W Indicates the channel width. C Indicates the number of channels; The input feature map is convolved using multiple parallel convolution kernels of different sizes. Batch normalization and ReLU activation operations are performed on the output of each convolution kernel in sequence to obtain features at each scale. Features at each scale are connected along the channel dimension to generate multi-scale features, while maintaining the same number of convolutional kernels at each scale.
[0007] In one possible implementation, the number of parallel convolutional kernels is 3; the size of the parallel convolutional kernels is 3×3, 5×5, and 7×7.
[0008] In one possible implementation, the spatiotemporal feature modeling includes: Determine the features of the input time series as X seq ∈ R T×C ,in T For time steps; C Indicates the number of channels; One-dimensional convolution is used to extract time features from the input time series features. Batch normalization and ReLU activation operations are then performed on the extracted time features to obtain the time features. The temporal features and multi-scale features are weighted and fused.
[0009] In one possible implementation, the channel attention mechanism includes: Input feature mappingX ∈ R H×W×C ,in, H Indicates the channel height. W Indicates the channel width. C Indicates the number of channels; Global average pooling is performed on each channel of the input feature map to compute global features; The global features are used to generate channel weights through a two-layer fully connected network; The channel weights are applied to the input features to generate reweighted input features.
[0010] In one possible implementation, the dynamic adaptive network structure includes: The improved residual network is determined to contain L residual modules, with input features... X ∈ R H×W×C ; Calculate the gate vector using a gating mechanism; The residual module is dynamically activated based on the gated vector.
[0011] In one possible implementation, the lightweight design includes: We employ Depthwise Separable Convolution (DSC) to decompose standard convolution into depthwise convolution and pointwise convolution, which process spatial features and channel features respectively. For the input feature map X ∈ R H×W×C and output feature map Y ∈ R H′×W′×C′ The computational complexity of standard convolution is:
[0012] in, K It is the size of the nucleus. H , W Input channel height and width, H' , W' For the output channel height and width, C Input the number of channels. C' Number of output channels; The computational complexity of DSC is:
[0013] Replace all set convolutions in the improved residual network with DSC.
[0014] In one possible implementation, constructing the combined loss function based on weighted cross-entropy loss and focus loss includes: Construct a weighted cross-entropy loss function and a focus loss function; The weighted cross-entropy loss function and the focus loss function are weighted and fused to obtain the combined loss function; The weighted cross-entropy loss function is:
[0015] in, L WCE The weighted cross-entropy loss; N The total number of samples; y i ∈{0,1} is the first i The true label of each sample y i =1 indicates electricity theft. y i =0 indicates normal power consumption; For the first i The predicted probability that a sample belongs to the category of electricity theft; ω 1 and ω 0 represents the weight of the electricity theft sample and the normal electricity consumption sample, respectively; The focus loss function is:
[0016] in, L FL This is due to scorch damage; γ It is an adjustable parameter. γ ≥0; The combined loss function is:
[0017] in, L This is the combined loss; These are weighting coefficients. .
[0018] In one possible implementation, the step of tuning the hyperparameters of the improved residual network using a Bayesian optimization method includes: Define hyperparameter vector X =[ x 1, x 2, ..., x d Among them, the hyperparameters to be optimized include the learning rate. η Network depth d L2 regularization parameters λ Elimination rate p With sample sizeb ; Using a Gaussian process (GP) to evaluate the objective function Modeling, the modeling equation is:
[0019] in, For hyperparameters The predicted mean of the objective function; For the objective function value and Covariance function of similarity; , σ 2 For amplitude parameters, L For length scale parameters; Expected Improvement (EI) is used as the acquisition function, which guides the next sampling position. The composite objective function is constructed as follows:
[0020] in, The classification accuracy of the model on the validation set; Configuration of hyperparameters The following training time; The maximum training time for all experiments; α For balance coefficient, α ∈[0,1]; A parallel sampling strategy is adopted, and a distributed computing framework is used to evaluate multiple candidate hyperparameter points simultaneously. The search space is dynamically adjusted during the optimization process using a decay factor. β t The shrinkage rate of the search space is controlled until the maximum number of evaluations is reached or the objective function converges; the decay factor update formula is as follows:
[0021] in, t This represents the current iteration number; T max The maximum number of iterations, β min This is the minimum shrinkage ratio.
[0022] In one possible implementation, the establishment of the indicator system based on the confusion matrix and the electricity theft detection threshold includes: Define confusion matrix
[0023] in, This indicates electricity theft; This indicates legitimate electricity theft; This indicates the number of samples whose data on electricity theft users was detected as normal. This indicates the number of samples whose electricity theft user data was detected as abnormal; This indicates the number of normal user data samples that were detected as abnormal. This indicates the number of normal user data samples that were detected as normal. Based on the confusion matrix, construct the following basic evaluation metrics:
[0024]
[0025]
[0026]
[0027] in, Precision For accuracy; indicating Recall For recall rate; when Precision, Recall and F When the overall measurement value is high, it indicates that the model is relatively accurate and effective in detecting electricity theft. The area under the curve (AUC) is calculated based on the receiver operating characteristic (ROC) curve, and the AUC is used to determine the electricity theft detection threshold.
[0028] In one possible implementation, determining the detection result of electricity theft based on the electricity theft detection model and the indicator system includes: Multi-scenario adaptability testing was conducted on the electricity theft detection model: the test set was divided into three operating conditions: high load, medium load, and low load, based on the maximum load value. The model simulates two types of anomalies: sudden anomalies and periodic anomalies, generating the same number of samples for each type. The detection performance of the model under different operating conditions and anomaly types is evaluated using the aforementioned indicator system. Interpretability analysis is used to assist in determining the detection results. The interpretability analysis includes: generating feature heatmaps using Grad-CAM and quantifying the marginal contribution of each input feature to the model output using SHAP.
[0029] Optionally, Grad-CAM is used to generate feature heatmaps, associate the model's focus areas on input features, and identify the time-series load fluctuation range that the model focuses on when detecting electricity theft; SHAP is used to quantify the marginal contribution of each input feature to the model output and generate a global feature importance ranking; combined with multi-scenario test results and interpretability analysis conclusions, the detection results of electricity theft are finally determined.
[0030] Secondly, embodiments of the present invention provide a detection device for electricity theft, comprising: The first building module is used to construct a structure optimization model by multi-dimensional aggregation using multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design, and construct a combined loss function based on weighted cross-entropy loss and focus loss. The second construction module is used to obtain an improved residual network based on the structural optimization model and the combined loss function, and to fine-tune the hyperparameters of the improved residual network using the Bayesian optimization method to obtain an electricity theft detection model. The detection module is used to establish an indicator system based on the confusion matrix and the electricity theft detection threshold, and to determine the detection result of electricity theft behavior according to the electricity theft behavior detection model and the indicator system.
[0031] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect or any possible implementation thereof.
[0032] In this embodiment of the invention, a multi-dimensional aggregation of multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure, and lightweight design can be used to construct a structurally optimized model that is more suitable for the needs of electricity theft detection, effectively enhancing the model's ability to extract features of different scales and dimensions from power load data. Simultaneously, a combined loss function constructed based on weighted cross-entropy loss and focus loss can specifically address the problem of imbalanced sample distribution in electricity theft detection. Further optimization of the hyperparameters of the improved residual network through Bayesian optimization can further enhance the model's detection accuracy and robustness. Finally, an index system established based on the confusion matrix and electricity theft detection threshold can comprehensively evaluate detection performance and provide reliable judgment criteria for detection results, achieving more efficient and accurate detection of electricity theft. Attached Figure Description
[0033] Figure 1 This is a flowchart illustrating the implementation of the detection method for electricity theft provided in this embodiment of the invention. Figure 2 This is a flowchart illustrating a method for detecting electricity theft provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the multi-scale convolution operation and feature extraction process of the residual module provided in this embodiment of the invention; Figure 4 This is a schematic diagram of the channel attention mechanism for dynamically adjusting the importance of feature channels provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of a depth-separable convolution process for processing spatial and channel features separately, provided by an embodiment of the present invention. Figure 6 This is a schematic diagram of the loss function construction for electricity theft detection provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of the structure of the detection device for electricity theft provided in an embodiment of the present invention; Figure 8 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0034] In recent years, the rapid development of machine learning and deep learning technologies has led to significant progress in electricity theft detection. Commonly used machine learning methods include Support Vector Machines (SVMs) and Random Forests, which utilize supervised learning to extract electricity theft features from historical data, thereby enabling classification or prediction of new datasets. SVMs have shown effective performance on small datasets, while Random Forests, due to their ability to evaluate feature importance, have been widely applied to electricity theft detection. However, these methods heavily rely on feature engineering and are highly sensitive to the quality of feature selection and extraction, limiting their performance in large-scale and complex data scenarios. Deep learning models such as Convolutional Neural Networks (CNNs) and Long Short-Term Memory (LSTM) networks can automatically extract high-dimensional features from large-scale time-series data, thereby reducing reliance on manual feature engineering. For example, some studies have used LTM networks to process time-series load data from smart grids, successfully capturing dynamic patterns of electricity theft; other studies have combined the spatial feature extraction capabilities of CNNs to enhance the detection of local anomalies in electricity consumption. While these deep learning methods have improved detection accuracy, they still face several challenges: First, hyperparameter tuning relies on human expertise and lacks systematic and automated methods, which limits the full utilization of model performance; second, insufficient attention is paid to robustness and generalization ability under multiple scenarios, limiting adaptability to different load conditions and anomaly types; third, the "black box" nature of these models reduces transparency and interpretability, making it difficult to meet the power industry's need for clear decision-making criteria.
[0035] In view of this, this invention proposes a novel intelligent detection method for electricity theft based on improved residual networks and Bayesian optimization. First, by integrating the optimized residual block design into a deep network structure, the model's feature extraction capability is enhanced. Then, Bayesian optimization is used to achieve efficient automated hyperparameter tuning, further improving detection performance and efficiency. Finally, an evaluation system for electricity theft detection indicators is established based on the confusion matrix and the electricity theft detection threshold. The adaptability and interpretability of the model in multiple scenarios are studied, providing a reference for practical electricity theft prevention and laying the foundation for intelligent management of power systems and safe operation of smart grids.
[0036] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0037] Figure 1 This is a schematic flowchart illustrating a method for detecting electricity theft provided in an embodiment of the present invention. Figure 1 As shown, it includes the following steps: S101 employs multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design, multi-dimensional aggregation to construct a structural optimization model, and constructs a combined loss function based on weighted cross-entropy loss and focus loss.
[0038] The execution subject of each embodiment of this application can be a server, processor, microprocessor, or other device with data processing capabilities. In actual implementation, the specific implementation method of the execution subject can be selected according to actual needs. This embodiment does not impose any special restrictions on this, as long as it is a device with data processing capabilities.
[0039] In response to the concealment and complexity of electricity theft in smart grids, and to better meet the needs of electricity theft detection tasks, this invention improves the traditional residual network by modifying it in five dimensions: multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure, and lightweight design, thereby aggregating to obtain an optimized model structure.
[0040] In electricity theft detection tasks, the number of normal electricity consumption samples in the dataset is usually much greater than the number of electricity theft samples. This imbalance causes the model to focus primarily on the majority class samples, such as normal electricity consumption, during training, thus ignoring the minority class samples of electricity theft, which adversely affects the performance of electricity theft detection. To address this issue, this invention establishes a weighted cross-entropy loss function based on the traditional cross-entropy loss, and further integrates them into a focus loss function to improve the model's sensitivity to electricity theft samples and its robustness to samples that are difficult to classify.
[0041] S102. An improved residual network is obtained based on a structural optimization model and a combined loss function. The hyperparameters of the improved residual network are then tuned using a Bayesian optimization method to obtain a model for detecting electricity theft.
[0042] Based on Bayesian optimization, a surrogate model between hyperparameters and model performance is constructed using Gaussian processes. This model is then combined with a data acquisition function to balance the search and development processes. A composite objective function and parallel sampling strategy are employed to dynamically adjust the search space during optimization, using a data-driven approach to iteratively optimize hyperparameter configurations and achieve short-time, high-precision prediction of potential optimal configurations. Finally, an improved residual network is integrated with Bayesian optimization to form an electricity theft detection model.
[0043] Figure 2 This is a flowchart illustrating a method for detecting electricity theft according to another embodiment of the present invention. In practical implementation, to verify the electricity theft detection model, performance evaluation indicators such as accuracy, recall, F1 score, and AUC are constructed. Experiments are designed to test different load conditions (high load, medium load, low load) and anomaly types (sudden anomalies, periodic anomalies), and the algorithm complexity and efficiency of the model are analyzed. Furthermore, Grad-CAM and SHAP are used to conduct interpretability studies on the model's decision-making basis.
[0044] S103. An indicator system is established based on the confusion matrix and the electricity theft detection threshold, and the detection results of electricity theft behavior are determined according to the electricity theft behavior detection model and the indicator system.
[0045] In this embodiment, a multi-dimensional aggregation of multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure, and lightweight design enables the construction of a structurally optimized model that is more suitable for electricity theft detection requirements, effectively enhancing the model's ability to extract features of different scales and dimensions from power load data. Simultaneously, a combined loss function constructed based on weighted cross-entropy loss and focus loss can specifically address the problem of imbalanced sample distribution in electricity theft detection. Further optimization of the hyperparameters of the improved residual network through Bayesian optimization further enhances the model's detection accuracy and robustness. Finally, an index system established based on the confusion matrix and electricity theft detection threshold can comprehensively evaluate detection performance and provide reliable judgment criteria for detection results, achieving more efficient and accurate detection of electricity theft.
[0046] The above embodiments summarize the process of the method for detecting electricity theft according to the present invention. The following will elaborate on the construction process of the model and indicator system, as well as the model verification.
[0047] Figure 3 This is a schematic diagram illustrating the multi-scale convolution operation and feature extraction process of the residual module provided in an embodiment of the present invention. In one possible implementation, such as... Figure 3As shown, multi-scale feature extraction includes: The input feature map is determined as follows X ∈ R H×W×C ,in, H Indicates the channel height. W Indicates the channel width. C Indicates the number of channels; Multiple parallel convolutional kernels of different sizes are used to perform convolution operations on the input feature map. Batch normalization and ReLU activation operations are performed on the output of each convolutional kernel in sequence to obtain features at each scale. Features at each scale are connected along the channel dimension to generate multi-scale features, while maintaining the same number of convolutional kernels at each scale.
[0048] In one possible implementation, the number of parallel convolutional kernels is 3; the parallel convolutional kernel sizes are 3×3, 5×5, and 7×7. In other possible implementations, the number of parallel convolutional kernels is 4 or more. Optionally, when the number of parallel convolutional kernels is 4, the convolutional kernel sizes are 3×3, 5×5, 7×7, and 11×11.
[0049] Abnormal characteristics of electricity theft can manifest as short-term changes (such as a sudden drop in power consumption) and long-term changes (such as sustained low load), while traditional single-scale convolutional kernels have limitations in extracting features at different scales. To address this issue, the residual module in this invention combines multi-scale convolution operations, using parallel convolutional kernels of different sizes to capture local and global information from electricity load features.
[0050] Let the input feature map be X ∈ R H×W×C ,in H, W and C These represent the height, width, and number of channels, respectively. Multi-scale convolution operations use kernels of sizes 3×3, 5×5, and 7×7. For example... Figure 3 As shown, the output of each convolution kernel is batch normalized and ReLU activated, as shown in Equation (1): (1) In the formula, Indicates having k × k The kernel performs a convolution operation. The outputs of all kernels are concatenated along the channel dimension to generate a multi-scale feature representation. Y multi As shown in equation (2): (2) In the formula, Concat represents a connection along the channel dimension. In the implementation, the number of channels is set to... C=64, with the same number of kernels at each scale. This multi-scale design enables the simultaneous extraction of local features and long-term load patterns, enhancing the network's ability to adapt to the diversity of power theft.
[0051] In this embodiment, by explicitly defining the dimensional parameters of the input feature map, a clear processing foundation is provided for subsequent feature extraction. Using multiple parallel convolutional kernels of different sizes to convolve the input feature map can capture both local detailed features and global overall features in the electricity load data, overcoming the limitations of traditional single-scale convolutional kernels in feature extraction. Batch normalization operations performed on the output of each convolutional kernel accelerate model training convergence and improve feature stability, while ReLU activation introduces nonlinear transformations, enhancing the model's ability to express complex features. Connecting features at each scale along the channel dimension to generate multi-scale features, while maintaining a consistent number of convolutional kernels at each scale, ensures the balance of features at each scale during fusion, effectively integrating feature information from different scales and laying the foundation for the subsequent model to accurately identify the feature patterns corresponding to electricity theft.
[0052] In one possible implementation, spatiotemporal feature modeling includes: Determine the features of the input time series as X seq ∈ R T×C ,in T For time steps; C Indicates the number of channels; One-dimensional convolution is used to extract time features from the input time series features. Batch normalization and ReLU activation operations are then performed on the extracted time features to obtain the time features. We perform weighted fusion of temporal features and multi-scale features.
[0053] Electricity consumption data is essentially time-series data, and capturing its temporal dynamics is crucial for detecting electricity theft. Therefore, a one-dimensional convolution (1D-CNN) is introduced into each residual module to model the dynamics of the temporal features. Let the input time-series features be... X seq ∈ R T×C ,in T For time steps, C This represents the number of channels. The temporal features extracted using 1D convolution are shown in Equation (3): (3) In the formula, Conv1D represents the kernel size. k t A one-dimensional convolution operation with a resolution of 3 covers three time steps. This local receptive region design captures short-term changes in the time series.
[0054] To integrate spatiotemporal features, a feature fusion strategy is adopted, combining temporal features... Y time and multi-scale features Y multi The weighted sums and combinations are shown in equation (4): (4) In the formula, α and β These are learnable parameters initialized to 0.5 and optimized based on the loss function during training. Y fusion The fusion features provide a comprehensive representation of temporal and spatial information, enhancing the network's ability to detect complex power theft patterns.
[0055] In this embodiment, by explicitly defining the dimensional parameters of the input time series features, the temporal dimension attributes of the power load data are precisely focused. One-dimensional convolution is used to extract the input time series features, effectively capturing the dynamic changes in power load over time, such as short-term sharp load drops or long-term sustained low loads that may result from electricity theft. Batch normalization and ReLU activation operations are performed on the extracted time features to optimize their quality and improve their effectiveness and stability. A feature fusion strategy is employed to weightedly fuse time features with multi-scale features, enabling the model to simultaneously consider both the spatial and temporal dimensions of the power load data. This avoids the detection limitations caused by single-dimensional features, thus more comprehensively capturing the complex patterns that electricity theft may present and improving the model's ability to identify different types of electricity theft.
[0056] Figure 4 This is a schematic diagram of the channel attention mechanism for dynamically adjusting the importance of feature channels provided in an embodiment of the present invention. In one possible implementation, such as... Figure 4 As shown, the channel attention mechanism includes: Input feature mapping X ∈ R H×W×C ; Perform global average pooling on each channel of the input feature map to compute global features; Global features are used to generate channel weights through a two-layer fully connected network; Channel weights are applied to the input features to generate reweighted input features.
[0057] In practice, not all feature channels contribute equally to power theft detection. To dynamically adjust the importance of feature channels, a squeeze-and-excitation (SE) module is embedded in each residual module. The SE module first maps the input features... X ∈ R H×W×C (in, H Indicates the channel height. W Indicates the channel width. C Global average pooling is performed on each channel (representing the number of channels) to compute a global feature representation, as shown in Equation (5): (5) In the formula, z c It is the first c The global feature values of each channel are then used to obtain the global feature values. z c ∈ R C Channel weights are generated using a Layer 2 fully connected network. s c ∈ R C As shown in equation (6): (6) In the formula, δ It is the ReLU activation function; σ Use the Sigmoid activation function; W 1∈ R C / r×C and W 2∈ R C×C / r The weight matrix of the fully connected layer, the reduction ratio r =16. Adjust the channel weights. s c The input features are applied to generate reweighted features, as shown in Equation (7): (7) In the formula, X c Indicates the first element in the input feature map. c The channel's characteristic data. This channel attention mechanism significantly improves sensitivity to key features, effectively distinguishing between normal electricity consumption patterns and electricity theft patterns, such as... Figure 4 As shown.
[0058] In this embodiment, by explicitly defining the dimensional parameters of the input feature map, a clear basis is provided for subsequent channel-level feature optimization. Performing global average pooling on each channel of the input feature map allows for the acquisition of global feature information for each channel, avoiding the bias of local feature information and more comprehensively reflecting the contribution of each channel to electricity theft detection. The global features are then used to generate channel weights through a two-layer fully connected network. This leverages the network's learning ability to adaptively determine the importance of each channel, highlighting channel features crucial for electricity theft detection and suppressing the influence of irrelevant or interfering channels. Applying the generated channel weights to the input features to generate reweighted input features enables the model to focus on feature channels that are significant for identifying electricity theft behavior in subsequent processing, improving feature discriminative power, more accurately distinguishing between normal electricity usage patterns and electricity theft patterns, and reducing detection errors caused by interference from irrelevant channel features.
[0059] In one possible implementation, the dynamically adaptive network structure includes: The improved residual network is determined to contain L residual modules, with input features... X ∈ R H×W×C ; Calculate the gate vector using a gating mechanism; The residual module is dynamically activated based on the gating vector.
[0060] In an optional implementation, the residual modules are dynamically activated based on the gating vector, including: activating more residual modules for samples with significant anomalies; and bypassing some residual modules by skipping connections for normal samples.
[0061] In real-world applications, the complexity and severity of battery theft vary depending on the situation, necessitating dynamic adjustments to the network. Specifically, the network dynamically activates residual modules based on the importance of input features. For exceptionally significant samples, more residual modules are activated to extract deeper features, while normal samples bypass modules by skipping connections to reduce computational complexity. This dynamic structure is implemented using a learnable gating mechanism. Assume the network contains... L Each residual module has the following input features: X ∈ R H ×W×C Then the activation state of the gate is as shown in equation (8): (8) In the formula, G is the gate vector; σ Use the Sigmoid activation function; W g and b gThese are learnable weights and biases. This dynamic activation allows the network to allocate more computational resources to complex inputs while reducing resource usage on simple samples, thereby improving efficiency and adaptability.
[0062] In this embodiment, by explicitly defining the number of residual modules and the dimensional parameters of the input features in the improved residual network, a basic framework for the dynamic adjustment of the network structure is provided. A gating mechanism is used to calculate a gating vector, which can be used to adaptively determine the degree of anomaly of the input sample, such as whether the sample has significant electricity theft characteristics. Based on the gating vector, residual modules are dynamically activated. For samples with significant anomalies, activating more residual modules allows for deeper extraction of the sample's deep features, ensuring accurate identification of complex electricity theft patterns. For normal samples, skipping connections bypasses some residual modules, significantly reducing unnecessary computational overhead. This dynamic adjustment method ensures both the detection accuracy for complex electricity theft samples and effectively controls the model's computational complexity, improving the model's operational efficiency and adaptability in practical applications.
[0063] In one possible implementation, lightweight design includes: We use Depth-Separable Convolution (DSC) to decompose standard convolution into depthwise convolution and pointwise convolution, which process spatial features and channel features respectively. For the input feature map X ∈ R H×W×C and output feature map Y ∈ R H′×W′×C′ The computational complexity of standard convolution is:
[0064] in, K It is the size of the nucleus. H , W Input channel height and width, H' , W' For the output channel height and width, C Input the number of channels. C' Number of output channels; The computational complexity of DSC is:
[0065] Replace all set convolutions in the improved residual network with DSC.
[0066] In the actual operation of electricity theft detection systems, computational resources are typically limited. To address this issue, this invention introduces DSC to reduce computational complexity while maintaining the expressiveness of the model. Compared to standard convolution, DSC decomposes convolution into depthwise convolution and pointwise convolution to process spatial and channel features separately. For the input feature map... X ∈ R H×W×C and output feature map Y ∈ R H′×W′×C′ (in H , W Input channel height and width, H' , W' For the output channel height and width, C Input the number of channels. C' (where the number of output channels is ), the computational complexity of standard convolution is shown in equation (9): (9) In the formula, K It is the size of the kernel. The computational complexity of depthwise separable convolution is, as shown in equation (10): (10) Figure 5 This is a schematic diagram of a depthwise separable convolution process for processing spatial and channel features separately, provided by an embodiment of the present invention. In this process, as... Figure 5 As shown, all 3×3 convolutions are replaced with DSC. This design significantly reduces computational resource requirements while maintaining model performance.
[0067] In this embodiment, standard convolution is decomposed into depthwise convolution and pointwise convolution by employing depthwise separable convolution. This allows the two types of convolution to focus on processing spatial and channel features respectively, significantly reducing computational complexity compared to standard convolution and mathematically reducing the computational resources required for model operation. By clearly defining the dimensional parameters of the input and output feature maps and the difference in computational complexity between the two types of convolution, the advantages of lightweight design are clearly demonstrated. Replacing all predefined convolutions in the improved residual network with depthwise separable convolution effectively reduces the model's computational load and parameter size while maintaining its ability to represent electricity theft features. This solves the problem of limited computational resources in practical electricity theft detection scenarios, making the model easier to deploy on various power system terminals or edge devices, while ensuring that the model's detection performance is not significantly affected by the lightweight design.
[0068] Figure 6 This is a schematic diagram illustrating the construction of the loss function for electricity theft detection provided in an embodiment of the present invention. In one possible implementation, such as... Figure 6As shown, a combined loss function is constructed based on weighted cross-entropy loss and focus loss, including: Construct a weighted cross-entropy loss function and a focus loss function; The weighted cross-entropy loss function and the focus loss function are weighted and fused to obtain the combined loss function.
[0069] Cross-entropy loss is widely used in classification tasks to measure the difference between the predicted probability distribution and the true label distribution. For binary classification problems, the basic form of cross-entropy loss is shown in equation (11): (11) In the formula L CE Represents cross-entropy loss; N The total number of samples; y i ∈{0,1} is the first i The true label of each sample y i =1 indicates electricity theft. y i =0 indicates normal power consumption; For the first i The predicted probability that a sample belongs to the category of electricity theft.
[0070] Cross-entropy loss assigns equal weights to all samples, which is effective for balanced class distributions. However, for highly imbalanced problems, such as electricity theft detection, directly using cross-entropy loss can cause the model to ignore minority class samples.
[0071] To address the class imbalance problem, this invention introduces class weights. ω c Different weights are assigned to the loss contributions of different classes. The weighted cross-entropy loss function is shown in equation (12): (12) In the formula, L WCE The weighted cross-entropy loss; ω 1 and ω 0 represents the weight of the electricity theft sample and the normal electricity consumption sample, respectively.
[0072] Class weight ω c The weights are typically calculated based on the sample proportions to mitigate the effects of class imbalance. Specifically, the weights are calculated as shown in equation (13): (13) In the formula, p c ∈(0,1] is c Class sample proportion;c ∈{0,1} represents the category label. C =0 indicates normal electricity usage. C =1 indicates electricity theft. For example, the normal electricity consumption ratio is... p 0 = 0.95, the electricity theft rate is p If 1 = 0.05, then the weight ω 0、 ω 1. The calculations are shown in equations (14) and (15): (14) (15) This weighting method amplifies the influence of minority class samples in the loss function, thereby improving the model's ability to detect electronic theft.
[0073] While weighted cross-entropy loss addresses the class imbalance problem, during training, the loss contribution from easily classified samples may account for a large portion of the total loss, thus limiting the model's optimization for difficult-to-classify samples. To solve this problem, this invention introduces a focus loss function to reduce the loss weight of easily classified samples, thereby forcing the model to pay more attention to difficult-to-classify samples.
[0074] The focus loss function combined with the class weights is defined as shown in equation (16): (16) In the formula, L FL For burnt damage; γ ≥0 is an adjustable parameter used to control the reduction of loss weights for samples that are easy to classify.
[0075] parameter γ It is usually set to 2, which is an empirical value that can effectively reduce the loss contribution of easily classified samples.
[0076] Finally, this invention employs a combined loss function that combines weighted cross-entropy loss and focus loss, simultaneously addressing the optimization problems of class imbalance and difficult-to-classify samples, such as... Figure 6 As shown. The combined loss function is shown in equation (17): (17) In the formula, L This is the combined loss value; It is a weighting coefficient used to adjust the contribution of weighted cross-entropy loss and focus loss to the total loss. λ The initial value was set to 0.5, and its optimal value was determined through experiments.
[0077] In this embodiment, by constructing a weighted cross-entropy loss function, and using ω1 and ω0 to weight and adjust the losses of electricity theft samples and normal electricity consumption samples respectively, the class imbalance problem in electricity theft detection, where the number of normal samples far exceeds the number of electricity theft samples, can be specifically addressed. This avoids the model from overemphasizing normal samples and ignoring electricity theft samples due to sample imbalance, thus improving the model's sensitivity to minority class samples of electricity theft. An adjustable parameter is introduced by constructing a focus loss function. γ Reducing the loss weights for easily classified samples forces the model to focus its training on difficult-to-classify samples, such as those with ambiguous boundaries, thus improving the model's ability to identify complex or covert electricity theft. Fusing the weighted cross-entropy loss function and the focus loss function with a weighting coefficient λ simultaneously addresses both class imbalance and difficult-to-classify sample issues. This ensures the model doesn't miss any electricity theft samples during training while accurately identifying difficult-to-classify electricity theft patterns, significantly improving the model's detection robustness and reducing the false negative and false positive rates for electricity theft.
[0078] In one possible implementation, Bayesian optimization methods are used to tune the hyperparameters of the improved residual network, including: Define hyperparameter vector X =[ x 1, x 2, ..., x d Among them, the hyperparameters to be optimized include the learning rate. η Network depth d L2 regularization parameters λ Elimination rate p With sample size b ; Using GP to apply the objective function Modeling; EI is used as the acquisition function, which guides the next sampling position. A composite objective function is constructed, and a parallel sampling strategy is adopted to simultaneously evaluate multiple candidate hyperparameter points using a distributed computing framework. During the optimization process, the search space is dynamically adjusted, and the shrinkage rate of the search space is controlled by the decay factor until the maximum number of evaluations is reached or the objective function converges.
[0079] In practice, the goal of Bayesian optimization is to minimize the objective function. First, Bayesian optimization uses General Process (GP) on the objective function. Modeling. GP is a nonparametric probabilistic model for estimating the posterior distribution of a target function. It assumes... Follows the mean function μ ( x and covariance function The multivariate normal distribution is described. The modeling equation is shown in equation (18): (18) In the formula Given hyperparameters The predicted mean of the objective function; It is in the quantization objective function value and Covariance function of similarity. A commonly used covariance function is the radial basis function (RBF), as shown in equation (19): (19) In the formula, σ 2 This is a parameter controlling the magnitude of the variance of the control function value; L It is the length scale parameter that determines the similarity between input points.
[0080] Then Bayesian optimization uses the acquisition function. α ( x The sampling function balances the search for undeveloped areas and the development of high-potential areas to guide the next sampling location. A commonly used sampling function is EI, as shown in equation (20): (20) In the formula, This represents the current optimal objective function value. A higher acquisition function value indicates a higher search priority in subsequent iterations.
[0081] Bayesian optimization is used to tune the hyperparameters of the improved residual network, thereby enhancing its verification performance in electricity theft detection tasks. The hyperparameter vector is defined as follows: X =[ x 1, x 2, ..., x d ], where each dimension represents a hyperparameter to be optimized. Objective function Defined as the verification error, as shown in equation (21): (twenty one) In the formula, This indicates the model's classification accuracy on the validation set. This is a hyperparameter vector.
[0082] The optimized hyperparameters include the learning rate ( η Network depth d L2 regularization parameters λ ), elimination rate ( p ) and sample size ( b ),in ηThis represents the step size for parameter updates during training, and its range on a logarithmic scale is
[10] . -5 10 -1 ]; d This represents the number of remaining blocks in the network, with values selected from {10, 20, 30, 40, 50}. λ The norm constraint representing the control weights is used to prevent overfitting, and its range is
[10] on a logarithmic scale. -6 10 -2 ]; p This represents the proportion of neurons randomly dropped during training, with a value range of [0, 0.5]. b This controls the number of samples used in each parameter update, with values selected from {16, 32, 64, 128}.
[0083] The optimization process begins with Latin hypercube sampling, initializing the model to multiple hyperparameter combinations. The model is trained and evaluated on a validation set for each combination, generating initial objective function values. Based on these points, a Gaussian process surrogate model is constructed to predict the mean and variance of the objective function. The next sampling point is determined using the desired improvement sampling function, and the hyperparameter combination with the highest sampling value is selected for evaluation. This iterative process continues, updating the surrogate model, until the maximum number of evaluations is reached or the objective function converges.
[0084] To further improve the efficiency and effectiveness of Bayesian optimization, this invention proposes the following optimization scheme: First, the validation accuracy and training time are combined into a composite objective function to optimize model performance and training efficiency. Specifically, the objective function is shown in equation (22): (twenty two) In the formula T ( x ) indicates hyperparameter configuration x The following training time; T max The maximum training time for all experiments; α ∈[0,1] is the balance coefficient between control performance and efficiency.
[0085] Secondly, a parallel sampling strategy is adopted, utilizing a distributed computing framework to simultaneously evaluate multiple candidate hyperparameter points, thereby accelerating the optimization process; specifically, a Gaussian process is used to predict the mean of the objective function. μ ( x ) and variance σ 2 ( x And use the batch acquisition function to define the total value of the candidate points, as shown in equation (23): (twenty three) Where EI represents the expected improvement at a single point; k ( x i , x j This quantifies the correlation between points. By optimizing this function, the selection... k The relevant candidate points are identified and assigned to multiple GPUs or CPU cores for parallel training. The surrogate model is updated after each round, which significantly reduces the total time required for hyperparameter optimization.
[0086] Finally, the search space is dynamically adjusted during the optimization process, gradually narrowing it down to the possible optimal region, thereby improving search efficiency. Specifically, in each iteration, the high-potential region where the expected improvement in EI exceeds the threshold is determined, as shown in equation (24): (twenty four) Redefine the search boundary using a decay factor. β t The shrinkage rate of the search space is controlled as shown in equations (25) and (26): (25) (26) In the formula, t This represents the current iteration number; T max The maximum number of iterations, β min This is the minimum shrinkage ratio.
[0087] This approach ensures diversity in the early exploration phase while achieving accuracy in the later search phase, effectively balancing the trade-off between efficiency and global optimality.
[0088] In this embodiment, a Bayesian optimization method is used to tune the hyperparameters of the improved residual network. First, a hyperparameter vector including learning rate and network depth is defined to clarify the optimization object and scope, ensuring coverage of key configurations. Next, a Gaussian process is used to model the objective function, accurately fitting the relationship between hyperparameters and model performance, reducing blind sampling and improving evaluation accuracy. Then, the desired improvement is used as the sampling function to balance "exploring the unknown" and "utilizing the known," avoiding local optima and approximating the potential optimal combination. A composite objective function that balances classification accuracy and training time is then constructed to avoid excessively long training times and meet the efficiency requirements of real-time detection. Afterward, parallel sampling combined with distributed computing is used to simultaneously evaluate multiple candidate points, shortening the tuning time. Finally, the search space is dynamically adjusted using a decay factor to narrow the scope and improve convergence speed. Ultimately, efficient and accurate tuning is achieved, compensating for insufficient basic network parameter configuration and optimizing the performance of the electricity theft detection model.
[0089] In one possible implementation, an indicator system is established based on a confusion matrix and an electricity theft detection threshold, including: Define confusion matrix
[0090] in, This indicates electricity theft; This indicates legitimate electricity theft; This indicates the number of samples whose data on electricity theft users was detected as normal. This indicates the number of samples whose electricity theft user data was detected as abnormal; This indicates the number of normal user data samples that were detected as abnormal. This indicates the number of normal user data samples that were detected as normal. Constructing basic evaluation indicators based on confusion matrices; The area under the ROC curve (AUC) is calculated, and the AUC is used to determine the threshold for detecting electricity theft. The AUC value is between 0.5 and 1. The larger the AUC, the better the detection effect of electricity theft.
[0091] In the specific implementation process, when the electricity theft detection data is unbalanced, the accuracy of the detection model is evaluated by constructing a confusion matrix, as shown in equation (27): (27) In the formula: This indicates electricity theft; This indicates legitimate electricity theft; This indicates the number of samples whose data on electricity theft users was detected as normal. This indicates the number of samples whose electricity theft user data was detected as abnormal; This indicates the number of normal user data samples that were detected as abnormal. This indicates the number of samples from legitimate users that were detected as normal. To improve the effectiveness of electricity theft detection, it is expected that... and The bigger the better, and and The smaller the value, the better. Therefore, a confusion matrix is used to construct precision, recall, and... The measurement indices are shown in equations (28) to (30), and the FPR and TPR values are calculated simultaneously, as shown in equation (31): (28) (29) (30) (31) In the formula, Precision For accuracy; indicating Recall For recall rate; when Precision, Recall and F A higher overall measurement value indicates that the model is more accurate and effective in detecting electricity theft. Furthermore, the selection of the electricity theft detection threshold is crucial; both excessively high and low thresholds can lead to decreased accuracy or even inaccuracy in the detection model. Therefore, this invention uses the AUC index to determine the electricity theft detection threshold. AUC is typically calculated based on the ROC curve, with the horizontal and vertical axes representing FPR and TPR, respectively. The value is the area between the bottom of the ROC curve and the horizontal axis, usually between 0.5 and 1. A higher value indicates better electricity theft detection performance.
[0092] Based on the aforementioned embodiments, this invention proposes multi-scenario applications covering different load conditions and anomaly types, which greatly improves the adaptability and robustness of the model in different scenarios.
[0093] First, for load conditions, the test set was divided into high load (maximum load exceeding 85% of capacity), medium load (maximum load between 50% and 85% of capacity), and low load (maximum load below 50% of capacity) based on the maximum load value. The model's detection performance under each load condition was evaluated using evaluation metrics. Then, for anomaly types, two typical electricity theft anomaly patterns were simulated: one was to simulate sudden anomalies by inserting short-term sharp drops in load values into the time series data; the other was to simulate periodic anomalies by adding a sinusoidal fluctuation pattern to represent periodic load changes. 1000 samples were generated for each anomaly type to evaluate the model's ability to detect different anomaly types. Finally, Grad-CAM and SHAP were used to conduct an interpretability study on the decision-making basis of the model: For Grad-CAM, the generated feature heatmap is associated with the region of interest of the proposed model on the input features. When electricity theft is successfully detected, the model will pay close attention to the load fluctuation within a specific time interval in the time series data; For SHAP, it can further analyze and quantify the marginal contribution of each input feature to the output of the proposed model and generate a ranking of global feature importance, realizing the model's ability to extract effective decision features from the input data.
[0094] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0095] The following are device embodiments of the present invention. For details not described in detail, please refer to the corresponding method embodiments described above.
[0096] Figure 7 A schematic diagram of a detection device for electricity theft provided in an embodiment of the present invention is shown. For ease of explanation, only the parts related to the embodiment of the present invention are shown, and are described in detail below: like Figure 7 As shown, the detection device 7 for electricity theft includes: The first building module 701 is used to construct a structure optimization model by multi-dimensional aggregation using multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design, and construct a combined loss function based on weighted cross-entropy loss and focus loss. The second construction module 702 is used to obtain an improved residual network based on the structural optimization model and the combined loss function, and to fine-tune the hyperparameters of the improved residual network using the Bayesian optimization method to obtain an electricity theft detection model. The detection module 703 is used to establish an indicator system based on the confusion matrix and the electricity theft detection threshold, and to determine the detection result of electricity theft behavior according to the electricity theft behavior detection model and the indicator system.
[0097] In this embodiment of the invention, a multi-dimensional aggregation of multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure, and lightweight design can be used to construct a structurally optimized model that is more suitable for the needs of electricity theft detection, effectively enhancing the model's ability to extract features of different scales and dimensions from power load data. Simultaneously, a combined loss function constructed based on weighted cross-entropy loss and focus loss can specifically address the problem of imbalanced sample distribution in electricity theft detection. Further optimization of the hyperparameters of the improved residual network through Bayesian optimization can further enhance the model's detection accuracy and robustness. Finally, an index system established based on the confusion matrix and electricity theft detection threshold can comprehensively evaluate detection performance and provide reliable judgment criteria for detection results, achieving more efficient and accurate detection of electricity theft.
[0098] Figure 8 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. For example... Figure 8 As shown, the electronic device 8 of this embodiment includes a processor 80 and a memory 81. The memory 81 stores a computer program 82. When the processor 80 executes the computer program 82, it implements the steps in the various method embodiments described above. Alternatively, when the processor 80 executes the computer program 82, it implements the functions of each module / unit in the various device embodiments described above.
[0099] For example, computer program 82 may be divided into one or more modules / units, which are stored in memory 81 and executed by processor 80 to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of computer program 82 in electronic device 8.
[0100] Electronic device 8 may include, but is not limited to, processor 80 and memory 81. Those skilled in the art will understand that... Figure 8 This is merely an example of electronic device 8 and does not constitute a limitation on electronic device 8. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic device 8 may also include input / output devices, network access devices, buses, etc.
[0101] For the sake of simplicity and clarity, only the above-described functional modules / units are used as examples. In practical applications, the functions described above can be assigned to different functional modules / units as needed. These modules / units can be implemented in hardware, software, or a combination of both.
[0102] In the above embodiments, the descriptions of each embodiment have their own emphasis. Parts not detailed or described in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Unless otherwise specified or in conflict with logic, the terminology and / or descriptions between different embodiments are consistent and can be referenced interchangeably. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships.
[0103] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A method for detecting electricity theft, characterized in that, include: We employ multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design to construct a structure optimization model through multi-dimensional aggregation, and construct a combined loss function based on weighted cross-entropy loss and focus loss. An improved residual network is obtained based on the structural optimization model and the combined loss function, and the hyperparameters of the improved residual network are tuned using the Bayesian optimization method to obtain an electricity theft detection model. An index system is established based on a confusion matrix and an electricity theft detection threshold, and the detection result of electricity theft behavior is determined according to the electricity theft behavior detection model and the index system.
2. The method for detecting electricity theft according to claim 1, characterized in that, The multi-scale feature extraction includes: The input feature map is determined as follows X ∈ R H×W×C ,in, H Indicates the channel height. W Indicates the channel width. C Indicates the number of channels; The input feature map is convolved using multiple parallel convolution kernels of different sizes. Batch normalization and ReLU activation operations are performed on the output of each convolution kernel in sequence to obtain features at each scale. Features at each scale are connected along the channel dimension to generate multi-scale features, while maintaining the same number of convolutional kernels at each scale.
3. The method for detecting electricity theft according to claim 2, characterized in that, The spatiotemporal feature modeling includes: Determine the features of the input time series as X seq ∈ R T×C ,in T For time steps; C Indicates the number of channels; One-dimensional convolution is used to extract time features from the input time series features. Batch normalization and ReLU activation operations are then performed on the extracted time features to obtain the time features. The temporal features and multi-scale features are weighted and fused.
4. The method for detecting electricity theft according to claim 3, characterized in that, The channel attention mechanism includes: Input feature mapping X ∈ R H×W×C ; Global average pooling is performed on each channel of the input feature map to compute global features; The global features are used to generate channel weights through a two-layer fully connected network; The channel weights are applied to the input features to generate reweighted input features.
5. The method for detecting electricity theft according to claim 4, characterized in that, The dynamic adaptive network structure includes: The improved residual network is determined to contain L residual modules, with input features... X ∈ R H×W×C ; Calculate the gate vector using a gating mechanism; The residual module is dynamically activated based on the gated vector.
6. The method for detecting electricity theft according to claim 5, characterized in that, The lightweight design includes: We use Depth-Separable Convolution (DSC) to decompose standard convolution into depthwise convolution and pointwise convolution, which process spatial features and channel features respectively. For the input feature map X ∈ R H×W×C and output feature map Y ∈ R H′×W′×C′ The computational complexity of standard convolution is: in, K It is the size of the nucleus. H , W Input the channel height and width. H' , W' For the output channel height and width, C Input the number of channels. C' Number of output channels; The computational complexity of DSC is: Replace all set convolutions in the improved residual network with the DSC.
7. The method for detecting electricity theft according to claim 1, characterized in that, The construction of the combined loss function based on weighted cross-entropy loss and focus loss includes: Construct a weighted cross-entropy loss function and a focus loss function; The weighted cross-entropy loss function and the focus loss function are weighted and fused to obtain the combined loss function; The weighted cross-entropy loss function is: in, L WCE The weighted cross-entropy loss; N The total number of samples; y i ∈{0,1} is the first i The true label of each sample y i =1 indicates electricity theft. y i =0 indicates normal power consumption; For the first i The predicted probability that a sample belongs to the category of electricity theft; ω 1 and ω 0 represents the weight of the electricity theft sample and the normal electricity consumption sample, respectively; The focus loss function is: in, L FL For scorch damage loss; γ It is an adjustable parameter. γ ≥0; The combined loss function is in, L This is the combined loss; These are weighting coefficients. .
8. The method for detecting electricity theft according to claim 1, characterized in that, The indicator system established based on the confusion matrix and the electricity theft detection threshold includes: Define confusion matrix in, This indicates electricity theft; This indicates legitimate electricity theft; This indicates the number of samples whose data on electricity theft users was detected as normal. This indicates the number of samples whose electricity theft user data was detected as abnormal; This indicates the number of normal user data samples that were detected as abnormal. This indicates the number of normal user data samples that were detected as normal. Based on the confusion matrix, construct the following basic evaluation metrics: in, Precision For accuracy; indicating Recall Recall rate; The area under the curve (AUC) is calculated based on the receiver operating characteristic (ROC) curve, and the AUC index is used to determine the electricity theft detection threshold.
9. A detection device for electricity theft, characterized in that, include: The first building module is used to construct a structure optimization model by multi-dimensional aggregation using multi-scale feature extraction, spatiotemporal feature modeling, channel attention mechanism, dynamic adaptive network structure and lightweight design, and construct a combined loss function based on weighted cross-entropy loss and focus loss. The second construction module is used to obtain an improved residual network based on the structural optimization model and the combined loss function, and to fine-tune the hyperparameters of the improved residual network using the Bayesian optimization method to obtain an electricity theft detection model. The detection module is used to establish an indicator system based on the confusion matrix and the electricity theft detection threshold, and to determine the detection result of electricity theft behavior according to the electricity theft behavior detection model and the indicator system.
10. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Electricity stealing user identification and electricity stealing time period detection method
CN116432085A