A deep temporal-causal inference and explainability method for removing time-varying confounding
By generating latent variables through a temporal decontamination module and a recursive marginal structure network, and combining a multi-task multilayer perceptron and a recurrent neural network, the problem of unobserved time-varying confounding factors in complex multi-process time-series data is solved, and reliable estimation and clear interpretation of individual-level dynamic causal effects are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TONGJI UNIV
- Filing Date
- 2026-03-12
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies struggle to effectively remove unobserved time-varying confounding factors when processing complex, multi-process, and multi-time-point time-series data, leading to biased causal estimations, a lack of deep time-series modeling and interpretability, and difficulty in providing clear causal explanations.
A temporal decontamination module is used to generate latent variables, combined with a recursive marginal structure network for causal estimation, and multi-dimensional disposal variables are processed through a multi-task multilayer perceptron and a recurrent neural network. A cumulative local effect analysis method is introduced to provide individual-level dynamic causal effect estimation and interpretability analysis.
It effectively reduces the impact of unobserved time-varying confusion, improves the reliability of causal estimation, provides clear causal explanations in complex multi-disposition scenarios, and supports individual-level dynamic causal effect estimation and visualization interpretation.
Smart Images

Figure CN122311481A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the interdisciplinary field of artificial intelligence and causal inference, and in particular to a deep temporal causal inference and interpretability method for removing time-varying obfuscation. Background Technology
[0002] In applications such as smart cities, intelligent transportation, public health, and refined governance, various systems continuously generate and accumulate massive amounts of time-series data, such as resident movement trajectories, medical records, phased policy implementation records, and equipment operation logs. Traditional statistical regression models and time series forecasting models (such as ARIMA, VAR, and simple LSTM forecasting models) are mainly used to reveal the correlation between variables or to make numerical predictions of future outcomes. They can usually only answer "what will happen in the future," but are difficult to rigorously answer causal questions such as "how much impact a specific intervention has on the outcome variable, and how this impact evolves over time."
[0003] In recent years, causal inference theories (such as the potential outcome framework, propensity score method, and marginal structure model MSM) have been gradually introduced into time series data analysis to estimate the potential outcomes for individuals or groups under different intervention paths, thus providing a more rigorous tool for evaluating intervention effects. However, in real-world applications, interventions often involve multiple treatments, multiple time points, strong nonlinearity, and high dimensionality, accompanied by complex time dependencies. Traditional causal inference methods face severe challenges in terms of modeling capabilities, assumptions, and computational complexity, making them difficult to directly apply to such complex time series scenarios.
[0004] In scenarios with significant time dependence, common approaches in existing technologies mainly fall into the following categories: First, sequential regression or generalized linear models are used to model each time point separately, usually assuming that all confounding factors have been fully observed and enter the model in a linear form; second, marginal structure models (MSM) combined with propensity score weighting (IPTW) are used to reconstruct the "pseudo-randomized trial" population by constructing weights to mitigate the impact of time dependence confounding; third, deep learning models such as RNN and LSTM are introduced to predict time series, but most of these works mainly focus on prediction accuracy and lack rigorous causal explanation capabilities.
[0005] The aforementioned methods typically rely on strong assumptions such as "sequential strong ignorability," which assumes that, given historical observations, all confounding factors simultaneously influencing intervention allocation and outcome variables have been observed and incorporated into the model. However, in real-world environments, numerous confounding factors are often difficult to observe or quantify, such as individual psychological characteristics, risk preferences, unrecorded resource availability, subjective perceptions of the environment, cultural habits, and cognitive biases. These factors themselves exhibit time-varying characteristics and simultaneously influence intervention allocation and outcome variables through multiple complex pathways. Traditional linear or simple nonlinear models struggle to adequately characterize these high-dimensional, multivariate, nonlinear, and interactive effects.
[0006] To overcome these limitations, some studies have begun to explore the introduction of deep causal learning structures such as Time Series Deconfounder and Recurrent Marginal Structural Network (RMSN) to estimate causal effects in the context of multiple time points and multiple treatments, and have achieved preliminary results in areas such as clinical prediction and policy time-series effect assessment. However, existing technologies still have the following significant shortcomings in terms of the depth of handling time-varying confounding, the ability to characterize the joint allocation structure of multiple treatments, and the organic integration with model interpretability.
[0007] (1) The handling of time-varying confounding factors relies on strong assumptions, which can easily lead to causal estimation bias: Most existing causal inference methods (including traditional marginal structure models and some deep structure models) are usually based on two core premises: first, all confounding factors affecting intervention allocation and outcome variables have been observed; second, the entry form of these confounding factors in the model has been pre-defined (e.g., linear or specific nonlinear forms). When there are unobservable or difficult-to-measure time-varying confounding factors, the above assumptions are often difficult to satisfy, leading to problems such as bias in propensity score estimation, distortion of IPTW weights, and instability in individual treatment effect (ITE) estimation. In long-term time series scenarios, this bias will accumulate over time, eventually seriously affecting the reliability of intervention effect assessment and strategy optimization.
[0008] (2) Limited modeling capabilities in multi-disposition and multi-time-point scenarios: In many real-world applications, interventions are not single-dimensional but are composed of multiple different forms of interventions. For example, there are interventions that change continuously over time (such as "social contact intensity" and "drug dosage"), as well as multiple binary interventions (such as different levels of policy response and multiple drug combinations). Moreover, there are often significant interdependencies and linkages between different interventions. In existing technologies, many methods are only applicable to single interventions or a few discrete interventions. Even when modeling multiple interventions, they often use a simple concatenation of inputs, ignoring the relevant structures behind the joint allocation of multiple interventions, making it difficult to effectively characterize the confounding relationships and causal mechanisms under the combined effect of multiple interventions.
[0009] (3) Deep models focus on prediction accuracy but lack causal interpretability at the mechanism level: Although deep learning models such as LSTM and Transformer perform well in time series prediction tasks, most methods aim to improve prediction accuracy and output only numerical prediction results, lacking a systematic answer to "when, in what nonlinear form, and in what interactive way does a certain feature or intervention affect the result." Currently, there is a lack of interpretable analysis tools that are compatible with causal inference frameworks and can provide both global and local perspectives. Traditional interpretation methods (such as gradient-based saliency graphs and simple feature importance ranking) often do not consider causal structure and are easily affected by feature correlation and multicollinearity, making it difficult to provide reliable mechanism explanations for complex time series causal models.
[0010] (4) Lack of a unified framework to achieve "removal of time-varying confusion + deep time series modeling + model interpretability": Most existing deep time series causal models are "point-like innovations". For example, some only combine the decontamination structure with RNN to deal with some hidden confusion, but do not provide a systematic model interpretation module; some only propose interpretability methods applicable to general prediction models, but do not design for specific causal effect scenarios; overall, there is still a lack of an integrated technical framework that connects the entire chain from "potential outcome modeling - time series decontamination - causal effect estimation - interpretability analysis".
[0011] The aforementioned shortcomings directly lead to the difficulty in simultaneously meeting the following requirements in many key application scenarios: on the one hand, effectively reducing or eliminating the impact of unobservable time-varying confusion, thereby improving the credibility of causal estimation; on the other hand, being able to output individual-level time-series causal effects in complex environments with multiple time points and multiple treatments, and providing clear, quantitative, and visualized explanatory indicators to support decision-making and mechanism understanding.
[0012] Therefore, there is an urgent need for a technical solution that can effectively overcome the interference of unobserved time-varying phenomena, be applicable to complex multi-process time-series scenarios, and provide a clear causal explanation. Summary of the Invention
[0013] The purpose of this invention is to overcome the above-mentioned defects and provide a method that can effectively overcome unobserved time-varying confusion interference, is applicable to complex multi-process time series scenarios, and can provide a clear causal explanation. This solves the problem of how to achieve unbiased and reliable individual-level dynamic causal effect estimation in complex time series data with unobserved time-varying confusion, and can perform quantitative and interpretable mechanism analysis on the estimation results.
[0014] To achieve the above objectives, this invention proposes a deep temporal causal inference and interpretability method for removing time-varying obfuscation, comprising the following steps: S1: Data Acquisition and Preprocessing: Acquire time-series datasets of multiple individuals, wherein the time-series datasets include the sequence of outcome variables for each individual. Multidimensional treatment variable sequence Time-varying covariate sequence and static features And based on the time-series dataset, construct historical information for each individual. ; S2: Temporal Decontamination and Latent Variable Generation: Based on the historical information, the temporal decontamination module is used to learn and generate a set of latent variable sequences that evolve over time. The latent variable sequence is used to replace unobserved time-varying confounding factors, such that, given the latent variable sequence and the observed variables, the treatments in different dimensions of the multidimensional treatment variable sequence are approximately conditionally independent. S3: Weighted Causal Estimation: Based on the latent variable sequence, the historical information, and the multi-dimensional treatment variable sequence, input to the propensity network of the recurrent marginal structure network module, calculate the stable inverse probability weight of each individual at each time point; use the stable inverse probability weight to weight the loss function of the prediction network of the recurrent marginal structure network module, train the prediction network to learn the mapping relationship from the historical information, the latent variable sequence, and the current treatment to the outcome variable, and obtain a trained causal inference model; using the trained causal inference model, predict the corresponding potential outcome sequence by inputting different counterfactual treatment paths, and calculate the individual-level time-series causal effect (ITE) based on the potential outcome sequence under different treatment paths; S4: Model interpretability analysis: The trained causal inference model is regarded as the objective function. The cumulative local effect analysis method is used to calculate the first-order cumulative local effect curve and the second-order interaction effect curve of the multidimensional treatment variable sequence and the key time-varying covariate sequence to quantify their nonlinear marginal contribution and interaction contribution to the prediction of the potential outcome. The heterogeneity of the effect among individuals is analyzed based on the individual conditional expectation curve.
[0015] Furthermore, in step S2, the recurrent neural network is an LSTM network; the multi-dimensional treatment variable sequence simultaneously includes treatments in continuously varying forms and treatments in binary forms. The temporal decontamination module sets up a multi-task multilayer perceptron at each time point. The multi-task multilayer perceptron has multiple output heads, each corresponding to a treatment dimension in the multi-dimensional treatment variable sequence. The multi-task multilayer perceptron uses the latent variables, time-varying covariates, and static features as inputs to predict the conditional assignment probability of each dimension in the multi-dimensional treatment variable sequence. Step S2 specifically involves: S21. The historical information is recursively encoded using a recurrent neural network (RNN / LSTM) to generate latent states, as shown in the following formula: initial: ,in For trainable random initialization vectors; Recursion: ; in, In time The generated latent state variable is used to represent the representation vector of the latent time-varying confounding factors learned by the time-series encoder, and is used to characterize the unobserved factors that affect the treatment variable and the outcome variable; Represents the previous time step The potential state variables are used to recursively update the potential representation of the current time step; These are randomly initialized trainable vectors used to initialize the hidden states of the recurrent neural network and are updated through gradient optimization during model training. For individuals The static feature vector represents individual attributes that do not change over time, such as gender, age, education level, or other demographic attributes. In time A multidimensional vector of disposal variables is used to represent the intervention or exposure status received by an individual at the previous time step. These disposal variables can simultaneously include continuous variables (e.g., social exposure index) and binary variables (e.g., policy implementation status). In time A time-varying covariate vector is used to represent observed characteristics that change over time, such as environmental factors, weather conditions, or behavioral state variables.
[0016] S22. At each time point, the potential state is combined with the observed covariates at the current time, input into the multi-task multilayer perceptron, and the allocation probability or distribution parameters of the action under the current conditions are output, expressed by the following formula: ; in, In time Time of the first The conditional assignment result of each disposal variable is used to represent the allocation probability or probability distribution parameter of that disposal under the current conditions. For a binary disposal variable, this value represents the probability of the disposal occurring; for a continuous disposal variable, this value represents the parameter of the corresponding conditional probability distribution. The mapping function of a multi-task multilayer perceptron (Fully Connected Network) consists of several fully connected layers and is used to perform nonlinear mapping on input features and output prediction results for the corresponding processing dimension. Individual The static feature vector represents individual attributes that do not change over time, such as demographic features or basic individual attributes. Refers to time The time-varying covariate vector represents the observed characteristics that change over time, such as environmental variables, behavioral states, or situational variables; Refers to time The latent state variables are obtained by encoding historical information through a recurrent neural network, and are used to represent unobserved time-varying confounding factors; In a multi-tasking multilayer perceptron, the relationship between the first and second layers is... The network parameters corresponding to each treatment variable include the weight matrix and bias terms. Different treatment dimensions have their own independent output heads and corresponding parameters.
[0017] S23. The temporal decontamination module is trained by minimizing the loss function between the disposal allocation predicted by the multi-task multilayer perceptron and the actual disposal allocation, and the latent states generated during the training process are used as the sequence of latent variables.
[0018] Furthermore, in the output head of the multi-task multilayer perceptron, for binary processing, the loss function adopts cross-entropy loss, and the output probability is generated using a sigmoid activation function. For continuous processing, the loss function adopts a log-likelihood-based loss function and utilizes a fully connected layer with Monte Carlo Dropout to output conditional distribution parameters or approximate probabilities.
[0019] Furthermore, after step S2, which involves time series decompression, the process also includes a latent variable validity verification step from the time series decompression module. This step includes: 1) On the validation set, for each time point Calculate the observed statistics for disposal allocation: ; in, Refers to time Time-based variable handling The conditional log-likelihood statistic is used to measure how well the model fits the disposal allocation mechanism. Refers to latent variables The expectation operator; In the case of a given latent variable Static characteristics and time-varying covariates Under the condition, disposal variable The conditional probability or probability density; Refers to time The disposal variable; Refers to time The latent variables are used to represent unobserved time-varying confounding factors; Individual Static characteristics; Refers to time The time-varying covariates.
[0020] 2) Generate multiple sets of replication treatment samples based on the trained temporal decontamination module, and calculate the corresponding replication statistics; 3) Compare the distributions of the observed statistic and the replication statistic. If the p-value calculated based on the comparison results is within a preset reasonable range, then the latent variable is determined to be valid and used for subsequent causal estimation.
[0021] Furthermore, in step S3, the recursive edge structure network module includes a bias network and an outcome prediction network, wherein the bias network is used to learn the complete conditional probability distribution of the disposal assignment. and simplified conditional probability distribution Based on this, the stable inverse probability weights at each time point are calculated; The stable inverse probability weight The calculation formula is: ; Among them, the denominator For a given historical treatment and historical confusion, the complete conditional distribution is given; molecule A simplified distribution that relies solely on historical processing; the complete conditional distribution and simplified distribution All of these are learned by the tendency network in the recursive edge structure network module; the tendency network uses LSTM or variational RNN structure to model the multi-treatment time series; Indexed by the current time; To predict the time span, it means from time... arrive Time window length; This is the time index variable used in weight calculation to represent the time index from... arrive Each time step; For time The treatment variable or multidimensional treatment vector at any given time; For time The handling variables or handling history at any given moment.
[0022] Furthermore, the extreme weights of the stable inverse probability weights are truncated to the 1%–99th percentile and normalized according to the prediction window to prevent variance inflation caused by extreme weight values. The truncation method is as follows: calculate the 1% and 99th percentiles of the distribution of all weights in the dataset, increase the weights below the 1% percentile to the 99th percentile, decrease the weights above the 99th percentile to the 99th percentile, and normalize according to the prediction window.
[0023] Furthermore, in step S3, the construction and training steps of the recursive edge structure network are as follows: S31. Construct a bias network, which is used to learn the complete conditional probability distribution of the disposal assignment. and simplified conditional probability distribution Based on this, the stable inverse probability weight at each time point is calculated. ; S32. Construct a result prediction network, wherein the result prediction network is an encoder based on a recurrent neural network, and its input includes the historical information. With the latent variable sequence Its loss function uses the mean squared error weighted by the stable inverse probability weight SW; S33. Use training data to jointly or separately train the tendency network and the result prediction network to obtain a trained causal inference model.
[0024] Furthermore, the result prediction network is a weighted LSTM encoder, whose input includes the historical information and the latent variable sequence, and whose loss function is the weighted mean square error with the added stable inverse probability weights, as shown in the formula: .
[0025] in, The loss function value of the network that predicts the outcome; Represents time The stable inverse probability weights are used to adjust for sample selection bias caused by different treatment paths; Representative of individuals In time The actual value of the variable; Representative results prediction network in time For individuals The prediction results.
[0026] The result prediction network uses only an Encoder structure and learns time-dependent hidden states by making "one-step forward" predictions on the real historical path. This provides a basis for constructing potential outcomes and individual causal effects.
[0027] Furthermore, in step S3, the method for calculating the individual-level temporal causal effect (ITE) is as follows: The parameters of the trained causal inference model are fixed; For individual i, under the same historical information and potential variable sequence, the first treatment path and the second treatment path are input respectively to obtain the first potential outcome sequence and the second potential outcome sequence; The difference between the first potential outcome sequence and the second potential outcome sequence at the corresponding time point is calculated as the treatment effect of the individual at the corresponding time point, thus obtaining the individual-level time-dependent treatment effect curve.
[0028] Furthermore, in step S4, the importance of the corresponding feature is measured by calculating the standard deviation of the first-order cumulative local effect (ALE) curve, and the effect strength of the corresponding feature is quantified by calculating the cumulative local effect range (ALER) or the cumulative local effect mean offset (ALED).
[0029] Furthermore, the model interpretability analysis steps specifically include: 4.1) First-order cumulative local effect analysis: For the selected target feature to be explained, its value range is divided into multiple bins; for each bin, the average change in the predicted output of the causal inference model is calculated when the value of the target feature changes slightly, which is taken as the local effect; starting from the lower limit of the target feature value, the local effect is accumulated to obtain the first-order cumulative local effect curve, which is used to characterize the global average marginal effect of the feature on the prediction result; 4.2) Second-order interaction effect analysis: For each target feature pair, after deducting their respective first-order effects, the second-order joint partial effect is calculated, and a second-order cumulative local effect surface describing the additional interaction contribution between the target feature pairs is generated. 4.3) Characteristic effect quantification: Based on the first-order cumulative local effect curve, calculate its standard deviation to measure the importance of the feature, and calculate the cumulative local effect range or average offset to quantify the intensity of the characteristic effect. 4.4) Individual heterogeneity analysis: For the target feature, fix the values of other features and plot the individual condition expectation curves of multiple individuals under different feature values; by analyzing the dispersion and shape pattern of the cluster of individual condition expectation curves, the differences in treatment effects among individuals are revealed.
[0030] The present invention also proposes a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method for deep temporal causal inference and interpretability by removing time-varying obfuscation.
[0031] Compared with the prior art, the advantages of the present invention are: This invention automatically infers latent variables that evolve over time using a temporal decontamination module (TSD). This is used to replace time-varying confounding factors that are difficult to observe directly. Using this latent representation, the present invention is able to... Under these conditions, the joint allocation of multidimensional treatments becomes approximately independent, thereby weakening the strong assumption in traditional causal methods that "all confounding factors must be fully observed." This effectively reduces the accumulation of bias caused by hidden confounding and improves the robustness of inverse probability weighting (IPTW) and latent outcome estimation. This mechanism is particularly important for dealing with unobservable factors that are prevalent in the real world, effectively reducing the bias caused by time-varying confounding and significantly improving the reliability of causal estimation.
[0032] This invention, based on Recursive Edge Structure Network (RMSN), deeply integrates the causal inference approach of the Minimum Structural Model (MSM) with the RNN / LSTM architecture. This allows the model to retain the theoretical rigor of causal weight calculation while possessing the powerful expressive capabilities of neural networks for handling high-dimensional, nonlinear, and time-dependent data. This structure can adapt to both continuous and discrete interventions, supporting dynamic causal effect estimation under long-term, multi-stage, and multi-scenario intervention paths. It reduces dependence on linear models and pre-defined functional forms, making it more suitable for characterizing real intervention mechanisms in complex systems and enabling unified handling of multi-treatment, multi-time-point, and complex nonlinear dynamic causal relationships.
[0033] Unlike existing methods that focus solely on prediction accuracy or only provide overall average causal effects, this invention, based on deep causal modeling, further introduces interpretability analysis modules such as ALE and ICE, constructing an integrated deep causal framework with both predictive and causal explanatory capabilities, forming a complete interpretable causal analysis system. This system not only outputs individual-level, time-dependent treatment effects but also explains the nonlinear contributions and interactions of features at both global and local levels. Furthermore, it quantifies high-dimensional causal relationships into easily understandable effect measures using numerical indicators such as ALER and ALED, providing transparent and traceable evidence for scientific decision-making, mechanism understanding, and policy evaluation.
[0034] The overall framework of this invention is highly versatile and scalable, and can be widely applied to various scenarios requiring the processing of long-term, multi-disposition data, such as human mobility behavior analysis, social impact effect assessment, medical multi-treatment path analysis, and policy intervention time-series assessment. The model structure, input feature dimensions, treatment types, and time granularity can all be flexibly adjusted according to actual applications, making it easy to integrate into engineering systems such as urban computing, medical decision support, social governance, and public policy evaluation, demonstrating significant practical deployment value. Attached Figure Description
[0035] Figure 1 This is an overall flowchart of the deep temporal causal inference and interpretability method for removing time-varying obfuscation proposed in this embodiment of the invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be further described below.
[0037] Example 1 This embodiment proposes a deep temporal causal inference and interpretability method to remove time-varying obfuscation, which is based on a potential outcome framework. For each individual i, within the observation time range T, the following core data objects are defined: Based on the potential outcome framework, for each individual At any moment The observation history is modeled as follows: Observation result sequence: ; Observation of multi-process sequences: ,in For individuals exist Accepting at all times A vector of treatments (which may include consecutive treatments and binary treatments). Time-varying covariates: ; Individual static characteristics: ; Historical information: .
[0038] The goal of this invention is to learn a family of functions. This makes it possible to obtain historical observation information for a given individual. With a set future disposal path It can predict future moments. Potential expected outcomes: ; and by comparing different treatment paths The function's output calculates the individual-level time-series causal effect (ITE). Let be the expectation operator, representing the conditional expectation of the potential outcome; Representative of individuals In time Potential outcome variables; Represents time to The set disposal path indicates the disposal sequence over a future period of time; Representative of individuals Historical observation information, including historical result sequences , processing sequence Time-varying covariates and individual static characteristics The predictive function to be learned is used to predict time given historical information and future course of action. The expected value of the potential outcome.
[0039] like Figure 1 As shown, the following steps are the specific implementation process to achieve this goal.
[0040] S1. Data Acquisition and Preprocessing: Acquire time-series datasets of multiple individuals over a period of time. The time-series dataset for each individual includes: the sequence of outcome variables for each individual. Multidimensional treatment variable sequence Time-varying covariate sequence and static features And construct historical information for each individual based on the time-series dataset. ; S1.1 Data Acquisition: Collect panel data for N individuals from the target system (e.g., medical record database, city management platform). Ensure that the data for each individual i includes: Resulting variable sequence Refers to a sequence of target indicators that changes over time, i.e., a scalar sequence arranged by timestamps. ,constitute ; Multidimensional treatment variable sequence Refers to a sequence of one or more intervention or treatment variables that change over time, i.e., a vector sequence arranged by timestamps. Each It is a K a A dimensional vector, used to represent the multiple interventions applied at time t, constitutes... Among them, the multidimensional disposal variables include both continuously varying disposals and binary disposals.
[0041] Time-varying covariate sequence This refers to a sequence of other observed variables that change over time and may affect the outcome and course of action; in other words, a vector sequence arranged by timestamps. ,constitute These variables are either shared by all individuals or unique to each individual.
[0042] Individual static characteristics Individual characteristics that do not change over time (such as gender, baseline age, type).
[0043] S1.2 Data Preprocessing: The collected data sequences are cleaned, including handling missing values (e.g., using forward imputation or interpolation), identifying and handling outliers. Continuous variables are standardized or normalized, and categorical variables are coded.
[0044] S1.3 Sequence Alignment: 1.3.1) The timeline is standardized according to the actual significance of the research question and the natural cycle of the data (e.g., days, hours, or minutes). The original timestamps of all individuals are discretized according to this interval and mapped to a series of equally spaced integer time points t=1,2,...,T. For example, all observations occurring on a certain day are collected under the index t of that day, and representative values at that time point can be obtained through aggregation (e.g., summation, averaging) or sampling (e.g., taking values at a specific moment).
[0045] 1.3.2) The individual time series are then aligned and truncated to form fixed-length or variable-length sequences. The specific time series alignment method is as follows: On the discretized time axis, check whether each individual has a complete observation entry at each time point t. For missing time points, imputation or labeling is performed. For time-varying covariates shared by all individuals, ensure that they are defined at each time point t. This process ensures that the time series among individuals are strictly aligned in the time dimension. The specific truncation method is as follows: Based on modeling requirements (such as input length constraints) and the analysis time window, the aligned long sequences are truncated. Two strategies can be adopted: First, fixed-length sequences, i.e., setting a fixed historical window length L. For each individual, from time point t=L to t=T, multiple continuous subsequences of length L can be extracted, either slidingly or non-slidingly. Each subsequence and its corresponding static features constitute an independent training / prediction sample. Second, variable-length sequences, i.e., retaining the complete sequence of each individual from start to finish, but using padding and masking techniques to enable the model to handle inputs of different lengths. Typically, the sequence length needs to be uniformly padded to the length of the longest sequence in the dataset.
[0046] S1.4. Constructing Historical Information Objects: After completing the above processing, construct a standardized historical information object for each individual i (or each fixed-length sample). Typically, all samples are divided into training, validation, and test sets, either by individual sample or by time window.
[0047] S2. Temporal Decontamination and Latent Variable Generation: Based on the historical information mentioned above, the temporal decontamination module is used to learn and generate a set of latent variables that evolve over time. This is used to replace unobserved time-varying confounding factors, ensuring that, given the latent variable sequence and observed variables, the treatments in different dimensions of the multidimensional treatment variable sequence are approximately conditionally independent; theoretically, this is achieved by making the joint treatment assignment satisfy the approximation: It can be considered that This study captures a common driving factor behind multi-disposition correlations: multi-factor latent confusion. Here, the latent variable refers to the vector representing the unobserved confusion at each time point t, denoted as... The latent variable sequence refers to the sequence of latent variables of individual i at all time points, denoted as { }={ ,..., }
[0048] The specific implementation process for this step is as follows: S2.1. Construct a recurrent neural network (RNN), such as an LSTM, as the encoder; use the RNN / LSTM to recursively encode historical information to generate latent states. The formula is as follows: initial: ,in For trainable random initialization vectors; Recursion: ; in, In time The generated latent state variable is used to represent the representation vector of the latent time-varying confounding factors learned by the time-series encoder, and is used to characterize the unobserved factors that affect the treatment variable and the outcome variable; Represents the previous time step The potential state variables are used to recursively update the potential representation of the current time step; These are randomly initialized trainable vectors used to initialize the hidden states of the recurrent neural network and are updated through gradient optimization during model training. For individuals The static feature vector represents individual attributes that do not change over time, such as gender, age, education level, or other demographic attributes. In time A multidimensional vector of disposal variables is used to represent the intervention or exposure status received by an individual at the previous time step. These disposal variables can simultaneously include continuous variables (e.g., social exposure index) and binary variables (e.g., policy implementation status). In time A time-varying covariate vector is used to represent observed characteristics that change over time, such as environmental factors, weather conditions, or behavioral state variables.
[0049] S2.2. At each time point, a multi-task multilayer perceptron (MLP) is set up. This MLP takes latent variables, time-varying covariates, and static features as inputs and predicts the conditional assignment probability for each dimension of the multi-dimensional disposal variable sequence. In this embodiment, the obtained latent states... With the observed covariates at the current time (time-varying covariate sequence) and static features The input is combined and fed into a multi-task multilayer perceptron (MLP) (which has K...). a One output head, corresponding to K a (Each disposal dimension) predicts the allocation probability or distribution parameters of that disposal under the current conditions, expressed in the following formula: ; In the formula, In time Time of the first The conditional assignment result of each disposal variable is used to represent the allocation probability or probability distribution parameter of that disposal under the current conditions. For a binary disposal variable, this value represents the probability of the disposal occurring; for a continuous disposal variable, this value represents the parameter of the corresponding conditional probability distribution. It is a mapping function of a multi-task multilayer perceptron (Fully Connected Network), which consists of several fully connected layers. It is used to perform nonlinear mapping on input features and output the prediction results of the corresponding processing dimension. For individuals The static feature vector represents individual attributes that do not change over time, such as demographic features or basic individual attributes. For time The time-varying covariate vector represents the observed characteristics that change over time, such as environmental variables, behavioral states, or situational variables; For time The latent state variables are obtained by encoding historical information through a recurrent neural network, and are used to represent unobserved time-varying confounding factors; For multi-task multilayer perceptrons and the first The network parameters corresponding to each treatment variable include the weight matrix and bias terms. Different treatment dimensions have their own independent output heads and corresponding parameters; For the binary processing dimension, the output head of the MLP uses the Sigmoid activation function to output probabilities. ; For the continuous processing dimension, the corresponding output head uses a fully connected layer with Monte Carlo Dropout to output its conditional distribution parameters or approximate probabilities.
[0050] S2.3. By minimizing the loss function between the disposal assignment predicted by the multi-task multilayer perceptron and the actual disposal assignment, the temporal decontamination module is trained, and the latent states generated during the training process are used as a sequence of latent variables.
[0051] In this embodiment, a cross-entropy loss function is used for binary treatments; for continuous treatments, a log-likelihood-based loss function is used. Through optimization, the model can accurately predict the joint assignment of the current treatment based on historical data and latent variables, and forces the latent variables to... The dependencies between the encoded multiprocessors approximately satisfy the following: .
[0052] In the formula, This represents the total number of dimensions of the disposal variables; In time Time of the first The values that the disposal variables can take; For time The multidimensional processing vector; For time The latent variables, generated by the time-series decontamination module, are used to represent unobserved time-varying confounding factors; For individuals The static eigenvectors.
[0053] After training, to verify whether the Temporal Decontamination Module (TSD) successfully captures the true distribution of disposal assignments, a posterior predictive check is needed to validate the effectiveness of the latent variables of the TSD module. Specifically, after training, the module is forward-propagated across all data to obtain the latent variables of each individual i at each time point t. , forming a sequence { ,..., }, denoted as { }; to verify { The effectiveness of} is validated through posterior prediction. 1) On the validation set, for each time point Calculate the observed statistics for disposal allocation: ; in, Refers to latent variables The expectation operator; In the case of a given latent variable Static characteristics and time-varying covariates Under the condition, disposal variable The conditional probability or probability density; Refers to time The disposal variable; Refers to time The latent variables are used to represent unobserved time-varying confounding factors; Individual Static characteristics; Refers to time The time-varying covariates.
[0054] 2) Generate multiple sets of replication treatment samples based on the trained temporal decontamination module, and calculate the corresponding replication statistics; 3) Compare the distributions of the observed statistic and the replication statistic. If the p-value calculated based on the comparison results is within a preset reasonable range (e.g., the calculated p-value is close to 0.5), then the TSD module is considered to have a good fit to the treatment distribution, and its generated latent variables are determined. It is effective and can be used as a "surrogate variable" to hide confusion in subsequent causal estimation.
[0055] S3. Weighted Causal Estimation: Based on the input of the aforementioned latent variable sequence, historical information, and multi-dimensional treatment variable sequence into the propensity network of the recurrent marginal structure network module, the stable inverse probability weight of each individual at each time point is calculated; the loss function of the prediction network of the recurrent marginal structure network module is weighted with the stable inverse probability weight, and the prediction network is trained to learn the mapping relationship from the historical information, latent variable sequence, and current treatment to the outcome variable, resulting in a trained causal inference model; then, using the trained causal inference model, different counterfactual treatment paths are input to predict the corresponding potential outcome sequence, and the individual-level time-series causal effect (ITE) is calculated based on the potential outcome sequence under different treatment paths.
[0056] The Recursive Edge Network Module (RMSN module) includes a propensity network (RMSN-Propensity) and an outcome prediction network (RMSN-Outcome). The propensity network is used to learn the complete conditional probability distribution of disposition assignment. and simplified conditional probability distribution And based on this, the stable inverse probability weights at each time point are calculated.
[0057] The construction method of this Recursive Edge Network Module (RMSN module) includes: S3.1: Construct a biased network and calculate stable weights Construct a biased network (e.g., using an RNN or variational RNN) whose input is Used to learn the complete conditional probability distribution of disposal allocation and simplified conditional probability distribution The network is trained using a cross-entropy / log-likelihood loss function, and based on the trained propensity network, stable inverse probability weights are calculated for each time point across the entire sample. The calculation formula is as follows: ; Among them, the denominator For a given historical treatment and historical confusion, the complete conditional distribution is given; molecule A simplified distribution that relies solely on historical processing; a complete conditional distribution. and simplified distribution All of them are learned by the tendency network in the recursive edge structure network module; the tendency network uses LSTM or variational RNN structure to model the multi-treatment time series. Indexed by the current time; To predict the time span, it means from time... arrive Time window length; This is the time index variable used in weight calculation to represent the time index from... arrive Each time step; For time The treatment variable or multidimensional treatment vector at any given time; For time The handling variables or handling history at any given moment.
[0058] The extreme weights of the calculated stable inverse probability weights are truncated to the 1%–99th percentile and normalized by individual or time window to prevent variance inflation caused by extreme weight values. For example, the 1st and 99th percentiles of all weights in the dataset are calculated, weights below the 1st percentile are increased to that quantile, and weights above the 99th percentile are decreased to that quantile, and normalized by the prediction window.
[0059] S3.2. Constructing the Result Prediction Network The result prediction network is an encoder based on a recurrent neural network (RNN, such as LSTM) with weight adjustment. It adopts an encoder structure (without using a decoder) and learns a set of time-dependent hidden states by making "one-step forward" predictions on the real historical path. This provides a foundation for constructing potential outcomes and individual causal effects. At time t, its input is... The output is the prediction result. and hidden state The gradient descent algorithm is used to train the network until it converges on the validation set; its training loss function uses stable inverse probability weights SW. The weighted mean square error is calculated using the following formula: ; in, The loss function value of the result prediction network; In time The stable inverse probability weights are used to adjust for sample selection bias caused by different treatment paths; Individual In time The actual value of the variable; The result prediction network in time For individuals The prediction results.
[0060] S33. Use training data to jointly or separately train the tendency network and the outcome prediction network to obtain a trained causal inference model, that is, to obtain an RMSN model that can be used to generate potential outcomes.
[0061] After training, the trained causal inference model is used to predict the corresponding potential outcome sequence, and then the individual-level time-series causal effect (ITE) is calculated through the following steps: 1) Fix the parameters of the trained time series model and the causal inference model; 2) For individual i, with the same historical information and the sequence of latent variables { Under the condition of}: Constructing counterfactual intervention paths: Set two different treatment sequences (e.g., change part of the time trajectory of one of the treatment dimensions) to form factual path A and counterfactual path A′.
[0062] Calculate the potential outcome: Input the two paths into the trained RMSN outcome prediction network, while maintaining the input latent variable sequence { Without changing the initial value, forward propagation is performed to obtain the corresponding prediction result sequences Y(A) and Y(A′), which is equivalent to evaluating the prediction results while controlling for unobserved confusion. Values under different input processing conditions.
[0063] 3) Calculate the difference between the first potential outcome sequence Y(A) and the second potential outcome sequence Y(A′) at the corresponding time point, and use it as the individual's treatment effect at the corresponding time point to obtain the individual-level time-dependent treatment effect curve.
[0064] S4. Model interpretability analysis based on ALE: The trained causal inference model is regarded as the objective function. The cumulative local effect analysis method is adopted to calculate the first-order cumulative local effect curve and the second-order interaction effect curve of the multidimensional treatment variable sequence and the key time-varying covariate sequence to quantify their nonlinear marginal contribution and interaction contribution to the prediction of potential outcomes. The heterogeneity of effects among individuals is analyzed based on the individual conditional expectation curve.
[0065] The importance of the corresponding feature is measured by calculating the standard deviation of the first-order cumulative local effect (ALE) curve, and the effect strength of the corresponding feature is quantified by calculating the cumulative local effect range (ALER) or the cumulative local effect mean offset (ALED).
[0066] In this embodiment, after completing the weighted causal estimation, the Accumulated Local Effects (ALE) method is introduced and extended to provide interpretability for the causal inference model.
[0067] The interpretability analysis method for this model is as follows: the trained RSN result prediction network is treated as a black box prediction function. Its inputs include treatments, covariates, static features, and latent variables, and the following analyses are performed: 4.1) First-order cumulative local effect analysis: Selecting key target features to be explained For the selected target feature to be explained, its value range is divided into multiple bins. For each bin, the average change in the causal inference model's predicted output when the target feature value changes slightly is calculated as the local effect. Starting from the lower limit of the target feature value, the local effect is accumulated to obtain the first-order cumulative local effect curve, which is used to characterize the global average marginal effect of the feature on the prediction result. The calculation formula is: ; 4.2) Second-order interaction effect analysis: Selecting feature pairs For target feature pairs, after deducting their respective first-order effects, their second-order joint partial effects are calculated, and a second-order cumulative local effect surface describing the additional interactive contributions between target feature pairs is generated. This is used to identify which feature combinations produce synergistic or inhibitory effects in which value ranges, which is particularly important for understanding complex time-varying intervention mechanisms. 4.3) Quantification of Feature Effects Based on ALE: Based on the first-order cumulative local effect curve, its standard deviation is calculated to measure the importance of the feature: the larger the standard deviation, the wider the influence of the variable on the model prediction range in different value intervals. At the same time, indicators such as ALE Range (ALER) and ALE Deviation (ALED) are introduced to calculate the cumulative local effect range or average offset to quantify the strength of the feature effect; 4.4) Individual Heterogeneity Analysis Based on ICE: When there is a significant interaction effect, the first-order ALE is the global average effect. Further, the ICE (Individual Conditional Expectation) curve is introduced: For the target feature, other feature values are fixed, and the feature is predicted point by point under a series of values. Individual conditional expectation curves of multiple individuals under different feature values are plotted. Each ICE curve corresponds to one individual. The divergence of the curves reflects the heterogeneity between individuals. By analyzing the dispersion and shape pattern of the individual conditional expectation curve clusters, the differences in treatment effects among individuals can be revealed. Combining ALE and ICE can provide explanations for both the overall pattern and individual differences.
[0068] Example 2 Example 2 proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method of Example 1 described above.
[0069] The above are merely preferred embodiments of the present invention and do not constitute any limitation on the present invention. Any equivalent substitutions or modifications made by those skilled in the art to the technical solutions and content disclosed in the present invention without departing from the scope of the present invention shall be deemed to have remained within the protection scope of the present invention.
Claims
1. A method for deep temporal causal inference and explainability with removal of time-varying confounding, characterized in that, Includes the following steps: S1: data acquisition and pre-processing: acquiring a plurality of individual's time series dataset, the time series dataset comprising a sequence of outcome variable of each individual , a sequence of multi-dimension treatment variable , a sequence of time-varying covariate , and static features , and constructing historical information of each individual based on the time series dataset ; S2: Temporal deconfounding and latent variable generation: based on the historical information, learn and generate a set of time-evolving latent variables using a temporal deconfounding module , the latent variable sequence is used to replace the unobserved time-varying confounders, so that the different dimensions of the multi-dimensional treatment variable sequence are approximately conditionally independent between treatments given the latent variables and observed variables. S3: Weighted Causal Estimation: Based on the latent variable sequence, the historical information, and the multi-dimensional treatment variable sequence, the propensity network of the recurrent marginal structure network module is input, and the stable inverse probability weight of each individual at each time point is calculated; the loss function of the result prediction network of the recurrent marginal structure network module is weighted with the stable inverse probability weight, and the result prediction network is trained to learn the mapping relationship from the historical information, the latent variable sequence, and the current treatment to the result variable, so as to obtain a trained causal inference model; using the trained causal inference model, by inputting different counterfactual treatment paths, the corresponding potential result sequence is predicted, and the individual-level time-series causal effect (ITE) is calculated based on the potential result sequence under different treatment paths; S4: Model interpretability analysis: The trained causal inference model is regarded as the objective function. The cumulative local effect analysis method is used to calculate the first-order cumulative local effect curve and the second-order interaction effect curve of the multidimensional treatment variable sequence and the key time-varying covariate sequence to quantify their nonlinear marginal contribution and interaction contribution to the prediction of the potential outcome. The heterogeneity of the effect among individuals is analyzed based on the individual conditional expectation curve.
2. The deep temporal causal inference and explainability method that removes time-varying confounding of claim 1, wherein, In step S2, the recurrent neural network is an LSTM network; the temporal decontamination module sets up a multi-task multilayer perceptron at each time point, the multi-task multilayer perceptron has multiple output heads, which correspond to each treatment dimension in the multi-dimensional treatment variable sequence; the multi-task multilayer perceptron takes the latent variables, time-varying covariates and static features as inputs, and predicts the conditional assignment probability of each dimension in the multi-dimensional treatment variable sequence. Step S2 specifically involves: S21. Recursively encode the historical information using a recurrent neural network to generate potential states; S22. At each time point, the potential state is combined with the observation covariates at the current time and input into the multi-task multilayer perceptron, and the allocation probability or distribution parameters of the disposal under the current conditions are output. S23. The temporal decontamination module is trained by minimizing the loss function between the disposal allocation predicted by the multi-task multilayer perceptron and the actual disposal allocation, and the latent states generated during the training process are used as the sequence of latent variables.
3. The deep temporal causal inference and explainability method that removes time-varying confounding of claim 2, wherein, In the output head of the multi-task multilayer perceptron, for binary processing, the loss function adopts cross-entropy loss and uses the sigmoid activation function to output the probability. For continuous processing, the loss function adopts a log-likelihood-based loss function and uses a fully connected layer with Monte Carlo Dropout to output the conditional distribution parameters.
4. The deep causal time series inference and explainability method of removing time varying confounding of claim 1, wherein, After step S2, which involves decompression of time series data, the process also includes a latent variable validity verification step from the time series decompression module. This step includes: 1) On the validation set, for each time point , compute the observed statistics of treatment assignment: ; wherein, denotes the time treatment variable at time the conditional log-likelihood statistic for the model to measure the goodness of fit of the model to the treatment assignment mechanism; denotes the expectation operator with respect to the latent variable ; denotes the conditional probability or probability density of the treatment variable given the latent variable , static characteristics and time-varying covariates ; denotes the treatment variable at time ; denotes the latent variable at time , which is used to represent unobserved time-varying confounders; denotes the static characteristics of the individual ; denotes the time-varying covariates at time ; 2) Generate multiple sets of replication treatment samples based on the trained temporal decontamination module, and calculate the corresponding replication statistics; 3) Compare the distributions of the observed statistic and the replication statistic. If the p-value calculated based on the comparison results is within a preset reasonable range, then the latent variable is determined to be valid and used for subsequent causal estimation.
5. The deep temporal causal inference and explainability method that removes time-varying confounding of claim 1, wherein, In step S3, the recurrent edge structure network module comprises a propensity network and a result prediction network, the propensity network being used to learn a complete conditional probability distribution of treatment allocation and a simplified conditional probability distribution and based on this, to calculate a stable inverse probability weight at each time point; The stable inverse probability weights The formula for calculating is: ; Among them, the denominator For a given historical treatment and historical confusion, the complete conditional distribution is given; molecule A simplified distribution that relies solely on historical processing; the complete conditional distribution and simplified distribution All of these are learned by the tendency network in the recursive edge structure network module; the tendency network uses LSTM or variational RNN structure to model the multi-treatment time series; Indexed by the current time; To predict the time span, it means from time... arrive Time window length; This is the time index variable used in weight calculation to represent the time index from... arrive Each time step; For time The treatment variable or multidimensional treatment vector at any given time; For time The variables or history of actions taken at any given moment; The extreme weights of the stable inverse probability weights are truncated to the 1%–99th percentile and normalized according to the prediction window to prevent variance inflation caused by extreme weight values. The truncation method is as follows: calculate the 1% and 99th percentiles of the distribution of all weights in the dataset, increase the weights below the 1% percentile to the 1% percentile, decrease the weights above the 99th percentile to the 99th percentile, and normalize according to the prediction window.
6. The deep temporal causal inference and explainability method of removing time-varying confounding of claim 5, wherein, The result prediction network is a weighted LSTM encoder, whose input includes the historical information and the latent variable sequence. Its loss function is the weighted mean square error with the stable inverse probability weights added, as shown in the formula: ; wherein, a loss function value representing the result prediction network; a stable inverse probability weight representing the sample selection bias brought by different treatment paths at time ; a true result variable value representing the individual at time ; a predicted result of the result prediction network representing the individual at time .
7. The deep temporal causal inference and explainability method that removes time- varying confounding of claim 1, wherein, In step S3, the method for calculating the individual-level temporal causal effect (ITE) is as follows: The parameters of the trained causal inference model are fixed; For individual i, under the same historical information and potential variable sequence, the first treatment path and the second treatment path are input respectively to obtain the first potential outcome sequence and the second potential outcome sequence; The difference between the first potential outcome sequence and the second potential outcome sequence at the corresponding time point is calculated as the treatment effect of the individual at the corresponding time point, thus obtaining the individual-level time-dependent treatment effect curve.
8. The deep temporal causal inference and explainability method that removes time- varying confounding of claim 1, wherein, In step S4, the importance of the corresponding feature is measured by calculating the standard deviation of the first-order cumulative local effect (ALE) curve, and the effect strength of the corresponding feature is quantified by calculating the cumulative local effect range (ALER) or the cumulative local effect mean offset (ALED).
9. The deep temporal causal inference and explainability method of removing time-varying confounding of claim 8, wherein, The model interpretability analysis steps specifically include: 4.1) First-order cumulative local effect analysis: For the selected target feature to be explained, its value range is divided into multiple bins; for each bin, the average change in the predicted output of the causal inference model is calculated when the value of the target feature changes slightly, which is taken as the local effect; starting from the lower limit of the target feature value, the local effect is accumulated to obtain the first-order cumulative local effect curve, which is used to characterize the global average marginal effect of the feature on the prediction result; 4.2) Second-order interaction effect analysis: For each target feature pair, after deducting their respective first-order effects, the second-order joint partial effect is calculated, and a second-order cumulative local effect surface describing the additional interaction contribution between the target feature pairs is generated. 4.3) Characteristic effect quantification: Based on the first-order cumulative local effect curve, calculate its standard deviation to measure the importance of the feature, and calculate the cumulative local effect range or average offset to quantify the intensity of the characteristic effect. 4.4) Individual heterogeneity analysis: For the target feature, fix the values of other features and plot the individual condition expectation curves of multiple individuals under different feature values; by analyzing the dispersion and shape pattern of the cluster of individual condition expectation curves, the differences in treatment effects among individuals are revealed.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 9.