An intervention effect counterfactual prediction method and device under time series

By combining variational inference techniques with time series models and obtaining latent variables as input, the heterogeneity problem caused by factors not being observed in historical records in time series models is solved, thereby improving the prediction accuracy of intervention effects and the ability to assess risks.

CN122153290APending Publication Date: 2026-06-05TSINGHUA UNIVERSITY

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TSINGHUA UNIVERSITY
Filing Date
2026-02-05
Publication Date
2026-06-05

Smart Images

  • Figure CN122153290A_ABST
    Figure CN122153290A_ABST
Patent Text Reader

Abstract

The present application provides an intervention effect counterfactual prediction method and device under time sequence, the method comprises: in the field to be predicted intervention effect, obtain a plurality of historical samples to constitute a training data set, the historical sample contains the feature of historical time, the intervention accepted and the effect corresponding to the occurrence;Build an intervention effect counterfactual prediction model, including: time sequence submodel, hidden variable storage unit, hidden variable encoder, effect predictor;After training the intervention effect counterfactual prediction model using the training data set, the features of the to-be-predicted sample at the to-be-predicted time and each time before, the intervention accepted, the effect occurred at each time before are input into the model, and the prediction result of the effect at the to-be-predicted time is obtained.The present application learns potential factors for each sample by using variational inference technology combined with time sequence model, and obtains hidden variables;The hidden variables are used as additional inputs of the effect predictor, and the counterfactual prediction accuracy of different intervention effects can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of causal reasoning and counterfactual prediction, and specifically relates to a method and apparatus for counterfactual prediction of intervention effects in time series. Background Technology

[0002] Decision-making problems are prevalent in numerous applications, such as healthcare and financial marketing. Therefore, predicting counterfactual outcomes of different intervention options to aid decision-making is crucial. The high cost and time commitment of real-world trials have led researchers to attempt to learn from large amounts of observational data to achieve this goal. In some scenarios, decision-making problems are static, meaning there is only one decision and its effect. However, in many scenarios, decision-making problems can be more complex and span multiple time points. Therefore, it is necessary to predict counterfactual effects at different times, rather than outcomes at a single moment.

[0003] Because the scale of historical feature information varies across time periods, methods developed for static scenarios cannot be directly applied. To bridge this gap caused by task characteristics, some methods employ time series models, such as Long Short-Term Memory networks and Transformers, to characterize the temporal dependence between long history and effects. Typically, these approaches utilize time series models to extract a representation from historical information, in which features serve as samples. The effect prediction module uses the learned representation and counterfactual interventions to predict counterfactual effects. Based on this design, techniques for eliminating intervention selection bias in static scenarios can be used to achieve more accurate effect predictions in time series scenarios.

[0004] This approach attributes the heterogeneity of effects between samples to historical observed variables in the dataset. It assumes that all factors related to the effect are recorded in the features of the historical data. However, this premise does not hold true in many scenarios. There may be factors in the historical data that are not observed, yet they can still influence the outcome. For example, in medical settings, some factors crucial to a patient's treatment cannot be accurately measured due to limitations in detection methods. Therefore, predicting heterogeneous effects between different samples solely based on historical observations may overlook differences in effects between samples under the same observed variables (i.e., heterogeneity in effect generation). Ignoring these potential differences in effects makes the prediction a crude approximation, thus degrading predictive performance. Summary of the Invention

[0005] The purpose of this invention is to overcome the shortcomings of existing technologies and propose a method and apparatus for counterfactual prediction of intervention effects in time series data. This invention addresses the problem of insufficient predictive power of recorded observational attributes for intervention effects due to the difficulty in observing all attribute characteristics of individual samples in real-world scenarios. It tackles the hidden heterogeneity problem by revealing hidden factors and capturing effect differences that cannot be characterized by observed features. By using variational inference techniques combined with time series models, latent factors are learned for each sample to obtain latent variables. Using these latent variables as additional input to the effect predictor improves the accuracy of counterfactual predictions of different intervention effects. This invention can assist in time-series decision-making in fields such as medicine and finance and has high application value.

[0006] A first aspect of this invention proposes a counterfactual prediction method for intervention effects in time series, comprising:

[0007] In the domain where the intervention effect is to be predicted, a training dataset is formed by acquiring multiple historical samples. The historical samples contain the features of the historical moment, the intervention received, and the corresponding effect.

[0008] A counterfactual prediction model for intervention effects is constructed, comprising: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor; wherein the outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor;

[0009] The intervention effect counterfactual prediction model is trained using the training dataset to obtain the trained intervention effect counterfactual prediction model.

[0010] The characteristics of the sample to be predicted at the time to be predicted and at each time before the time of prediction, the intervention received, and the effects that occurred at each time before the time of prediction are input into the counterfactual prediction model of the intervention effect to obtain the prediction result of the effect at the time to be predicted.

[0011] In one specific embodiment of the present invention, it further includes:

[0012] The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation ,in, This represents the history of the i-th sample up to time t; Let represent the feature set of the i-th sample from time 1 to time t, the set of interventions received from time 1 to time t-1, and the set of effects that occurred from time 1 to time t-1, respectively.

[0013] The latent variable storage unit is used to store latent variables. and ,in This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample; at the initial time t=0, initialize . ;

[0014] The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. Indicates the value of the hidden variable. and Let represent the intervention received by the i-th sample at time t and the corresponding effect, respectively;

[0015] The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention .

[0016] In one specific embodiment of the present invention, it further includes:

[0017] The time series sub-model uses either a long short-term memory network or a Transformer network.

[0018] In one specific embodiment of the present invention, it further includes:

[0019] When training the counterfactual prediction model for the intervention effect, the loss function expression for the i-th sample at time t is as follows:

[0020]

[0021] in, Represents the mathematical expectation; ( ) represents the KL divergence; Represents a Gaussian distribution; Diag represents a diagonal matrix;

[0022] The final loss function is obtained by averaging the loss function over all samples and time steps in the training dataset.

[0023] A second aspect of the present invention provides a counterfactual prediction device for intervention effects in time series, comprising:

[0024] The training dataset construction module is used to acquire multiple historical samples to form a training dataset in the domain where the intervention effect to be predicted. The historical samples include the features of the historical moment, the intervention received, and the corresponding effect.

[0025] An intervention effect counterfactual prediction model construction module is used to construct an intervention effect counterfactual prediction model. The intervention effect counterfactual prediction model includes: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor. The outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor.

[0026] The model training module is used to train the counterfactual prediction model of the intervention effect using the training dataset, so as to obtain the trained counterfactual prediction model of the intervention effect.

[0027] The prediction module is used to input the characteristics of the sample to be predicted at the time to be predicted and the interventions received, as well as the effects that occurred at the previous times, into the counterfactual prediction model of the intervention effect, and to obtain the prediction result of the effect at the time to be predicted.

[0028] In one specific embodiment of the present invention, it further includes:

[0029] The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation ,in, This represents the history of the i-th sample up to time t; Let represent the feature set of the i-th sample from time 1 to time t, the set of interventions received from time 1 to time t-1, and the set of effects that occurred from time 1 to time t-1, respectively.

[0030] The latent variable storage unit is used to store latent variables. and ,in This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample; at the initial time t=0, initialize . ;

[0031] The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. Indicates the value of the hidden variable. and Let represent the intervention received by the i-th sample at time t and the corresponding effect, respectively;

[0032] The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention .

[0033] In one specific embodiment of the present invention, it further includes:

[0034] The time series sub-model uses either a long short-term memory network or a Transformer network.

[0035] In one specific embodiment of the present invention, it further includes:

[0036] When training the counterfactual prediction model for the intervention effect, the loss function expression for the i-th sample at time t is as follows:

[0037]

[0038] in, Represents the mathematical expectation; ( ) represents the KL divergence; Represents a Gaussian distribution; Diag represents a diagonal matrix;

[0039] The final loss function is obtained by averaging the loss function over all samples and time steps in the training dataset.

[0040] A third aspect of the present invention provides an electronic device comprising:

[0041] At least one processor; and a memory communicatively connected to said at least one processor;

[0042] The memory stores instructions that can be executed by the at least one processor, and the instructions are configured to perform the aforementioned counterfactual prediction method for intervention effects in a time series.

[0043] A fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions for causing the computer to execute the above-described counterfactual prediction method for intervention effects in a time series.

[0044] Features and beneficial effects of the present invention:

[0045] 1) This invention focuses on the problem of hidden heterogeneity in counterfactual prediction under time series, and proposes to use variational inference method to restore hidden factors from historical data, and use the restored hidden variables as input to the effect prediction module, which further improves the accuracy of model prediction.

[0046] 2) This invention utilizes powerful time prediction models such as Long Short-Term Memory Networks and Transformers to handle the complex variable relationships between historical features, interventions, and effects in time series, and has stronger model prediction capabilities.

[0047] 3) The variational inference technique used in this invention can be combined with a variety of model bases and can be adapted to different types of counterfactual prediction tasks in time series, such as the effect prediction problem under continuous value intervention and binary intervention.

[0048] 4) In addition to providing the predicted value of the effect, this invention can also provide the distribution of the predicted effect, so that decision-makers can consider both the quality of the effect and the magnitude of the risk when making intervention decisions.

[0049] 5) This invention can be applied to healthcare and biomedicine. In the fields of healthcare and biomedicine, the therapeutic effect of drugs on patients' health conditions is usually assessed using randomized controlled trials (RCTs) to obtain the gold standard. However, RCTs are time-consuming and costly. This invention uses historical observational data to learn a counterfactual predictive model for drug treatment effects, avoiding the costs associated with RCTs. Attached Figure Description

[0050] Figure 1 This is an overall flowchart of a time-series counterfactual prediction method for intervention effects according to an embodiment of the present invention. Detailed Implementation

[0051] This invention proposes a method and apparatus for predicting the counterfactual effect of interventions in time series data, which will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0052] A first aspect of this invention proposes a counterfactual prediction method for intervention effects in time series, comprising:

[0053] In the domain where the intervention effect is to be predicted, a training dataset is formed by acquiring multiple historical samples. The historical samples contain the features of the historical moment, the intervention received, and the corresponding effect.

[0054] A counterfactual prediction model for intervention effects is constructed, comprising: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor; wherein the outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor;

[0055] The intervention effect counterfactual prediction model is trained using the training dataset to obtain the trained intervention effect counterfactual prediction model.

[0056] The characteristics of the sample to be predicted at the time to be predicted and at each time before the time of prediction, the intervention received, and the effects that occurred at each time before the time of prediction are input into the counterfactual prediction model of the intervention effect to obtain the prediction result of the effect at the time to be predicted.

[0057] In a specific embodiment of the present invention, the overall process of the counterfactual prediction method for intervention effects in time series is as follows: Figure 1 As shown, it includes the following steps:

[0058] 1) Obtain multiple historical samples to form a training dataset.

[0059] In the field where the intervention effect is to be predicted, a training dataset is formed by collecting a batch of data recorded in application scenarios, denoted as . .in , and Let represent the characteristics of the i-th sample at time t, the intervention received, and the corresponding effect, respectively, where n is the total number of samples in the training dataset.

[0060] For example, in the medical field, a patient can be considered a sample. , and These can represent the medical observation characteristics, doctor's treatment measures, and recovery status of the i-th patient on day t, respectively.

[0061] For ease of description, let This represents the history of the i-th sample up to time t. Let represent the feature set of the i-th sample from time 1 to time t, the intervention set received from time 1 to time t-1, and the effect set that occurred from time 1 to time t-1, respectively.

[0062] in, This indicates that the i-th sample starts from time t and ends at time t. The set of features at time, This indicates that the i-th sample starts from time t and ends at time t. The set of interventions received at any time, This indicates that the i-th sample starts from time t and ends at time t. A set of effects that occur at any given moment.

[0063] 2) Construct a counterfactual prediction model for intervention effects.

[0064] In this embodiment, the counterfactual prediction model for intervention effects includes: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor. The outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor.

[0065] The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation In this embodiment, a Long Short-Term Memory network or a Transformer can be selected for implementation.

[0066] The hidden variable storage unit is used to store two vectors. and It can be read at any time. The latent variable storage unit represents the distribution of the latent variables. In this embodiment, the latent variables are characterized as Gaussian distributions with independent dimensions, where... This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample. At the initial time t=0, it is initialized to . .

[0067] The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. This represents the value of the latent variable. In this embodiment, the encoder outputs the time series sub-model. The output of the hidden variable storage unit and the dataset As input, the latent variables are processed by a multi-layer fully connected neural network.

[0068] The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention In this embodiment, the effect predictor will output the time series sub-model's... Sampling ,as well as As input, the predicted output value is processed by another multi-layer fully connected neural network.

[0069] The counterfactual prediction model for intervention effects described in this embodiment uses a time series sub-model to extract historical representations from a historical sequence containing features, interventions, and effects. Variational inference techniques are used to introduce an encoder to learn latent variables that characterize hidden heterogeneity for each time series sample. Latent variables are sampled from the latent variable distribution output by the encoder, and the latent variables, along with the representations extracted by the time series sub-model and the intervention, are simultaneously input into the decoder to obtain the predicted counterfactual effect distribution. The latent variable distribution output by the encoder is stored in the latent variable storage unit as the prior distribution in the variational inference process at the next time step for the prediction process at subsequent time steps.

[0070] 3) Use the training dataset obtained in step 1) to train the counterfactual prediction model of the intervention effect established in step 2).

[0071] In this embodiment, the training dataset is used. The counterfactual prediction model for the intervention effect is trained. The loss function for the i-th sample at time t is defined as follows:

[0072]

[0073] in, Represents the mathematical expectation, that is For each sampled value, the result within the brackets can be calculated. The average of the results within the brackets from multiple samples is the expected value.

[0074] ( ) represents the KL divergence, which means the difference between the two distributions before and after the vertical line in parentheses.

[0075] This indicates a Gaussian distribution. The part before the comma in parentheses represents the mean, and the part after the comma represents the covariance matrix.

[0076] Diag represents a diagonal matrix, with the values ​​in parentheses representing the values ​​on the diagonal and all off-diagonal elements being 0.

[0077] The final loss function is obtained by averaging the above loss function over all samples and time steps in the training dataset. In this embodiment, the Adam or SGD optimizer is used to optimize the parameters of the time series sub-model, the latent variable encoder, and the effect predictor to minimize the loss function value until convergence.

[0078] 4) Use the model trained in step 3) to predict the counterfactual effect of the intervention.

[0079] In this embodiment, the features of the new sample to be predicted at the new time T+1 and all previous times after T historical time periods are analyzed. Intervention and the effects that occurred at each previous moment. Input the trained counterfactual prediction model of the intervention effect, and the model outputs the corresponding effect at time T+1. The prediction results.

[0080] Specifically, , The trained counterfactual prediction model for intervention effects is input, where a time series sub-model is used to obtain the representation. Subsequently, based on the initialization... The hidden variable encoder iterates t from 0 to t according to the following expression. get .

[0081]

[0082] from Medium sampling and as well as The common inputs are fed into the effect predictor to obtain the distribution of effect predictions, and the mean of the effect prediction distribution is used as... The final prediction result.

[0083] In one specific embodiment of the invention, a hospital introduced a new antihypertensive drug and needed to assess the impact of the drug's usage regimen on the risk of future myocardial infarction or stroke. Doctors needed to analyze historical observational data (such as electronic health records, health insurance databases, etc.). Researchers decomposed the data of the i-th patient in the historical observation into whether or not medication was taken (denoted as...). Patient characteristics (such as blood pressure, renal function, concomitant medications, new-onset diseases, etc., expressed as...) ), and whether a myocardial infarction / stroke eventually occurs (indicated as ), These historical observation data are used to train the model, resulting in a counterfactual prediction model of the intervention effect. Now, facing a new patient, we observe all their historical information from time 1 to time T, i.e. And the features of the predicted time T+1. The doctor wants to decide whether to prescribe medication (choice) ),Will For each possible value, predict the corresponding value using the counterfactual prediction model. Based on the prediction results, select the one with the best prediction performance. As a last resort intervention.

[0084] To achieve the above embodiments, a second aspect of the present invention provides a counterfactual prediction device for intervention effects in time series, comprising:

[0085] The training dataset construction module is used to acquire multiple historical samples to form a training dataset in the domain where the intervention effect to be predicted. The historical samples include the features of the historical moment, the intervention received, and the corresponding effect.

[0086] An intervention effect counterfactual prediction model construction module is used to construct an intervention effect counterfactual prediction model. The intervention effect counterfactual prediction model includes: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor. The outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor.

[0087] The model training module is used to train the counterfactual prediction model of the intervention effect using the training dataset, so as to obtain the trained counterfactual prediction model of the intervention effect.

[0088] The prediction module is used to input the characteristics of the sample to be predicted at the time to be predicted and the interventions received, as well as the effects that occurred at the previous times, into the counterfactual prediction model of the intervention effect, and to obtain the prediction result of the effect at the time to be predicted.

[0089] In one specific embodiment of the present invention, it further includes:

[0090] The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation ,in, This represents the history of the i-th sample up to time t; Let represent the feature set of the i-th sample from time 1 to time t, the set of interventions received from time 1 to time t-1, and the set of effects that occurred from time 1 to time t-1, respectively.

[0091] The latent variable storage unit is used to store latent variables. and ,in This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample; at the initial time t=0, initialize . ;

[0092] The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. Indicates the value of the hidden variable. and Let represent the intervention received by the i-th sample at time t and the corresponding effect, respectively;

[0093] The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention .

[0094] In one specific embodiment of the present invention, it further includes:

[0095] The time series sub-model uses either a long short-term memory network or a Transformer network.

[0096] In one specific embodiment of the present invention, it further includes:

[0097] When training the counterfactual prediction model for the intervention effect, the loss function expression for the i-th sample at time t is as follows:

[0098]

[0099] in, Represents the mathematical expectation; ( ) represents the KL divergence; Represents a Gaussian distribution; Diag represents a diagonal matrix;

[0100] The final loss function is obtained by averaging the loss function over all samples and time steps in the training dataset.

[0101] This allows for the learning of latent factors for each sample using variational inference techniques combined with time series models, thus obtaining latent variables. Using these latent variables as additional input to the effect predictor can improve the accuracy of counterfactual predictions of different intervention effects.

[0102] To implement the above embodiments, a third aspect of the present invention provides an electronic device, comprising:

[0103] At least one processor; and a memory communicatively connected to said at least one processor;

[0104] The memory stores instructions that can be executed by the at least one processor, and the instructions are configured to perform the aforementioned counterfactual prediction method for intervention effects in a time series.

[0105] To implement the above embodiments, a fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions for causing the computer to execute the above-described counterfactual prediction method for intervention effects in a time series.

[0106] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0107] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform a time-series counterfactual prediction method for intervention effects according to the above embodiments.

[0108] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0109] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0110] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0111] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this application pertain.

[0112] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.

[0113] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0114] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0115] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0116] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.

Claims

1. A counterfactual prediction method for intervention effects in time series, characterized in that, include: In the domain where the intervention effect is to be predicted, a training dataset is formed by acquiring multiple historical samples. The historical samples contain the features of the historical moment, the intervention received, and the corresponding effect. A counterfactual prediction model for intervention effects is constructed, comprising: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor; wherein the outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor; The intervention effect counterfactual prediction model is trained using the training dataset to obtain the trained intervention effect counterfactual prediction model. The characteristics of the sample to be predicted at the time to be predicted and at each time before the time of prediction, the intervention received, and the effects that occurred at each time before the time of prediction are input into the counterfactual prediction model of the intervention effect to obtain the prediction result of the effect at the time to be predicted.

2. The method according to claim 1, characterized in that, Also includes: The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation ,in, This represents the history of the i-th sample up to time t; Let represent the feature set of the i-th sample from time 1 to time t, the set of interventions received from time 1 to time t-1, and the set of effects that occurred from time 1 to time t-1, respectively. The latent variable storage unit is used to store latent variables. and ,in This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample; at the initial time t=0, initialize . ; The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. Indicates the value of the hidden variable. and Let represent the intervention received by the i-th sample at time t and the corresponding effect, respectively; The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention .

3. The method according to claim 2, characterized in that, Also includes: The time series sub-model uses either a long short-term memory network or a Transformer network.

4. The method according to claim 2, characterized in that, Also includes: When training the counterfactual prediction model for the intervention effect, the loss function expression for the i-th sample at time t is as follows: in, Represents the mathematical expectation; ( ) represents the KL divergence; Represents a Gaussian distribution; Diag represents a diagonal matrix; The final loss function is obtained by averaging the loss function over all samples and time steps in the training dataset.

5. A counterfactual prediction device for intervention effects in time series, characterized in that, include: The training dataset construction module is used to acquire multiple historical samples to form a training dataset in the domain where the intervention effect to be predicted. The historical samples include the features of the historical moment, the intervention received, and the corresponding effect. An intervention effect counterfactual prediction model construction module is used to construct an intervention effect counterfactual prediction model. The intervention effect counterfactual prediction model includes: a time series sub-model, a latent variable storage unit, a latent variable encoder, and an effect predictor. The outputs of the time series sub-model and the latent variable storage unit are respectively connected to the inputs of the latent variable encoder, and the outputs of the latent variable encoder and the time series sub-model are respectively connected to the inputs of the effect predictor. The model training module is used to train the counterfactual prediction model of the intervention effect using the training dataset, so as to obtain the trained counterfactual prediction model of the intervention effect. The prediction module is used to input the characteristics of the sample to be predicted at the time to be predicted and the interventions received, as well as the effects that occurred at the previous times, into the counterfactual prediction model of the intervention effect, and to obtain the prediction result of the effect at the time to be predicted.

6. The apparatus according to claim 5, characterized in that, Also includes: The time series sub-model is used to store the history of the i-th sample before time t. Mapping to representation ,in, This represents the history of the i-th sample up to time t; Let represent the feature set of the i-th sample from time 1 to time t, the set of interventions received from time 1 to time t-1, and the set of effects that occurred from time 1 to time t-1, respectively. The latent variable storage unit is used to store latent variables. and ,in This represents the mean vector of the Gaussian distribution of the i-th sample. Let represent the variance vector of the i-th sample; at the initial time t=0, initialize . ; The latent variable encoder is used to base the historical representation at the current time. Intervention and effects To recover the distribution of latent variables ,in, Let represent the mean vector of the Gaussian distribution of the i-th sample at time t. Let represent the variance vector of the i-th sample at time t. Indicates the value of the hidden variable. and Let represent the intervention received by the i-th sample at time t and the corresponding effect, respectively; The effect predictor is used to predict based on the historical representation at the current moment. Intervention and latent variables of sampling Predicting the distribution of effects caused by intervention .

7. The apparatus according to claim 6, characterized in that, Also includes: The time series sub-model uses either a long short-term memory network or a Transformer network.

8. The apparatus according to claim 6, characterized in that, Also includes: When training the counterfactual prediction model for the intervention effect, the loss function expression for the i-th sample at time t is as follows: in, Represents the mathematical expectation; ( ) represents the KL divergence; Represents a Gaussian distribution; Diag represents a diagonal matrix; The final loss function is obtained by averaging the loss function over all samples and time steps in the training dataset.

9. An electronic device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in any one of claims 1-4.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the method according to any one of claims 1-4.