## Graph Representation Learning via Causal Diffusion for Out-of-Distribution Recommendation

Chu Zhao Northeastern University Shenyang, China chuzhao@stumail.neu.edu.cn

Enneng Yang Northeastern University Shenyang, China ennengyang@stumail.neu.edu.cn

Yuliang Liang Northeastern University Shenyang, China liangyuliang@stumail.neu.edu.cn

Pengxiang Lan Northeastern University Shenyang, China pengxianglan@stumail.neu.edu.cn

Yuting Liu Northeastern University Shenyang, China yutingliu@stumail.neu.edu.cn

Guibing Guo ∗ Northeastern University Shenyang, China guogb@swc.neu.edu.cn

Jianzhe Zhao Northeastern University Shenyang, China zhaojz@swc.neu.edu.cn

Xingwei Wang ∗ Northeastern University Shenyang, China wangxw@mail.neu.edu.cn

## ABSTRACT

Graph Neural Networks (GNNs)-based recommendation algorithms typically assume that training and testing data are drawn from independent and identically distributed (IID) spaces. However, this assumption often fails in the presence of out-of-distribution (OOD) data, resulting in significant performance degradation. In this study, we construct a Structural Causal Model (SCM) to analyze interaction data, revealing that environmental confounders (e.g., the COVID-19 pandemic) lead to unstable correlations in GNN-based models, thus impairing their generalization to OOD data. To address this issue, we propose a novel approach, graph representation learning via causal diffusion ( CausalDiffRec ) for OOD recommendation. This method enhances the model's generalization on OOD data by eliminating environmental confounding factors and learning invariant graph representations. Specifically, we use backdoor adjustment and variational inference to infer the real environmental distribution, thereby eliminating the impact of environmental confounders. This inferred distribution is then used as prior knowledge to guide the representation learning in the reverse phase of the diffusion process to learn the invariant representation. In addition, we provide a theoretical derivation that proves optimizing the objective function of CausalDiffRec can encourage the model to learn environment-invariant graph representations, thereby achieving excellent generalization performance in recommendations under distribution shifts. Our extensive experiments validate the effectiveness of CausalDiffRec in improving the generalization of OOD

∗ Corresponding authors.

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.

WWW'25, April 28-May 2, 2025, Sydney, NSW, Australia

© 2025 Copyright held by the owner/author(s). Publication rights licensed to ACM.

ACM ISBN 979-8-4007-1274-6/25/04...$15.00

https://doi.org/10.1145/3696410.3714849

data, and the average improvement is up to 10.69% on Food, 18.83% on KuaiRec, 22.41% on Yelp2018, and 11.65% on Douban datasets. Our code is available at https://github.com/user683/CausalDiffRec.

## CCS CONCEPTS

- · Information systems → Recommender systems .

## KEYWORDS

Graph Recommendation, Distributionally Robust Optimization, Out-of-Distribution

## ACMReference Format:

Chu Zhao, Enneng Yang, Yuliang Liang, Pengxiang Lan, Yuting Liu, Jianzhe Zhao, Guibing Guo, and Xingwei Wang. 2025. Graph Representation Learning via Causal Diffusion for Out-of-Distribution Recommendation. In Proceedings of the ACM Web Conference 2025 (WWW '25), April 28-May 2, 2025, Sydney, NSW, Australia. ACM, New York, NY, USA, 13 pages. https: //doi.org/10.1145/3696410.3714849

## 1 INTRODUCTION

Graph Neural Networks (GNN) [44, 58, 59], due to their exceptional ability to learn high-order features, have been widely applied in recommendation systems. GNN-based recommendation algorithms [8, 30, 43] learn user and item representations by aggregating information from neighboring nodes in the user-item interaction graph and then computing their similarity to predict user preferences. In addition, researchers have introduced various other techniques to continuously improve GNN-based recommendation algorithms. For example, integrating attention mechanisms [7, 25] with knowledge graphs [14] led to improving recommendation accuracy. Furthermore, the introduction of contrastive learning aims to improve the robustness of recommendation algorithms [17, 17, 51].

Despite significant progress in enhancing recommendation accuracy, most existing methods assume that test and training datasets follow an independently and identically distributed (IID) pattern, focusing on performance improvements under this assumption. Such methods struggle to generalize effectively to out-of-distribution (OOD) data, where test data distributions markedly differ from

training data [13, 23, 48]. For example, as shown in Figure 1, the popularity of medical supplies surged during the COVID-19 pandemic, alongside increased demand for fitness equipment and electronics due to government-imposed homestays. The recommender systems might infer that purchasing masks correlates with buying these additional items, driven by the common 'pandemic' factor rather than direct causation. Once the pandemic subsides, demand shifts, reducing the popularity of masks and related items. Consequently, the system may inaccurately recommend fitness equipment and electronics to mask buyers under the new distribution, leading to poor performance. Additionally, tests on the Yelp2018 dataset, comparing IID and OOD sets, demonstrate a significant performance drop. LightGCN [9] experiences an average 29.03% decline across three metrics on OOD data compared to IID settings, highlighting the robustness issues of GNN-based models in OOD scenarios. This challenge motivates the development of a recommendation framework with strong generalization capabilities for handling distribution shifts.

Several studies have aimed to enhance the generalization of recommender systems on OOD datasets by using causal inference to address data distribution shifts. For instance, CausPref [11] builds on NeuMF [10] by implementing invariant user preference causal learning and anti-preference negative sampling to boost model generalization. COR [31] utilizes a Variational Auto-Encoder for causal modeling by inferring unobserved user features from historical interactions. However, these methods are not tailored for GNNs, complicating their adaptation to GNN-based approaches.

Other researchers have adopted techniques like graph contrastive learning and graph data augmentation to improve the robustness of GNN-based recommendation algorithms, such as SGL [40], SimGCL [50], and LightGCL [1]. These approaches mainly address noise or popularity bias but underperform when test data distributions are unknown or varied, as evidenced by experimental results. Recently, a few GNN-based methods [53] have been proposed to enhance generalization across multiple distributions, but they lack strong theoretical backing.

Given these limitations, there is an urgent need to design theoretically grounded GNN-based methods to address distribution shifts. In this paper, we use invariant learning to improve the generalization of the OOD dataset. Utilizing insights from the prior knowledge of environment distribution and invariant learning [5, 20, 57] enhances model stability across varied environments. This is achieved by acquiring invariant representations, boosting the model's generalization capabilities and overall robustness. Following the research approach of prior work [52], we further analyze and argue that designing recommendation models based on invariant learning theory still faces the following two challenges:

- · (1) How to infer the distribution of underlying environments from observed user-item interaction data?
- · (2) Howtorecognize environment-invariant patterns amid changing user behaviors and preferences?

In this paper, we first develop a Structural Causal Model (SCM) to analyze data generation processes in recommender systems, specifically addressing the impact of data distribution shifts on GNN-based recommendation algorithms. We find that latent environmental variables can lead these models to capture unstable

Figure 1: Left and Middle: An example illustrates the popularity distribution shift, i.e., how the popularity of masks, disinfectants, exercise equipment, and electronic products changes with the COVID-19 pandemic. Right: We constructed both IID and OOD sets on the Yelp2018 dataset and compared the performance of the LightGCN model [9] on these datasets. Wefound a significant average performance drop (i.e., 29 03% . ) in OOD data across three metrics.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-fca78cc4-b629-418a-9177-7f8328817fb5.jpg)

correlations, hindering their generalization to OOD data. To tackle this, we introduce CausalDiffRec, a novel method using causal inference to remove these unstable correlations by learning invariant representations across different environments. CausalDiffRec comprises an environment generator to create diverse data distributions, an environment inference module to identify and utilize environmental components, and a diffusion module guiding invariant representation learning. Theoretically, we prove that CausalDiffRec can achieve better OOD generalization by identifying invariant representations across varying environments.

The contributions of this paper are concluded as follows:

- · Causal Analysis . We construct the SCM and analyze the generalization ability of GNN-based recommendation models on OOD data from the perspective of data generation. Based on our analysis and experimental results, we conclude that environmental confounders lead the model to capture unstable correlations, which is the key reason for its failure to generalize under distribution shifts.
- · Methodology . We introduce CausalDiffRec, a new GNN-based method for OOD recommendation, comprising three main modules: environment generation, environment inference, and diffusion. The environment generation module simulates user data distributions under various conditions, the environment inference module uses causal inference and variational approximation to deduce environment distribution, and the diffusion module facilitates graph representation learning. Theoretical analysis confirms that optimizing CausalDiffRec's objective function enhances model generalization.
- · Experimental Findings . We constructed three common types of distribution shifts across four datasets and conducted comparative experiments. The experiments demonstrate that CausalDiffRec consistently outperforms baseline methods. Specifically, CausalDiffRec exhibits enhanced generalization capabilities when dealing with OOD data, achieving a maximum metric improvement rate of 36.73%.

## 2 PRELIMINARY

## 2.1 GNN-based Recommendation

Given the observed implicit interaction matrix R ∈ { 0 1 , } 𝑚 𝑛 × , in which U = { 𝑢 ,𝑢 , . . . , 𝑢 1 2 𝑚 } represents the set of users, I =

{ 𝑖 1 , 𝑖 2 , . . . , 𝑖 𝑛 } represents the set of items, 𝑚 and 𝑛 denote the number of users and items, respectively. For the elements in the interaction matrix, 𝑟 𝑢𝑖 = 1 indicates an interaction between user 𝑢 and item 𝑖 , otherwise 0. In GNN-based recommendation algorithms, the user-item interaction matrix R is first transformed into a bipartite graph 𝐺 = {V E} , . We employ V to represent the node set and E = {( 𝑢, 𝑖 )| 𝑢 ∈ U , 𝑖 ∈ I , 𝑟 𝑢𝑖 = 1 } denotes the edge set. Given a user-item interaction graph G 𝑢 and the true user interactions 𝑦 𝑢 with respect to (w.r.t) user 𝑢 , the optimization objective of GNN-based methods can be expressed as:

$$\arg \min _ { \theta } \Xi _ { ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( G, Y ) } [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) ], \quad ( 1 ) \quad _ { \mathfrak { r } \colon \mathfrak { r } }$$

where 𝑓 𝜃 (·) is a learner that learns representations by aggregating high-order neighbor information from the user-item interaction graph. 𝑙 denotes the loss function and 𝑃 𝐺,𝑌 ( ) represents the joint distribution of the interaction graph 𝐺 and true label 𝑌 .

## 2.2 Denoising Diffusion Probabilistic Models

Denoising Diffusion Probabilistic Models (DDPM) [12] have been widely used in the field of image and video generation. The key idea of DDPM is to achieve the generation and reconstruction of the input data distribution through a process of gradually adding and removing noise. It leverages neural networks to learn the reverse denoising process from noise to real data distribution.

The diffusion process in recommender system models the evolution of user preferences and item information through noise addition and iterative recovery. Initially, data x 0 sampled from 𝑞 ( x ) undergo a forward diffusion to generate noisy samples x 1 , . . . , x 𝑇 over 𝑇 steps. Each step adds Gaussian noise, transforming the data distribution incrementally [12]:

$$q ( { \mathbf x } _ { t } | { \mathbf x } _ { t - 1 } ) = { \mathcal { N } } \left ( { \mathbf x } _ { t } ; \sqrt { 1 - \beta _ { t } } { \mathbf x } _ { t - 1 }, \beta _ { t } { \mathbf l } \right ), \quad \ \ ( 2 ) \quad \bullet \underbrace { \mathfrak { L } } _ { \mathfrak { e } }$$

where 𝛽 𝑡 ∈ ( 0 1 , ) controls the level of the added noise at step 𝑡 . In the reverse phase, the aim is to restore the original data by learning a model 𝑝 𝜃 to approximate the reverse diffusion from x 𝑇 to x 0 . The process, governed by 𝑝 𝜃 ( x 𝑡 -1 | x 𝑡 ) , uses the mean 𝜇 𝜃 and covariance Σ 𝜃 learned via neural networks:

$$p _ { \theta } ( { \mathbf x } _ { t - 1 } | { \mathbf x } _ { t } ) = \mathcal { N } \left ( { \mathbf x } _ { t - 1 } ; \mu _ { \theta } ( { \mathbf x } _ { t }, t ), \Sigma _ { \theta } ( { \mathbf x } _ { t }, t ) \right ). \quad \ \left ( 3 \right ) \quad r a t \epsilon$$

The reverse process is optimized to minimize the variational lower bound (VLB), balancing the fidelity of reconstruction and the simplicity of the model [38]:

$$\cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \\ & \quad - \log p _ { \theta } ( x _ { 1 } | x _ { 1 } ), \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cdot \quad \cd.$$

where 𝐷 𝐾𝐿 denotes the Kullback-Leibler (KL) divergence. Following [12], we mitigate the training instability issue in the model by expanding and reweighting each KL divergence term in the VLB with specific parameterization. Therefore, we have the following mean squared error loss:

$$\mathcal { L } _ { \text{simple} } = \mathbb { E } _ { t, x _ { 0 }, \epsilon _ { t } } \left [ \left \| \epsilon _ { t } - \epsilon _ { \theta } \left ( \sqrt { \alpha } _ { t } x _ { 0 } + \sqrt { 1 - \alpha _ { t } } \epsilon, t \right ) \right \| ^ { 2 } \right ], \ \ ( 5 ) \quad \ \ \ g e n { \epsilon } { \text{first} }$$

where 𝜖 𝑡 ∼ N( 0 , I ) is the noise for injection in forward process, 𝜖 𝜃 (·) denotes a function approximator that neural networks can replace, and 𝛼 𝑡 = ˛ 𝑇 𝑡 = 1 1 -𝛽 𝑡 . This framework allows the model

Figure 2: The structure causal model for GNN-based recommendation

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-4b6981b1-f9f6-4035-9a2b-aafdb30f7188.jpg)

to effectively learn noise-free representations and improve recommendation accuracy.

## 2.3 Invariant Pattern Recognition Mechanism

Invariant learning [23, 52] is often used to develop predictive models that can generalize to out-of-distribution (OOD) data, which originates from different environments. Existing invariant learning methods typically rely on the following assumptions:

Assumption : For a given user-item interaction graph (i.e., data distribution 𝐷 ), these interaction data are collected from 𝐾 different environments 𝐸 . User behavior patterns exist independently of the environment and can be used to generalize out-of-distribution user preference prediction. There exists an optimal invariant graph representation learning 𝐹 ∗ (·) satisfying:

- · Invariance Property . ∀ 𝑒 ∈ 𝐷 𝐸 ( ) , 𝑃 𝜃 ( 𝑌 𝐹 | ∗ ( 𝐺 , 𝐸 ) = 𝑒, 𝐼 ) = 𝑃 𝑌 𝐹 ( | ∗ ( 𝐺 , 𝐼 ) ) .
- · Sufficiency Condition . 𝑌 = 𝐹 ∗ ( 𝐺 ) + 𝜖, 𝜖 ⊥ 𝐸 , where ⊥ indicates statistical independence and 𝜖 is random noise.

The invariance property assumption indicates that a graph representation learning model exists capable of learning invariant user-item representations across different data distribution environments. The sufficiency condition assumption means that the learned invariant representations enable the model to make accurate predictions.

## 3 METHODOLOGY

In this section, we first construct SCM and identify environmental confounders as the key reason for the failure of GNN-based models to generalize on OOD (out-of-distribution) data. Subsequently, we introduce the variational inference to infer the true distribution of the environment. We use the diffusion model to learn the representation based on invariant learning. Finally, we provide rigorous theoretical proof of CausalDiffRec that can achieve great generalization. The model framework is illustrated in Figure 3.

## 3.1 SCM of GNN-based Recommendation

To explore the reasons behind the failure of GNN-based models to generalize on OOD data, we follow previous works [41, 42, 47] and first construct the SCM for data generation and data modeling in recommendation systems, as shown in Figure 2 (a) and Figure 2 (b). We find that environmental confounding factors are the key reason for the generalization failure of GNN-based methods. Finally, we

design an intervention model in Figure 2 (c) to eliminate the impact of environmental confounding factors.

- 3.1.1 Causal View in GNN-based Recommendation . In Figure 2, the three causal relations are derived from the definitions of data generation. The detailed causal analysis behind them is presented as follows:
- · Environmental Factors ( 𝐸 ) : These represent unseen factors such as sudden events or policies that affect user-item interaction graphs ( 𝐺 ) and true labels ( 𝑌 ). Invariant attributes ( 𝐼 ), like user gender and item categories, remain unaffected by these factors. Prior research [11] suggests leveraging these invariant features can enhance model generalization in OOD environments.
- · 𝐸 → 𝐺 : This describes the direct effect of the environment on user-item interactions, defined by the probability 𝑃 𝐺 𝐸 ( | ) . For instance, cold weather might increase user interactions with warm clothing.
- · 𝐺 → 𝑌 : This reflects how the interaction graph G influences the user behavior label 𝑌 , characterized by the GNN model 𝑌 = 𝑓 𝜃 ( 𝐺 ) . With fixed model parameters 𝜃 , the relationship between 𝐺 and 𝑌 is deterministic.
- · 𝐼 → 𝑌 : Invariant attributes directly affect the user behavior label 𝑌 . For instance, a user might consistently prefer a specific restaurant, where attributes like the location remain constant.
- · 𝐸 → 𝑌 : The environment directly impacts the user behavior label 𝑌 , independent of user-item interactions. For example, during holidays, users might be more inclined to buy holiday-related items regardless of past interactions.

In real-world scenarios, training data is collected from heterogeneous environments. Therefore, the environment directly influences the distribution of the data and the prediction result, which can be explicitly represented as 𝑃 𝑌,𝐺 𝐸 ( | ) = 𝑃 𝐺 𝐸 𝑃 𝑌 𝐺, 𝐸 ( | ) ( | ) . If we employ 𝐷 tr ( 𝐸 ) to represent the training data distribution for unobserved environments, the GNN-based model, when faced with OOD data, can rewrite Eq. (1) as:

$$\arg \min _ { \theta } \mathbb { E } _ { e \sim D _ { t r } ( E ), ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( G, Y | E = e ) } [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) | e ], \ ( 6 ) \quad \stackrel { \kappa } { \text{Eq.\} } }$$

Eq. (6) shows that environment 𝐸 affects the data generation used for training the GNN-based recommendation model.

3.1.2 Confounding Effect of E . Figure 2 (a) and Figure 2 (b) illustrate the causal relationships in data generation and model training for graph-based recommendation algorithms. 𝐸 acts as the confounder and directly optimizing 𝑃 𝑌 𝐺 ( | ) leads the GNN-based recommendation model to learn the shortcut predictive relationship between G 𝑢 and 𝑦 𝑢 , which is highly correlated with the environment 𝐸 . During the model training process, there is a tendency to use this easily captured shortcut relationship to model user preferences. However, this shortcut relationship is highly sensitive to the environment 𝐸 . When the environment of the test set is different from that of the training set (i.e., 𝐷 𝑡𝑟 ( 𝐸 ) ≠ 𝐷 𝑡𝑠 ( 𝐸 ) ), this relationship becomes unstable and invalid. The recommendation model that excessively learns environment-sensitive relationships in the training data will struggle to accurately model user preferences when faced with OOD data during the testing phase, resulting in decreased recommendation accuracy.

3.1.3 Intervention . Through the above analysis, we can improve the generalization ability of GNN-based recommendation models by guiding the model to uncover stable predictive relationships behind the training data, specifically those that are less sensitive to environmental changes. Thus, we can eliminate the influence of environmental confounders on model predictions. Specifically, we learn stable correlations between user item interaction G 𝑢 and ground truth 𝑦 𝑢 by optimizing 𝑃 𝜃 ( 𝑌 𝑑𝑜 𝐺 | ( )) instead of 𝑃 𝜃 ( 𝑌 𝐺 | ) . In causal theory, the 𝑑𝑜 -operation signifies removing the dependencies between the target variable and other variables. As shown in Figure 2 (c), by cutting off the causal relationship between the environment variables and the user interaction graph, the model no longer learns the unstable correlations between G 𝑢 and 𝑦 𝑢 . The 𝑑𝑜 -operation simulates the generation process of the interaction graph 𝐺 , where environmental factors do not influence the useritem interactions. This operation blocks the unstable backdoor path 𝐺 ← 𝐸 → 𝑌 , enabling the GNN-based recommendation model to capture the desired causal relationship that remains invariant under environmental changes.

Theoretically, 𝑃 𝜃 ( 𝑌 𝑑𝑜 𝐺 | ( )) can be computed through randomized controlled trials, which involve randomly collecting new data from any possible environment to eliminate environmental bias. However, such physical interventions are challenging. For instance, in a short video recommendation setting, it is impossible to expose all short videos to a single user, and it is also impractical to control the environment of data interactions. In this paper, we achieve a statistical estimation of 𝑃 𝜃 ( 𝑌 𝑑𝑜 𝐺 | ( )) by leveraging backdoor adjustment. We have:

$$P _ { \theta } ( Y | d o ( G ) ) = \Xi _ { e \sim D _ { t r } ( E ) } [ P _ { \theta } ( Y | G, E, I ) ]. \quad \quad ( 7 )$$

The derivation process is shown in Appendix B.1. Through the aforementioned backdoor adjustment, the influence of the environment 𝐸 on the generation of 𝐺 can be eliminated, enabling the model to learn correlations independent of the environment. However, in recommendation scenarios, environmental variables are typically unobservable or undefined, and their prior distribution 𝑃 ( 𝐸 = 𝑒 ) cannot be computed. Therefore, directly optimizing the Eq. (7) is challenging.

## 3.2 Model Instantiations

3.2.1 Environment Inference . This work introduces a variational inference method and proposes a variational inference-based environment instantiation mechanism. The core idea is to use variational inference to approximate the true distribution of environments and generate environment pseudo-labels as latent variables. The following tractable evidence lower bound (ELBO) can be obtained as the learning objective:

$$\underset { \text{$to} } { \text{to} } \quad \log P _ { \theta } ( Y | d o ( G ) ) \geq \mathcal { L } _ { e n v { I n f } } = \mathbb { E } _ { Q _ { \phi } ( E | G, I ) } [ \log P _ { \theta } ( Y | G, E, I ) ] \\ \text{he}$$

where 𝑄 𝜙 ( 𝐸 𝐺, 𝐼 | ) denotes environment estimation, which draws samples from the true distribution of the environment 𝐸 𝐷 . 𝐾𝐿 represents the Kullback-Leibler (KL) divergence of the volitional distribution 𝑄 𝜙 ( 𝐸 𝐺, 𝐼 | ) and the prior distribution 𝑃 𝜃 (E). 𝑃 𝜃 ( 𝑌 𝐺, 𝐸, 𝐼 | ) is the graph representation learning module that employs the useritem interaction graph and the node attributes of users and items as input to learn invariant representations. Section 3.2.2 will provide a

detailed introduction to the graph representation learning module. The derivation process of Eq. (8) is displayed in Appendix B.2.

3.2.2 Invariant Representation Learning . This section mainly consists of an environment generator, a diffusion-based graph representation learning module, and a recommendation module. Next, we will detail how they collaborate to enhance the generalizability of GNN-based models on OOD data and improve recommendation accuracy.

Environment Generator . In real-world recommendation scenarios, training datasets are collected in various environments. However, for a single user-centric interaction graph, the training dataset comes from a single environment. We need to learn environment-invariant correlations from training data originating from different environments to achieve the generalization capability of GNN-based recommendation models under distribution shifts. To circumvent this dilemma, this paper designs an environment generator 𝑔 𝜔 𝑘 (·)( 1 ≤ 𝑘 ≤ 𝐾 ) , which takes the user's original interaction graph 𝐺 as input and generates a set of 𝐾 interaction graphs { 𝐺 𝑖 } 𝐾 𝑖 = 1 to simulate training data from different environments. The optimization objective is expressed as follows:

$$\mathcal { L } _ { g e n e r a t o r } = \left [ \text{Var} ( \mathcal { L } ( g _ { \omega _ { k } } ( G ) ) \, \colon 1 \leq k \leq K ) \right ], \quad ( 9 ) \quad \text{def}$$

where 𝑉𝑎𝑟 (·) denotes the variance and L(·) is the loss function. Following existing work [42], we modify the graph structure by adding and removing edges. Given a Boolean matrix 𝐵 𝑘 , the adjacency matrix 𝐴 of the graph, and its complement 𝐴 ′ , the 𝑘 -th generated view for the original view is 𝐴 𝑘 = 𝐴 + 𝐵 𝑘 ⊙ ( 𝐴 -𝐴 ′ ) . Since 𝐵 𝑘 is a discrete matrix and not differentiable, it cannot be optimized directly. To address this issue, we borrow the idea from [42] and use reinforcement learning to treat graph generation as a decision process and edge editing as actions. Specifically, for view 𝑘 , we consider a parameter matrix 𝜃 𝑘 = { 𝜃 𝑘 𝑛𝑚 } . For the 𝑛 -th node, the probability of exiting the edge between it and the 𝑚 -th node is given by:

$$h ( a _ { n m } ^ { k } ) = \frac { \exp ( \theta _ { n m } ^ { k } ) } { \sum _ { m ^ { \prime } = 1 } ^ { m ^ { \prime } = m } \exp ( \theta _ { n m ^ { \prime } } ^ { k } ) }. \quad \quad ( 1 0 ) \quad \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$$

Wethensample 𝑠 actions { 𝑏 𝑘 𝑛𝑚𝑡 } 𝑠 𝑡 = 1 from a multinomial distribution 𝑀 ℎ 𝛼 ( ( 𝑘 𝑛 1 ) , . . . , ℎ ( 𝛼 𝑘 𝑛𝑚 )) , which give the nonzero entries in the 𝑛 -th row of 𝐵 𝑘 . The reward function 𝑅 𝐺 ( 𝑘 ) can be defined as the inverse loss. We can use the reinforcement algorithm to optimize the generator with the gradient:

$$\nabla _ { \theta _ { k } } \log h _ { \theta _ { k } } ( A _ { k } ) R ( G _ { k } ), \text{ \quad \ \ } ( 1 1 )$$

where 𝜃 𝑘 is the model parameters and ℎ 𝜃 𝑘 ( 𝐴 𝑘 ) = ˛ ˛ 𝑛 𝑠 𝑡 = 1 ℎ 𝑏 ( 𝑘 𝑛𝑚𝑡 ) . Optimizing Eq. (9) ensures that the generated graphs have large differences.

Causal Diffusion . Given the generated interaction graph 𝐺 𝑘 = ( 𝐴 , 𝐼 𝑘 ) where 𝐴 is the adjacency matrix, and 𝐼 is the feature matrix of users or items, instead of directly using 𝐺 𝑘 as input for diffusion, weusethe encoder from the Variational Graph Autoencoder (VGAE) to compress 𝐺 𝑘 to a low-dimensional vector x 0 𝑘 ∼ N( 𝜇 𝑘 , 𝜎 𝑘 ) for subsequent environment inference and graph invariant representation learning. The encoding process is as follows:

$$q _ { \psi } ( { \mathbf x } _ { k } ^ { 0 } | A _ { k }, I ) = N ( { \mathbf x } _ { k } ^ { 0 } | \mu _ { k }, \sigma _ { k } ), \text{ \quad \ \ } ( 1 2 )$$

where 𝜇 𝑘 = 𝐺𝐶𝑁 𝜇 ( 𝐴 , 𝐼 𝑘 ) is matrix of mean vectors and 𝜎 𝑘 = 𝐺𝐶𝑁 𝜎 ( 𝐴 , 𝐼 𝑘 ) denotes standard deviation. The 𝐺𝐶𝑁 (·) is the graph convolution network in the graph variational autoencoder. According to the reparameterization trick, x 0 𝑘 can be calculated as follows:

$$\mathbf x _ { k } ^ { 0 } = \mu _ { k } + \sigma _ { k } \odot \epsilon, \text{ \quad \ \ } \text{(13)}$$

where 𝜖 ∼ 𝑁 ( 0 , 𝐼 ) and ⊙ is the element product. Latent embedding x 0 𝑘 will be used as the input for the environment inference module to generate environment pseudo-labels. Meanwhile, x 0 𝑘 will do the forward and reverse processes in the latent space to learn the user/item embeddings in DDPM. The forward process can be calculated as:

$$q ( x _ { k } ^ { 1 \colon T } \, | \, x _ { k } ^ { 0 } ) = \prod _ { t = 1 } ^ { T } q ( x _ { k } ^ { t } \, | \, x _ { k } ^ { t - 1 } ). \quad \quad ( 1 4 )$$

After obtaining the environment approximation variable 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 = 𝑄 𝐸 𝐺 , 𝐼 ( | 𝑘 ) according to Eq. (8), the pair of latent variables ( 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 , x 𝑇 𝑘 ) to learn the invariant graph representation. We approximate the inference distribution by parameterizing the probabilistic decoder through a conditional DDPM 𝑝 𝜃 ( x 𝑡 -1 𝑘 | x 𝑇 𝑘 , 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) . Using DDPM, the forward process is entirely deterministic except for 𝑡 = 1. We define the joint distribution of the reverse generative process as follows:

$$p _ { \theta } ( x _ { k } ^ { 0 \colon T } \, | \, z _ { c a u s a l } ) = p ( x _ { k } ^ { T } ) \prod _ { t = 1 } ^ { T } p _ { \theta } ( x _ { k } ^ { t - 1 } \, | \, x _ { k } ^ { t }, z _ { c a u s a l } ). \quad ( 1 5 )$$

$$\ni _ { \ } e ^ { \prime } \Phi _ { \theta } ( x _ { k } ^ { t - 1 } | x ) = \mathcal { N } \left ( x _ { k } ^ { t - 1 } ; \mu _ { \theta } ( x _ { k } ^ { t }, z _ { c a u s a l }, t ), \Sigma _ { \theta } ( x _ { k } ^ { t }, z _ { c a u s a l }, t ) \right ).$$

The loss function in Eq. (5) can be rewritten as:

$$\mathcal { L } _ { \text{Invsample} } = \mathbb { E } _ { t, x _ { 0 }, \epsilon _ { t } } \left [ \left \| \epsilon _ { t } - \epsilon _ { \theta } \left ( x _ { k } ^ { t }, z _ { c a u s a l }, t \right ) \right \| ^ { 2 } \right ], \quad ( 1 7 )$$

where x 𝑡 𝑘 = √ 𝛼 𝑡 x 0 𝑘 + √ 1 -𝛼 𝑡 𝝐 . After obtaining the reconstructed output vector R = x 0 ′ 𝑘 from DDPM, it will be used as the input for the decoder of the variational graph decoder, which then reconstructs the input graph. The entire process is illustrated as follows:

$$\tilde { A } _ { k } = \phi ( \mathcal { R R } ^ { \top } ),$$

where 𝜙 (·) is the activation function (the sigmoid function is used in this paper). The VGAE is optimized by the variational lower bound:

$$\mathcal { L } _ { V G A E } & = \Xi _ { q _ { \psi } ( x _ { k } ^ { 0 } | A _ { k }, I ) } \left [ \log p _ { \theta } ( \hat { A } _ { k } | { \mathbf x } _ { k } ^ { 0 } ) \right ] \\ & \quad - D _ { K L } \left ( q _ { \psi } ( x _ { k } ^ { 0 } | A _ { k }, I ) \ \| \ p ( { \mathbf x } _ { k } ^ { 0 } ) \right ).$$

Prediction and Joint Optimization . Using the well-trained diffusion model to sample the final embeddings for user preference modeling:

$$\hat { r } _ { u, i } = e _ { u } ^ { \top } e _ { i },$$

where 𝑒 𝑢 and 𝑒 𝑖 denote the final user embedding w.r.t 𝑢 -th user and item embedding w.r.t 𝑖 -th item, respectively. Without loss of generality, LightGCN is used as the recommendation backbone, and Bayesian Personalized Ranking (BRP) loss is employed to optimize the model parameters:

$$\mathcal { L } _ { r e c } = \sum _ { u, v ^ { + }, v ^ { - } } - \log \sigma ( \hat { r } _ { u, v ^ { + } } - \hat { r } _ { u, v ^ { - } } ), \quad \quad ( 2 1 )$$

Figure 3: Overall framework illustration of the proposed CausalDiffRec model.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-aff22f1b-e5ac-4b6a-9fa2-d7ca92df9f3c.jpg)

where ( 𝑢, 𝑣 + , 𝑣 - ) is a triplet sample for pairwise recommendation training. 𝑣 + represents positive samples from which the user has interacted, and 𝑣 -are the negative samples that are randomly drawn from the set of items with which the user has not interacted, respectively. We use a joint learning strategy to optimize CausalDiffRec:

$$\mathcal { L } = & \mathcal { L } _ { r e c } + \lambda _ { 1 } \cdot \mathcal { L } _ { \text{generator} } \\ & + \lambda _ { 2 } \cdot ( \mathcal { L } _ { \text{VGAE} } + \mathcal { L } _ { \text{Invsample} } ) + \lambda _ { 3 } \cdot \mathcal { L } _ { \text{envInf} }, \quad \ \ ( 2 2 ) \quad \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$$

where 𝜆 1 , 𝜆 2 , and 𝜆 3 are hyper-parameters. We provide rigorous theoretical proof in appendix A that optimizing the loss function in Eq. (22) can encourage the model to learn environment-invariant graph representations, thereby achieving generalization in out-ofdistribution data recommendations. Model complexity analysis is provided in Appendix F.

## 4 EXPERIMENTS

In this section, we conducted extensive experiments to validate the performance of CausalDiffRec and address the following key research questions:

- · RQ1 : How does CausalDiffRec compare to the state-of-the-art strategies in both OOD and IID test evaluations?
- · RQ2 : Are the proposed components of CausalDiffRec effective for OOD generalization?
- · RQ3 : How do hyperparameter settings affect the performance of CausalDiffRec?

## 4.1 Experimental Settings

Datasets .We evaluate the performance of our proposed CausalDiffRec method under three common data distribution shifts across four real-world datasets: Food 1 , KuaiRec 2 Yelp2018 3 , and Douban 4 comprise raw data from the Douban system. Detailed statistics of the datasets are presented in Table 1. The detailed information and processing specifics of the dataset can be found in Appendix C.

Baselines . We compare the CusalDiffRec with the state-of-theart models: LightGCN[40], SGL [40], SimGCL[50], LightGCL[1], InvPref [39], InvCF [55], AdvDrop [53], AdvInfo [54], and DR-GNN [28]. Appendix E presents the detailed information of the baselines.

1 https://www.aclweb.org/anthology/D19-1613/

2 https://kuairec.com

3 https://www.yelp.com/dataset

4 https://www.kaggle.com/datasets/

## 4.2 Overall Performance (RQ1)

This section compares CausalDiffRec's performance and baselines under various data shifts and conducts a performance analysis.

Evaluation on temporal shift : Table 1 shows that CausalDiffRec significantly outperforms SOTA models on the Food dataset, with improvements of 1.99%, 24.89%, 6.03%, and 9.68% in Recall and NDCG. This indicates CausalDiffRec's effectiveness in handling temporal shift. DRO also excels in this area, with a 15% improvement over LightGCN in NDCG@20, due to its robust optimization across various data distributions. CDR surpasses GNN-based models thanks to its temporal VAE-based architecture, capturing preference shifts from temporal changes.

Evaluation on exposure shift : In real-world scenarios, only a small subset of items is exposed to users, leading to non-random missing interaction records. Using the fully exposed KuaiRec dataset, CausalDiffRec consistently outperforms baselines, with improvements ranging from 6.90% to 28.83%, indicating its capability to handle exposure bias. DRO and AdvInfoNce also show superior performance in NDCG and Recall metrics, enhancing the generalization of GNN-based models and demonstrating robustness compared to LightGCN.

Evaluation on popularity shift . We compare model performance on the Yelp2018 and Douban datasets, showing that our model significantly outperforms the baselines. On Douban, CausalDiffRec achieves 8.22% to 17.96% improvement, and on Yelp2018, the improvements range from 11.24% to 36.73%. Methods using contrastive learning (e.g., SimGCL, LightGCL, AdvInfoNce) outperform other baselines in handling popularity shifts. This is because the InfoNCE loss helps the model learn a more uniform representation distribution, reducing bias towards popular items. InvPref performs best among the baselines on Yelp2018, using clustering for contextual labels, unlike our variational inference approach. Our method, tailored for graph data, aggregates neighbor information for better recommendation performance than matrix factorization-based methods.

Additionally, in Table 4, we report the performance of CausalDiffRec compared to several baseline models that use LightGCN as the backbone. From the table, we observe the following: 1) These baseline models outperform LightGCN on IID datasets; 2) CausalDiffRec outperforms all baseline models across all metrics. This indicates that CausalDiffRec also performs well on IID datasets. We attribute

Table 1: The performance comparison between the baselines and CausalDiffRec on the four datasets with three data distribution shifts. The best results are highlighted in bold, and the second-best results are underlined. 'Impro.' denotes the relative improvements of CausalDiffRec over the second-best results.

| Dataset   | Metric   |   LightGCN |    SGL |   SimGCL |   LightGCL |   InvPref |   InvCF |    CDR |   AdvDrop |   AdvInfo |   DR-GNN |   Ours | Impro.   |
|-----------|----------|------------|--------|----------|------------|-----------|---------|--------|-----------|-----------|----------|--------|----------|
| Food      | R@10     |     0.0234 | 0.0198 |   0.0233 |     0.0108 |    0.0029 |  0.0382 | 0.026  |    0.024  |    0.0227 |   0.0266 | 0.0281 | 5.63%    |
| Food      | N@10     |     0.0182 | 0.0159 |   0.0186 |     0.0101 |    0.0014 |  0.0237 | 0.0195 |    0.0251 |    0.0135 |   0.0205 | 0.0296 | 17.93%   |
| Food      | R@20     |     0.0404 | 0.0324 |   0.0414 |     0.0181 |    0.0294 |  0.0392 | 0.0412 |    0.0371 |    0.0268 |   0.0436 | 0.0464 | 6.42%    |
| Food      | N@20     |     0.0242 | 0.0201 |   0.0249 |     0.0121 |    0.0115 |  0.024  | 0.0254 |    0.0237 |    0.0159 |   0.0279 | 0.0306 | 9.68%    |
| KuaiRec   | R@10     |     0.0742 | 0.07   |   0.0763 |     0.063  |    0.0231 |  0.1023 | 0.057  |    0.1014 |    0.1044 |   0.0808 | 0.1116 | 6.90%    |
| KuaiRec   | N@10     |     0.5096 | 0.4923 |   0.518  |     0.4334 |    0.2151 |  0.2242 | 0.263  |    0.329  |    0.4302 |   0.5326 | 0.6474 | 21.55%   |
| KuaiRec   | R@20     |     0.112  | 0.11   |   0.1196 |     0.1134 |    0.0478 |  0.1034 | 0.086  |    0.1214 |    0.1254 |   0.1266 | 0.1631 | 28.83%   |
| KuaiRec   | N@20     |     0.4268 | 0.4181 |   0.4446 |     0.409  |    0.2056 |  0.2193 | 0.224  |    0.3289 |    0.4305 |   0.4556 | 0.5392 | 18.35%   |
| Yelp2018  | R@10     |     0.0014 | 0.0027 |   0.0049 |     0.0022 |    0.0049 |  0.0004 | 0.0011 |    0.0027 |    0.0047 |   0.0044 | 0.0067 | 36.73%   |
| Yelp2018  | N@10     |     0.0008 | 0.0017 |   0.0028 |     0.0015 |    0.003  |  0.0026 | 0.0006 |    0.0017 |    0.0024 |   0.0029 | 0.0039 | 30.00%   |
| Yelp2018  | R@20     |     0.0035 | 0.0051 |   0.0106 |     0.0054 |    0.0108 |  0.0013 | 0.0016 |    0.0049 |    0.0083 |   0.0076 | 0.012  | 11.65%   |
| Yelp2018  | N@20     |     0.0016 | 0.0026 |   0.0047 |     0.0026 |    0.0049 |  0.0008 | 0.0008 |    0.0024 |    0.0038 |   0.0041 | 0.0055 | 11.11%   |
| Douban    | R@10     |     0.0028 | 0.0022 |   0.0086 |     0.007  |    0.0052 |  0.003  | 0.0014 |    0.0051 |    0.0076 |   0.0028 | 0.0094 | 9.30%    |
| Douban    | N@10     |     0.0015 | 0.0013 |   0.0045 |     0.0038 |    0.0026 |  0.0012 | 0.0007 |    0.0021 |    0.0042 |   0.0011 | 0.005  | 11.11%   |
| Douban    | R@20     |     0.0049 | 0.0047 |   0.0167 |     0.0113 |    0.0093 |  0.0033 | 0.02   |    0.0046 |    0.0103 |   0.0038 | 0.0197 | 17.96%   |
| Douban    | N@20     |     0.0019 | 0.002  |   0.0073 |     0.005  |    0.0038 |  0.0013 | 0.0019 |    0.0021 |    0.0053 |   0.0015 | 0.0079 | 8.22%    |

Table 2: Outcomes from ablation studies on four datasets. The top-performing results are highlighted in bold, while those that are second-best are underlined.

module and the environment inference module. Additionally, we use t-SNE to visualize the item representations captured by the baseline model and CausalDiffRec, to compare the models' generalization capabilities on OOD data.

| Dataset   | Ablation      |   R@10 |   R@20 |   N@10 |   N@20 |
|-----------|---------------|--------|--------|--------|--------|
| Food      | LightGCN      | 0.0234 | 0.0404 | 0.0182 | 0.0242 |
| Food      | w/o Gen.      | 0.0165 | 0.0259 | 0.0114 | 0.0148 |
| Food      | w/o Env.      | 0.0084 | 0.0144 | 0.0077 | 0.0098 |
| Food      | CausalDiffRec | 0.0251 | 0.0409 | 0.0296 | 0.0306 |
| KuaiRec   | LightGCN      | 0.0808 | 0.1266 | 0.5326 | 0.4556 |
| KuaiRec   | w/o Gen.      | 0.0966 | 0.1571 | 0.0445 | 0.3078 |
| KuaiRec   | w/o Env.      | 0.0047 | 0.174  | 0.0697 | 0.0784 |
| KuaiRec   | CausalDiffRec | 0.1116 | 0.1631 | 0.0674 | 0.5392 |
| Yelp2018  | LightGCN      | 0.0014 | 0.0035 | 0.0008 | 0.0016 |
| Yelp2018  | w/o Gen.      | 0.0041 | 0.0054 | 0.0037 | 0.0042 |
| Yelp2018  | w/o Env.      | 0.0027 | 0.0058 | 0.0042 | 0.0043 |
| Yelp2018  | CausalDiffRec | 0.0067 | 0.012  | 0.0039 | 0.0055 |
| Douban    | LightGCN      | 0.0028 | 0.0049 | 0.0015 | 0.0019 |
| Douban    | w/o Gen.      | 0.0044 | 0.0079 | 0.003  | 0.0045 |
| Douban    | w/o Env.      | 0.0044 | 0.007  | 0.0023 | 0.0031 |
| Douban    | CausalDiffRec | 0.0094 | 0.0197 | 0.005  | 0.0079 |

the performance improvement to our use of data augmentation and the incorporation of auxiliary information in modeling user preferences.

In summary, the analysis of experimental results demonstrates that our proposed CausalDiffRec can handle different types of distribution shifts and achieve good generalization.

## 4.3 In-depth Analysis (RQ2)

In this section, we conduct ablation experiments to study the impact of each component of CausalDiffRec on recommendation performance. The main components include the environment generator

Ablation studies . Table 2 presents the results of the ablation study that compares LightGCN, CausalDiffRec, and its two variants: 'w/o Gen.' (without the environment generator) and 'w/o Env.' (without the environment inference). The results show that removing these modules causes a significant drop in all metrics across four datasets. For example, on Yelp2018, Recall, and NDCG decreased by 148.15% and 126.83%, respectively, demonstrating the effectiveness of CausalDiffRec based on invariant learning theory for enhancing recommendation performance on OOD datasets. Additionally, even without the modules, CausalDiffRec still outperforms LightGCN on popularity shift datasets (Yelp2018 and Douban) due to the effectiveness of data augmentation and environment inference. However, on the Food and KuaiRec datasets, removing either module results in worse performance than LightGCN, likely due to multiple biases in these datasets. Without one module, the model struggles to handle multiple data distributions, leading to a performance drop. Overall, the ablation experiments highlight the importance of all modules in CausalDiffRec for improving recommendation performance and generalizing on OOD data.

Visualization analysis . In Figure 6 and Figure 7, we used t-SNE to visualize the item representations learned by LightGCN, SimGCL, and CausalDiffRec on Douban and Yelp2018 datasets to better observe our model's ability to handle distribution shifts. Following previous work [28], we recorded the popularity of each item in the training set and designated the top 10% most popular items as 'popular items' and the bottom 10% as 'unpopular items'. It is obvious that the embeddings of popular and unpopular items learned by LightGCN still exhibit a gap in the representation space. In contrast, the embeddings learned by CausalDiffRec are more evenly distributed within the same space. This indicates that CausalDiffRec

Figure 5: Effects of the number of environments K.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-e6487d21-8333-4c38-bd36-d1b60b924099.jpg)

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-a255c284-74f9-4f62-b84f-ad8976a40435.jpg)

can mitigate the popularity shift caused by popular items. Additionally, we found that the embeddings of popular and unpopular items learned by SimGCL are more evenly distributed compared to LightGCN. This is because contrastive learning can learn a uniform representation distribution.

## 4.4 Hyperparameter Investigation (RQ3)

Effect of Diffusion Step T . We conducted experiments to investigate the impact of the number of diffusion steps on performance; in CausalDiffRec, we used the same number of steps in the forward and reverse phases. we compare the performance with 𝑇 changing from 10 to 500. We present the results in Figure 4, and we have the following findings:

- · Whenthe number of steps is chosen within the range {10, 50, 100}, CausalDiffRec achieves the best performance across all datasets. We find that appropriately increasing the number of steps significantly improves Recall@20 and NDCG@20. These performance enhancements are mainly attributed to the diffusion enriching the representation capabilities of users and items.
- · Nevertheless, as we continue to increase the number of steps, the model will face overfitting issues. For example, on the food and yelp2018 datasets, Recall@20 and NDCG@20 consistently decrease. Although there is an upward trend on KuaiRec, the optimal solution is not achieved. Additionally, it is evident that more steps also lead to longer training times. We should carefully adjust the number of steps to find the optimal balance between enhancing representation ability and avoiding overfitting.

Effect of the number of Environments . Figure 5 shows the impact of the number of environments on the model's performance. We can see that as the number of environments increases, the performance of CausalDiffRec improves across the three datasets. This indicates that more environments help enhance the model's generalization on OOD (Out-of-Distribution) data. However, as the number of environments further increases, performance declines, which we believe is due to the model overfitting to too many environments.

## 5 RELATED WORK

## 5.1 GNN-based Recommendation

Recent developments in graph-based recommender systems have leveraged graph neural networks to model user-item interactions as a bipartite graph, enhancing recommendation accuracy through complex interaction capture [9, 35, 43]. Notably, LightGCN focuses on neighborhood aggregation without additional transformations, while other approaches employ attention mechanisms to prioritize influential interactions [3, 6, 25, 29, 36, 37]. Further research explores non-Euclidean spaces like hyperbolic space to better represent user-item relationships [27, 56]. Knowledge graphs also enhance these systems by integrating rich semantic and relational data directly into the recommendation process [2, 34]. Despite these advancements, graph-based systems often struggle with outof-distribution data due to the IID assumption and are challenged by multiple distribution shifts [15, 19, 40, 46, 50]. Additionally, contrastive learning methods in these systems rely on a fixed paradigm that lacks robust theoretical support, limiting adaptability to varied data shifts. However, the aforementioned models are trained on datasets where the training and test data distributions are drawn from the same distribution, leading to generalization failure when facing OOD data.

## 5.2 Diffusion based Recoomendation

The integration of diffusion processes into recommender systems leverages diffusion mechanisms to model dynamic propagation of user preferences and item information through interaction networks, enhancing recommendation accuracy and timeliness [16, 21, 22, 24, 26, 33, 45]. These models capture evolving user behaviors and have shown potential in various recommendation contexts, from sequential recommendations to location-based services. For instance, DiffRec [33] applies diffusion directly for recommendations, while Diff-POI [26] models location preferences. Furthermore, approaches like DiffKG [16] and RecDiff [22] utilize diffusion for denoising entity representations in knowledge graphs and user data in social recommendations, respectively, enhancing the robustness and reliability of the systems. These studies underscore diffusion's suitability for advanced representation learning in recommender systems. However, these methods cannot solve the OOD problem.

## 5.3 Out-of-Distribution Recommendation

Researchers have focused on recommendation algorithms for outof-distribution (OOD) data. COR [31] infers latent environmental factors in OOD data. CausPref [11] learns invariant user preferences and causal structures using anti-preference negative sampling. CaseQ [47] employs backdoor adjustment and variational inference for sequential recommendations. InvPref [39] separates invariant and variant preferences by identifying heterogeneous environments. However, these methods don't directly apply to graph-based recommendation models and fail to address OOD in graph structures. AdaDrop [53] uses adversarial learning and graph neural networks

to enhance performance by decoupling user preferences. DRO [28] integrates Distributionally Robust Optimization into Graph Neural Networks to handle distribution shifts in graph-based recommender systems. Distinct from these GNN-based methods, this paper explores how to use the theory of invariant learning to design GNNbased methods with good generalization capabilities.

## 6 CONCLUSION

This paper introduces CausalDiffRec, an innovative GNN-based model designed for OOD recommendation. CausalDiffRec aims to learn environment-invariant graph representations to improve model generalization on OOD data. It utilizes the backdoor criterion from causal inference and variational inference to mitigate environmental confounders, alongside a diffusion-based sampling strategy. Rooted in invariant learning theory, we theoretically demonstrate that optimizing CausalDiffRec's objective function enhances its ability to identify invariant graph representations, boosting generalization on OOD data. Experiments on four real-world datasets show CausalDiffRec surpasses baseline models, with ablation studies confirming its effectiveness.

## ACKNOWLEDGMENTS

This work is partially supported by the National Natural Science Foundation of China under Grant (No. 62032013, 62102074), the Science and Technology projects in Liaoning Province (No. 2023JH3 / 10200005).

## REFERENCES

- [1] Xuheng Cai, Chao Huang, Lianghao Xia, and Xubin Ren. 2023. LightGCL: Simple yet effective graph contrastive learning for recommendation. arXiv preprint arXiv:2302.08191 (2023).
- [2] Yixin Cao, Xiang Wang, Xiangnan He, Zikun Hu, and Tat-Seng Chua. 2019. Unifying knowledge graph learning and recommendation: Towards a better understanding of user preferences. In WWW . 151-161.
- [3] Jianxin Chang, Chen Gao, Yu Zheng, Yiqun Hui, Yanan Niu, Yang Song, Depeng Jin, and Yong Li. 2021. Sequential recommendation with graph neural networks. In SIGIR . 378-387.
- [4] Yongqiang Chen, Yonggang Zhang, Yatao Bian, Han Yang, MA Kaili, Binghui Xie, Tongliang Liu, Bo Han, and James Cheng. 2022. Learning causally invariant representations for out-of-distribution generalization on graphs. NIPS 35 (2022), 22131-22148.
- [5] Elliot Creager, Jörn-Henrik Jacobsen, and Richard Zemel. 2021. Environment inference for invariant learning. In ML . PMLR, 2189-2200.
- [6] Hiroshi Fukui, Tsubasa Hirakawa, Takayoshi Yamashita, and Hironobu Fujiyoshi. 2019. Attention branch network: Learning of attention mechanism for visual explanation. In CVPR . 10705-10714.
- [7] Meng-Hao Guo, Tian-Xing Xu, Jiang-Jiang Liu, Zheng-Ning Liu, Peng-Tao Jiang, Tai-Jiang Mu, Song-Hai Zhang, Ralph R Martin, Ming-Ming Cheng, and Shi-Min Hu. 2022. Attention mechanisms in computer vision: A survey. Computational visual media 8, 3 (2022), 331-368.
- [8] Qingyu Guo, Fuzhen Zhuang, Chuan Qin, Hengshu Zhu, Xing Xie, Hui Xiong, and Qing He. 2020. A survey on knowledge graph-based recommender systems. TKDE 34, 8 (2020), 3549-3568.
- [9] Xiangnan He, Kuan Deng, Xiang Wang, Yan Li, Yongdong Zhang, and Meng Wang. 2020. Lightgcn: Simplifying and powering graph convolution network for recommendation. In Proceedings of the 43rd International ACM SIGIR conference on research and development in Information Retrieval . 639-648.
- [10] Xiangnan He, Lizi Liao, Hanwang Zhang, Liqiang Nie, Xia Hu, and Tat-Seng Chua. 2017. Neural collaborative filtering. In Proceedings of the 26th international conference on world wide web . 173-182.
- [11] Yue He, Zimu Wang, Peng Cui, Hao Zou, Yafeng Zhang, Qiang Cui, and Yong Jiang. 2022. Causpref: Causal preference learning for out-of-distribution recommendation. In WWW . 410-421.
- [12] Jonathan Ho, Ajay Jain, and Pieter Abbeel. 2020. Denoising diffusion probabilistic models. (2020), 6840-6851.
- [13] Yen-Chang Hsu, Yilin Shen, Hongxia Jin, and Zsolt Kira. 2020. Generalized odin: Detecting out-of-distribution image without learning from out-of-distribution data. In CVPR . 10951-10960.
- [14] Shaoxiong Ji, Shirui Pan, Erik Cambria, Pekka Marttinen, and S Yu Philip. 2021. A survey on knowledge graphs: Representation, acquisition, and applications. TNNLS 33, 2 (2021), 494-514.
- [15] Yangqin Jiang, Chao Huang, and Lianghao Huang. 2023. Adaptive graph contrastive learning for recommendation. In KDD . 4252-4261.
- [16] Yangqin Jiang, Yuhao Yang, Lianghao Xia, and Chao Huang. 2024. Diffkg: Knowledge graph diffusion model for recommendation. In WSDM . 313-321.
- [17] Mengyuan Jing, Yanmin Zhu, Tianzi Zang, and Ke Wang. 2023. Contrastive self-supervised learning in recommender systems: A survey. TOIS 42, 2 (2023), 1-39.
- [18] Seul Lee, Jaehyeong Jo, and Sung Ju Hwang. 2023. Exploring chemical space with score-based out-of-distribution generation. In ICML . PMLR, 18872-18892.
- [19] Chaoliu Li, Lianghao Xia, Xubin Ren, Yaowen Ye, Yong Xu, and Chao Huang. 2023. Graph transformer for recommendation. In SIGIR . 1680-1689.
- [20] Haoyang Li, Ziwei Zhang, Xin Wang, and Wenwu Zhu. 2022. Learning invariant graph representations for out-of-distribution generalization. NIPS 35 (2022), 11828-11841.
- [21] Zihao Li, Aixin Sun, and Chenliang Li. 2023. Diffurec: A diffusion model for sequential recommendation. TOIS 42, 3 (2023), 1-28.
- [22] Zongwei Li, Lianghao Xia, and Chao Huang. 2024. RecDiff: Diffusion Model for Social Recommendation. arXiv preprint arXiv:2406.01629 (2024).
- [23] Jiashuo Liu, Zheyan Shen, Yue He, Xingxuan Zhang, Renzhe Xu, Han Yu, and Peng Cui. 2021. Towards out-of-distribution generalization: A survey. arXiv preprint arXiv:2108.13624 (2021).
- [24] Haokai Ma, Ruobing Xie, Lei Meng, Xin Chen, Xu Zhang, Leyu Lin, and Zhanhui Kang. 2024. Plug-in diffusion model for sequential recommendation. In AAAI , Vol. 38. 8886-8894.
- [25] Zhaoyang Niu, Guoqiang Zhong, and Hui Yu. 2021. A review on the attention mechanism of deep learning. Neurocomputing 452 (2021), 48-62.
- [26] Yifang Qin, Hongjun Wu, Wei Ju, Xiao Luo, and Ming Zhang. 2023. A diffusion model for poi recommendation. TOIS 42, 2 (2023), 1-27.
- [27] Jianing Sun, Zhaoyue Cheng, Saba Zuberi, Felipe Pérez, and Maksims Volkovs. 2021. Hgcf: Hyperbolic graph convolution networks for collaborative filtering. In WWW . 593-601.
- [28] Bohao Wang, Jiawei Chen, Changdong Li, Sheng Zhou, Qihao Shi, Yang Gao, Yan Feng, Chun Chen, and Can Wang. 2024. Distributionally Robust Graph-based Recommendation System. In WWW . 3777-3788.
- [29] Jianling Wang, Kaize Ding, Ziwei Zhu, and James Caverlee. 2021. Session-based recommendation with hypergraph attention networks. In SDM . SIAM, 82-90.
- [30] Shoujin Wang, Liang Hu, Yan Wang, Xiangnan He, Quan Z Sheng, Mehmet A Orgun, Longbing Cao, Francesco Ricci, and Philip S Yu. 2021. Graph learning based recommender systems: A review. arXiv preprint arXiv:2105.06339 (2021).
- [31] Wenjie Wang, Xinyu Lin, Fuli Feng, Xiangnan He, Min Lin, and Tat-Seng Chua. 2022. Causal representation learning for out-of-distribution recommendation. In WWW . 3562-3571.
- [32] Wenjie Wang, Xinyu Lin, Liuhui Wang, Fuli Feng, Yunshan Ma, and Tat-Seng Chua. 2023. Causal disentangled recommendation against user preference shifts. TOIS 42, 1 (2023), 1-27.
- [33] Wenjie Wang, Yiyan Xu, Fuli Feng, Xinyu Lin, Xiangnan He, and Tat-Seng Chua. 2023. Diffusion recommender model. In SIGIR . 832-841.
- [34] Xiang Wang, Xiangnan He, Yixin Cao, Meng Liu, and Tat-Seng Chua. 2019. Kgat: Knowledge graph attention network for recommendation. In KDD . 950-958.
- [35] Xiang Wang, Xiangnan He, Meng Wang, Fuli Feng, and Tat-Seng Chua. 2019. Neural graph collaborative filtering. In SIGIR . 165-174.
- [36] Xiang Wang, Hongye Jin, An Zhang, Xiangnan He, Tong Xu, and Tat-Seng Chua. 2020. Disentangled graph collaborative filtering. In SIGIR . 1001-1010.
- [37] Yifan Wang, Suyao Tang, Yuntong Lei, Weiping Song, Sheng Wang, and Ming Zhang. 2020. Disenhan: Disentangled heterogeneous graph attention network for recommendation. In CIKM . 1605-1614.
- [38] Yunke Wang, Xiyu Wang, Anh-Dung Dinh, Bo Du, and Charles Xu. 2023. Learning to schedule in diffusion probabilistic models. In KDD . 2478-2488.
- [39] Zimu Wang, Yue He, Jiashuo Liu, Wenchao Zou, Philip S Yu, and Peng Cui. 2022. Invariant preference learning for general debiasing in recommendation. In KDD . 1969-1978.
- [40] Jiancan Wu, Xiang Wang, Fuli Feng, Xiangnan He, Liang Chen, Jianxun Lian, and Xing Xie. 2021. Self-supervised graph learning for recommendation. In SIGIR . 726-735.
- [41] Qitian Wu, Fan Nie, Chenxiao Yang, Tianyi Bao, and Junchi Yan. [n. d.]. Graph out-of-distribution generalization via causal intervention. In WWW . 850-860.
- [42] Qitian Wu, Hengrui Zhang, Junchi Yan, and David Wipf. 2022. Handling distribution shifts on graphs: An invariance perspective. arXiv preprint arXiv:2202.02466 (2022).
- [43] Shiwen Wu, Fei Sun, Wentao Zhang, Xu Xie, and Bin Cui. 2022. Graph neural networks in recommender systems: a survey. Comput. Surveys 55, 5 (2022), 1-37.

- [44] Zonghan Wu, Shirui Pan, Fengwen Chen, Guodong Long, Chengqi Zhang, and S Yu Philip. 2020. A comprehensive survey on graph neural networks. TNNLS 32, 1 (2020), 4-24.
- [45] Zihao Wu, Xin Wang, Hong Chen, Kaidong Li, Yi Han, Lifeng Sun, and Wenwu Zhu. 2023. Diff4rec: Sequential recommendation with curriculum-scheduled diffusion augmentation. In CIKM . 9329-9335.
- [46] Lianghao Xia, Chao Huang, Chunzhen Huang, Kangyi Lin, Tao Yu, and Ben Kao. 2023. Automated self-supervised learning for recommendation. In WWW . 992-1002.
- [47] Chenxiao Yang, Qitian Wu, Qingsong Wen, Zhiqiang Zhou, Liang Sun, and Junchi Yan. 2022. Towards out-of-distribution sequential event prediction: A causal treatment. NIPS 35 (2022), 22656-22670.
- [48] Jingkang Yang, Kaiyang Zhou, Yixuan Li, and Ziwei Liu. 2024. Generalized out-of-distribution detection: A survey. IJCV (2024), 1-28.
- [49] Nianzu Yang, Kaipeng Zeng, Qitian Wu, Xiaosong Jia, and Junchi Yan. 2022. Learning substructure invariance for out-of-distribution molecular representations. NIPS 35 (2022), 12964-12978.
- [50] Junliang Yu, Hongzhi Yin, Xin Xia, Tong Chen, Lizhen Cui, and Quoc Viet Hung Nguyen. 2022. Are graph augmentations necessary? simple graph contrastive learning for recommendation. In SIGIR . 1294-1303.
- [51] Junliang Yu, Hongzhi Yin, Xin Xia, Tong Chen, Jundong Li, and Zi Huang. 2023. Self-supervised learning for recommender systems: A survey. TKDE 36, 1 (2023), 335-355.
- [52] Haonan Yuan, Qingyun Sun, Xingcheng Fu, Ziwei Zhang, Cheng Ji, Hao Peng, and Jianxin Li. 2024. Environment-Aware Dynamic Graph Learning for Out-ofDistribution Generalization. NIPS 36 (2024).
- [53] An Zhang, Wenchang Ma, Pengbo Wei, Leheng Sheng, and Xiang Wang. 2024. General Debiasing for Graph-based Collaborative Filtering via Adversarial Graph Dropout. In WWW . 3864-3875.
- [54] An Zhang, Leheng Sheng, Zhibo Cai, Xiang Wang, and Tat-Seng Chua. 2024. Empowering Collaborative Filtering with Principled Adversarial Contrastive Loss. (2024).
- [55] An Zhang, Jingnan Zheng, Xiang Wang, Yancheng Yuan, and Tat-Seng Chua. 2023. Invariant collaborative filtering to popularity distribution shift. In WWW . 1240-1251.
- [56] Yiding Zhang, Chaozhuo Li, Xing Xie, Xiao Wang, Chuan Shi, Yuming Liu, Hao Sun, Liangjie Zhang, Weiwei Deng, and Qi Zhang. 2022. Geometric disentangled collaborative filtering. In SIGIR . 80-90.
- [57] Zeyang Zhang, Xin Wang, Ziwei Zhang, Zhou Qin, Weigao Wen, Hui Xue, Haoyang Li, and Wenwu Zhu. 2024. Spectral invariant learning for dynamic graphs under distribution shifts. NIPS 36 (2024).
- [58] Xin Zheng, Yi Wang, Yixin Liu, Ming Li, Miao Zhang, Di Jin, Philip S Yu, and Shirui Pan. 2022. Graph neural networks for graphs with heterophily: A survey. arXiv preprint arXiv:2202.07082 (2022).
- [59] Jie Zhou, Ganqu Cui, Shengding Hu, Zhengyan Zhang, Cheng Yang, Zhiyuan Liu, Lifeng Wang, Changcheng Li, and Maosong Sun. 2020. Graph neural networks: A review of methods and applications. AI open 1 (2020), 57-81.

## A THEORETICAL PROOF

CausalDiffRec aims to learn the optimal generator 𝐹 ∗ (·) as stated in the assumption in section 2.3, thereby obtaining invariant graph representations to achieve OOD generalization in recommendation performance under data distribution shifts. Before starting the theoretical derivation, let's do some preliminary work. For the convenience of theoretical proof, we rewrite Eq. (22) as:

$$\arg \min _ { \theta } \left ( \mathcal { L } _ { \text{task} } + \mathcal { L } _ { \text{infer} } \right ),$$

where L 𝑡𝑎𝑠𝑘 = L 𝑟𝑒𝑐 +L generator +L VGAE +L Invsample and L infer = L envInf , and for the derivation convenience, we temporarily ignore the penalty coefficient. The L task and L infer can be further abstracted as:

$$\text{frac} \text{src} \colon & \text{as} \colon \\ \text{$\mathcal{L}$} _ { \text{task} } = \arg \min _ { \theta } \mathbb { E } _ { e \sim D _ { t r } ( E ), ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( Y, G | E = e ) } \\ [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) ] \\ \mathcal { L } _ { \text{infer} } = \min _ { q ( Y | z _ { c a u s a l } ) } \text{Var} \{ \mathbb { E } _ { e \sim D _ { t r } ( E ), ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( Y, G | E = e ) } \\ [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) | d o ( \mathcal { G } _ { u } ) ] \}. \\ \text{...} \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \colon \end{array}$$

We follow the proof technique from [52] and show the optimality of the Eq. (23) with the following two propositions that can achieve OOD recommendation.

Proposition A.1. Minimizing Eq. (23) promotes the model's adherence to the Invariance Property and the Sufficient Condition outlined in Assumption (in Sec. 2.3).

Proposition A.2. Optimizing Eq. (23) corresponds to minimizing the upper bound of the OOD generalization error described in Eq. (6).

Proposition A.1 and Proposition A.2, respectively, avoid strong hypotheses and ensure that the OOD generalization error bound of the learned model is within the expected range. In fact, this can also be explained from the perspective of the SCM model in Figure 2. Optimizing Eq. (6) eliminates the negative impact of unstable correlations learned by the model, which are caused by latent environments, on modeling user preferences. At the same time, it enhances the model's ability to learn invariant causal features across different latent environments. Proofs for Proposition A.1 and Proposition A.2 are shown as follows:

Before starting the proof, we directly follow previous work [4, 18, 42, 49, 52] to propose the following lemma, using information theory to interpret the invariance property and sufficient condition in Assumption and to assist in the proof of Proposition A.1. Using the Mutual Information I ( ; ) , the invariance property and sufficient condition in Assumption can be equivalently expressed as follow lemma:

Lemma A.3. (1) Invariance: ∀ 𝑒 ∈ 𝐷 𝐸 , 𝑃 ( ) 𝜃 ( 𝑌 |P ∗ 𝐼𝑛𝑣 , 𝐸 = 𝑒, 𝐼 ) = 𝑃 𝑌 ( |P ∗ 𝐼𝑛𝑣 , 𝐼 ) ⇔ ( I 𝑌 𝐸 ; |P ∗ 𝐼𝑛𝑣 , 𝐼 ) = 0 where P ∗ 𝐼𝑛𝑣 = 𝐹 ∗ ( 𝐺 ) . (2) Sufficiency: I ( 𝑌 ; P ∗ 𝐼𝑛𝑣 , 𝐼 ) is maxmized.

For the invariance property, it is easy to get the following equation:

$$\text{and} \\ \text{vey.} \quad \begin{array} { c } \mathbb { I } ( Y ; E | \mathcal { P } _ { \ln v } ^ { * }, I ) \\ = \mathbb { E } _ { \mathcal { P } _ { \ln v } ^ { * }, I } \left [ \mathbb { D } _ { \mathrm K L } \left ( P ( Y, E | \mathcal { P } _ { \ln v } ^ { * }, I ) | | P ( Y | \mathcal { P } _ { \ln v } ^ { * }, I ) P ( E | \mathcal { P } _ { \ln v } ^ { * }, I ) \right ) \right ] \end{array} \quad ( 2 5 )$$

For the sufficient condition, we employ the method of contradiction and prove it through the following two steps:

First , we prove that for 𝑌 , P ∗ 𝐼𝑛𝑣 , and 𝐼 satisfying P ∗ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , they also satisfy that I ( 𝑌 ; P ∗ 𝐼𝑛𝑣 , 𝐼 ) is maximized. We leverage the method of contradiction to prove this. Assume P ∗ 𝐼𝑛𝑣 ≠ arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , and there exists P ′ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , where P ′ 𝐼𝑛𝑣 ≠ P ∗ 𝐼𝑛𝑣 . We can always find a mapping function 𝑀 such that P ′ 𝐼𝑛𝑣 = 𝑀 (P ∗ 𝐼𝑛𝑣 , 𝑅 ) , where 𝑅 is a random variable. Then we have:

$$\mathbb { I } ( Y ; \mathcal { P } _ { I n v } ^ { \prime }, I ) & = \mathbb { I } ( Y ; \mathcal { P } _ { I n v } ^ { * }, R, I ) \\ & = \mathbb { I } ( Y ; \mathcal { P } _ { I n v } ^ { * }, I ) + \mathbb { I } ( Y ; R | \mathcal { P } _ { I n v } ^ { * }, I ).$$

Since 𝑅 is a random variable and does not contain any information about 𝑌 , we have I ( 𝑌 𝑅 ; |P ∗ 𝐼𝑛𝑣 , 𝐼 ) = 0. Therefore:

$$\mathbb { I } ( Y ; \mathcal { P } ^ { \prime } _ { I n v }, I ) = \mathbb { I } ( Y ; \mathcal { P } ^ { * } _ { I n v }, I ).$$

This leads to a contradiction.

Next , we prove that for 𝑌 , P ∗ 𝐼𝑛𝑣 , and 𝐼 satisfying P ∗ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , they also satisfy that I ( 𝑌 ; P ∗ 𝐼𝑛𝑣 , 𝐼 ) is maximized. Assume P ∗ 𝐼𝑛𝑣 ≠ arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , and there exists P ′ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) , where P ′ 𝐼𝑛𝑣 ≠ P ∗ 𝐼𝑛𝑣 . We have the following inequality:

$$\mathbb { I } ( Y ; \mathcal { P } _ { I n v } ^ { * } I ) \leq \mathbb { I } ( Y ; \mathcal { P } _ { I n v } ^ { \prime } I ).$$

From this, we can deduce that:

$$\mathcal { P } ^ { \prime } _ { I n v } = \arg \max _ { \mathcal { P } _ { I n v } } \mathbb { I } ( Y ; \mathcal { P } _ { I n v }, I ), \quad \quad ( 2 9 ) \quad \ \.$$

where contradicts P ∗ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) . Since the assumption leads to a contradiction, and the assumption does not hold. Therefore, P ∗ 𝐼𝑛𝑣 = arg max P 𝐼𝑛𝑣 I ( 𝑌 ; P 𝐼𝑛𝑣 , 𝐼 ) holds. This proves that I ( 𝑌 ; P ∗ 𝐼𝑛𝑣 , 𝐼 ) is maximized. The lemma A.3 is complicated proven.

Proof of Proposition A.1. First , optimizing the first term L task in Eq. (23) enables the model to satisfy the sufficient condition. Analyzing the SCM in Figure 2(c), we have the fact that max 𝑞 𝑧 𝐺,𝐼 ( | ) I ( 𝑌,𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) is equivalent to min 𝑞 𝑧 𝐺,𝐼 ( | ) I ( 𝑌,𝐺 𝑍 | 𝑐𝑎𝑢𝑠𝑎𝑙 ) , as we use 𝑑𝑜 𝐺 ( ) to eliminate the unstable correlations between Y and G caused by the latent environment. We have:

$$\mathbb { I } ( Y, G | z _ { c a u s a l } ) & = D _ { K L } ( p ( Y | G, E ) \| p ( Y | z _ { c a u s a l }, E ) ) \\ & = D _ { K L } ( p ( Y | G, E ) \| p ( Y | z _ { c a u s a l } ) ) \\ & - D _ { K L } ( p ( Y | z _ { c a u s a l }, E ) \| q ( Y | z _ { c a u s a l } ) ) \\ & \leq D _ { K L } ( p ( Y | G, E ) \| p ( Y | z _ { c a u s a l } ) ). \quad \quad \quad ( \text{$30$} ) \quad \text{$the r$} \quad \text{$r$} \quad \text{$1$}$$

Based on the above derivation, we have:

$$\mathbb { I } ( Y, G | z _ { c a u s a l } ) & \leq \quad \begin{array} { c } ( 6 ). \\ \text{$(1)} ( Y, G | z _ { c a u s a l } ) \end{array} \quad ( 3 1 ) \quad \text{the} \\ \min _ { q ( Y | z _ { c a u s a l } ) } \ D _ { K L } ( p ( Y | G, E ) \| p ( Y | z _ { c a u s a l } ) ). \quad \begin{array} { c } ( 3 1 ) \quad \text{the} \\ \text{be} \, \mathbb { q } \end{array}$$

Besides, we have:

$$\text{Besides, we have} \colon \\ \text{$D_{KL}(p(Y|G,E)||p(Y|z_{causal}))$} \\ = \mathbb { E } _ { e \in D _ { t r } ( E ) \mathbb { E } _ { ( G, Y ) \sim p(G, Y | e ) } } \\ \mathbb { E } _ { z _ { c a u s a l } \sim q(z _ { c a u s a l } | G, I ) } \left [ \log \frac { q ( Y | G, e ) } { p ( Y | z _ { c a u s a l } ) } \right ] \text{ for the $p$} \\ \leq \mathbb { E } _ { e \in D _ { t r } ( E ) \mathbb { E } _ { ( G, Y ) \sim p(G, Y | e ) } } \text{ } \\ \left [ \log \frac { p ( Y | G, e ) } { \mathbb { E } _ { z _ { c a u s a l } \sim q(z _ { c a u s a l } | G, I ) q ( Y | z _ { c a u s a l } ) } \right ] ( Jensen Inequality). \quad \text{$L$} \\ \text{ by} \colon \\ \text{Finally, we reach} \colon$$

Finally, we reach:

$$& \min _ { q ( Y | z _ { c a u s a l } ) } D _ { K L } ( p ( Y | G, E ) \| p ( Y | z _ { c a u s a l } ) ) \quad \text{ with } \\ & \Leftrightarrow \arg \min _ { \theta } \mathbb { E } _ { e \sim D _ { t r } ( E ), ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( Y, G | E = e ) } [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) ]. \\ & \text{--} \quad. \quad. \quad. \quad. \quad.$$

Thus, we have demonstrated that minimizing the expectation term ( L 𝑡𝑎𝑠𝑘 ) in Eq. (23) is equivalent to minimizing the upper bound of I ( 𝑌 𝐺 ; | 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) . This results in maximizing I ( 𝑌 ; P ∗ 𝐼𝑛𝑣 , 𝐼 ) , thereby helping to ensure that the model satisfies the Sufficient Condition.

Next , we prove that optimizing the first term L 𝑡𝑎𝑠𝑘 in Eq. (23) enables the model to satisfy the Invariance Property. Similar to Eq. (30), we have:

$$( 3 0 ), \, \text{we have} \colon \\ \mathbb { I } ( Y ; E = e \, | \, z _ { \text{causal} } ) \\ \, = \, D _ { K L } ( p ( Y \, | \, z _ { \text{causal} }, e ) \, \| \, p ( Y \, | \, z _ { \text{causal} } ) ) \\ \, = \, D _ { K L } ( p ( Y \, | \, z _ { \text{causal} }, E ) \, \| \, \mathbb { E } _ { e \in D ( E ) } [ p ( Y \, | \, z _ { \text{causal} }, e ) ] ) \\ \, = \, D _ { K L } ( q ( Y \, | \, z _ { \text{causal} } ) \, \| \, \mathbb { E } _ { e \in D ( E ) } [ q ( Y \, | \, z _ { \text{causal} } ] ) ) \\ \, - \, D _ { K L } ( q ( Y \, | \, z _ { \text{causal} } ) \, \| \, p ( Y \, | \, z _ { \text{causal} }, e ) ) \quad \text{The} \, 1 \\ \quad \text{Prop} \, 1 \\ \, - \, D _ { K L } ( \mathbb { E } _ { e \in D ( E ) } [ p ( Y \, | \, z _ { \text{causal} }, e ) ] \, \| \, \mathbb { E } _ { e \in D ( E ) } [ q ( Y \, | \, z _ { \text{causal} } ] ) \\ \, \leq \, D _ { K L } ( q ( Y \, | \, z _ { \text{causal} } ) \, \| \, \mathbb { E } _ { e \in D ( E ) } [ q ( Y \, | \, z _ { \text{causal} } ] ).$$

Besides, the last term in Eq. (34) can be further expressed as:

$$& \cdot \cdot \cdot \cdot \cdot \cdot \\ & D _ { K L } ( q ( Y \, | \, z _ { c a u s a l } ) \, \| \, \mathbb { E } _ { e \in D ( E ) } [ q ( Y \, | \, z _ { c a u s a l } ) ] ) \\ & = \mathbb { E } _ { e \in D _ { t r } ( E ) } \mathbb { E } _ { ( G, Y ) \sim p ( G, Y | e ) } \mathbb { E } _ { z _ { c a u s a l } \sim q ( z _ { c a u s a l } | G, I ) } \\ \text{old}. & \quad \left [ \log \frac { p ( Y | G, e ) } { \mathbb { E } _ { e \in D ( E ) } q ( Y | z _ { c a u s a l } ) } \right ] ( Jensen Inequality ) \\ \text{hat} \\ \text{en}. & \quad \leq \mathbb { E } _ { e \in D ( E ) } [ | l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) - \mathbb { E } _ { e \in D ( E ) } [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) ] | ] \\ \text{task} \quad. & \quad. \quad. \quad. \quad. \quad. \quad. \quad. \quad. \quad. \quad. \quad. \quad.$$

where the last term in Eq. (35) is the upper bound for the 𝐷 𝐾𝐿 ( 𝑞 𝑌 ( | 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) ∥ E 𝑒 ∈ 𝐷 𝐸 ( ) [ 𝑞 𝑌 ( | 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 )]) . Finally, we have:

$$\stackrel { \cdot } { \text{ise} } & \min _ { q ( Y | z _ { c a u s a l } ) } D _ { K L } ( q ( Y \, | \, z _ { c a u s a l } ) \, \| \, \mathbb { E } _ { e \in D ( E ) } [ q ( Y \, | \, z _ { c a u s a l } ) ] ) \\ & \Leftrightarrow \min _ { q ( Y | z _ { c a u s a l } ) } \text{Var} \{ \mathbb { E } _ { e \sim D _ { t r } ( E ), ( \mathcal { G } _ { u }, y _ { u } ) \sim P ( Y, G | E = e ) } \\ & [ l ( f _ { \theta } ( \mathcal { G } _ { u } ; \theta ), y _ { u } ) | d o ( \mathcal { G } _ { u } ) ] \}.$$

(36)

Hence, minimizing the variance term ( L 𝑟𝑖𝑠𝑘 ) in Eq. (23) effectively reduces the upper bound of I ( 𝑌 𝐸 ; = 𝑒 | 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) . Thereby ensuring the model adheres to the Invariance Property.

Proof of Proposition A.2. Optimizing Eq. (23) is tantamount to reducing the upper bound of the OOD generalization error in Eq. (6). Let 𝑞 𝑌 ( | 𝐺 ) represent the inferred variational distribution of the true distribution 𝑝 𝑌 ( | 𝐺, 𝐸 ) . The OOD generalization error can be quantified by the KL divergence between these two distributions:

𝐷

𝐾𝐿

(

𝑝 𝑌 𝐺, 𝐸

(

|

)∥

𝑞 𝑌 𝐺

(

|

))

$$= \Xi _ { e \in D _ { t r } ( E ) } \Xi _ { ( Y, G ) \sim p ( Y, G | E ) } \log \frac { p ( Y | G, E = e ) } { q ( Y | G ) }.$$

Following previous work, we use information theory to assist in the proof of Proposition A.2. We propose the lemma A.4 to rewrite the OOD generalization, which is shown as follows:

Lemma A.4. The out-of-distribution generalization error is limited by:

$$\L ^ { \prime } _ { K L } ( p ( Y | G, E ) \| q ( Y | G ) ) \leq D _ { K L } [ p ( Y | G, E ) \| q ( Y | z _ { c a u s a l } ) ], \quad ( 3 8 )$$

where 𝑞 𝑌 𝑧 ( | 𝑐𝑎𝑢𝑠𝑎𝑙 ) is the inferred variational environment distribution. The proof of Lemma A.4 is shown as:

$$\dots \dots \tau \vdots \tau _ { \ } c a u s u a \varphi \sim \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \ dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \\ \text{tribution. The proof of Lemma A.4 is shown as: } \\ & D _ { K L } ( p ( Y | G, E = e ) \| q ( Y | z _ { \ } c a u s u a | ) ) \\ & = \tilde { E } _ { e \in D ( E ) } \tilde { E } _ { ( Y, G ) \sim p ( G, Y | E = e ) } \left [ \log \frac { p ( Y | G, E = e ) } { \tilde { E } _ { z _ { \ } c a u s a l \sim q ( z _ { \ } c a u s a l | G, I ) } q ( Y | z _ { \ } c a u s a l ) } \right ] \\ & \leq \tilde { E } _ { e \in D ( E ) } \tilde { E } _ { ( Y, G ) \sim p ( G, Y | E = e ) } \\ & \tilde { E } _ { z _ { \ } c a u s a l \sim q ( z _ { \ } c a u s a l | G, I ) } \log \frac { p ( Y | G, e ) } { q ( Y | z _ { \ } c a u s a l ) } \\ & = D _ { K L } [ p ( Y | G, E ) \| q ( Y | z _ { \ } c a u s a l ) ], \\ \\ \text{The Lemma A.4 has been fully proven. Based on Lemma A.3 and} \\ - \quad \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \cdots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots \dots.$$

The Lemma A.4 has been fully proven. Based on Lemma A.3 and Proposition A.1, the Eq. (23) can be adapted as:

$$\min _ { q ( z _ { c a u s a l } | G, I ), q ( Y, z _ { c a u s a l } ) } & & ( 4 0 ) \\ D _ { K L } ( p ( Y | G, E = e ) \| q ( Y | z _ { c a u s a l } ) ) + \mathbb { I } ( Y, E = e | z _ { c a u s a l } )$$

Table 3: Detailed statistics for each dataset.

| Dataset   | #Users   | #Items   | #Interactions   | Density        |
|-----------|----------|----------|-----------------|----------------|
| Food      | 7,809    | 6,309    | 216,407         | 4 . 4 × 10 - 3 |
| KuaiRec   | 7,175    | 10,611   | 1,153,797       | 1 . 5 × 10 - 3 |
| Yelp2018  | 8,090    | 13,878   | 398,216         | 3 . 5 × 10 - 3 |
| Douban    | 8,735    | 13,143   | 354,933         | 3 . 1 × 10 - 3 |

Hence, according to Lemma A.4, we confirm that minimizing Eq. (23) is equivalent to minimizing the upper bound of the OOD generalization error in Eq. (6), meaning that:

- argmin 𝜃 (L 𝑡𝑎𝑠𝑘 + L 𝑖𝑛𝑓 𝑒𝑟 ) ⇔ min 𝑞 𝑧 ( 𝑐𝑎𝑢𝑠𝑎𝑙 | 𝐺,𝐼 ) ,𝑞 ( 𝑌,𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) 𝐷 𝐾𝐿 ( 𝑝 𝑌 𝐺, 𝐸 ( | = 𝑒 )∥ 𝑞 𝑌 𝑧 ( | 𝑐𝑎𝑢𝑠𝑎𝑙 )) + I ( 𝑌, 𝐸 = 𝑒 𝑧 | 𝑐𝑎𝑢𝑠𝑎𝑙 ) ( I ( 𝑌, 𝐸 = 𝑒 𝑧 | 𝑐𝑎𝑢𝑠𝑎𝑙 ) 𝑖𝑠 𝑛𝑜𝑛 -𝑛𝑒𝑔𝑎𝑡𝑖𝑣𝑒 ) ≥ min 𝑞 𝑧 ( 𝑐𝑎𝑢𝑠𝑎𝑙 | 𝐺,𝐼 ) ,𝑞 ( 𝑌,𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 ) 𝐷 𝐾𝐿 ( 𝑝 𝑌 𝐺, 𝐸 ( | = 𝑒 )∥ 𝑞 𝑌 𝑧 ( | 𝑐𝑎𝑢𝑠𝑎𝑙 )) ≥ 𝐷 𝐾𝐿 ( 𝑝 𝑌 𝐺, 𝐸 ( | )∥ 𝑞 𝑌 𝐺 ( | )) .

(41)

The Proposition A.2 is completely proven.

## B DERIVATION

## B.1 Derivation for Equation 7

𝑃 𝜃 ( 𝑌 𝑑𝑜 𝐺 | ( ))

- = ∑︁ 𝑒 𝑃 𝜃 ( 𝑌 𝑑𝑜 𝐺 , 𝐸 | ( ) = 𝑒, 𝐼 ) 𝑃 𝜃 ( 𝐸 = 𝑒 𝑑𝑜 | ( 𝐺 )) 𝑃 𝜃 ( 𝐼 )
- = ∑︁ 𝑒 𝑃 𝜃 ( 𝑌 𝐺, 𝐸 | = 𝑒, 𝐼 ) 𝑃 𝜃 ( 𝐸 = 𝑒 𝑑𝑜 | ( 𝐺 )) 𝑃 𝜃 ( 𝐼 )
- = ∑︁ 𝑒 𝑃 𝜃 ( 𝑌 𝐺, 𝐸 | = 𝑒, 𝐼 ) 𝑃 𝜃 ( 𝐸 = 𝑒 ) 𝑃 𝜃 ( 𝐼 ) (42)
- = ∑︁ 𝑒 𝑃 𝜃 ( 𝑌 𝐺, 𝐸 | = 𝑒, 𝐼 ) 𝑃 𝜃 ( 𝐸 = 𝑒, 𝐼 )
- = E 𝑒 ∼ 𝐷 𝑡𝑟 ( 𝐸 ) [ 𝑃 𝜃 ( 𝑌 𝐺, 𝐸, 𝐼 | )] ,

## B.2 Derivation for Equation 8

Taking the logarithm on both sides of Eq. (8) and according to Jensen's Inequality, we have:

$$\log _ { 0 }$$

$$\text{Taking the logarithm on both sides of Eq. (8) and according to } \text{$p$} \\ \text{Jensen's Inequality, we have:} \\ \log P _ { \theta } ( Y | d o ( G ) ) & \quad \text{$\bullet$ Te} \\ = \log \mathbb { E } _ { e \sim D _ { t r } ( E ) } [ P _ { \theta } ( Y | G, E, I ) ] & \text{$\text{or}$} \\ = \log \sum _ { e } P _ { \theta } ( Y | G, E = e, I ) P _ { \theta } ( E = e, I ) \frac { Q _ { \phi } ( E = e | G, I ) } { Q _ { \phi } ( E = e | G, I ) } & \text{$\text{via}$} \\ \geq \sum _ { e } Q _ { \phi } ( E = e | G, I ) & \quad \text{$\bullet$ E$} \\ \log P _ { \theta } ( Y | G, E = e, I ) P _ { \theta } ( E = e, I ) \frac { 1 } { Q _ { \phi } ( E = e | G, I ) } & \text{$\text{(43)}$} \\ = \sum _ { e } [ Q _ { \phi } ( E = e | G, I ) \log P _ { \theta } ( Y | G, E = e, I ) - \\ \log \frac { Q _ { \phi } ( E = e | G, I ) P _ { \theta } ( E = e, I ) } { Q _ { \phi } ( E = e | G, I ) } ] & \text{$\bullet$ cond} \\ = \mathbb { E } _ { Q _ { \phi } ( E = e | G, I ) } [ \log P _ { \theta } ( Y | G, E = e, I ) ] & \text{$\text{def}$} \\ - D _ { K L } ( Q _ { \phi } ( E = e | G, I ) \, \| \, P _ { \theta } ( E = e ) ).$$

- -𝐷 𝐾𝐿 ( 𝑄 𝜙 ( 𝐸 = 𝑒 𝐺, 𝐼 | ) ∥ 𝑃 𝜃 ( 𝐸 = 𝑒 )) .

Figure 6: Visualization of user embedding distributions using various methods on the Douban dataset. CausalDiffRec ensures that hot items and cold items have representations that are nearly co-located within the same space.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-92b748f2-b3e2-4efb-b21c-378aa1671492.jpg)

Figure 7: Visualization of user embedding distributions using various methods on the Yelp2018 dataset. CausalDiffRec ensures that hot items and cold items have representations that are nearly co-located within the same space.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00490v4-figure-107fe5cc-41b2-4cdc-80f9-1a2a18ee6cf6.jpg)

## C DATASET DETAIL

Processing Details . We retain only those users with at least 15 interactions on the Food dataset, at least 25 interactions on the Yelp2018 and Douban datasets, and items with at least 50 interactions on these datasets. For all three datasets, only interactions with ratings of 4 or higher are considered positive samples. For the KuaiRec dataset, interactions with a watch ratio of 2 or higher are considered positive samples.

We directly follow [28] to process the dataset above to construct three common types of out-of-distribution data:

- · Popularity shift : We randomly select 20% of interactions to form the OOD test set, ensuring a uniform distribution of item popularity. The remaining data is split into training, validation, and IID test sets in a ratio of 7:1:2, respectively. This type of distribution shift is applied to the Yelp2018 and Douban datasets.
- · Temporal shift : We sort the dataset by timestamp in descending order and designate the most recent 20% of each user's interactions as the OOD test set. The remaining data is split into training, validation, and IID test sets in a ratio of 7:1:2, respectively. The food dataset is used for this type of distribution shift.
- · Exposure shift : In KuaiRec, the smaller matrix, which is fully exposed, serves as the OOD test set. The larger matrix collected from the online platform is split into training, validation, and IID test sets in a ratio of 7:1:2, respectively, creating a distribution shift.

## D HYPERPARAMETER SETTINGS

We implement our CausalDiffRec in Pytorch. All experiments are conducted on a single RTX-4090 with 24G memory. Following the default hyperparameter search settings of the baselines, we expand their hyperparameter search space and tune the hyperparameters. For our CausalDiffRec, we tune the learning rates in { 1 𝑒 -3 1 , 𝑒 -

Table 4: Model performance comparison on IID datasets.

| Dataset   | Ablation      |   R@10 |   R@20 |   N@10 |   N@20 |
|-----------|---------------|--------|--------|--------|--------|
| KuaiRec   | LightGCN      | 0.0154 | 0.0174 | 0.0272 | 0.021  |
| KuaiRec   | AdvDrop       | 0.0431 | 0.0258 | 0.0469 | 0.0276 |
| KuaiRec   | AdvInfo       | 0.0514 | 0.0298 | 0.0518 | 0.03   |
| KuaiRec   | DRO           | 0.0307 | 0.0226 | 0.0505 | 0.0291 |
| KuaiRec   | CausalDiffRec | 0.0567 | 0.0472 | 0.0634 | 0.0707 |
| Yelp2018  | LightGCN      | 0.0023 | 0.0022 | 0.0039 | 0.0029 |
| Yelp2018  | AdvDrop       | 0.0061 | 0.0051 | 0.0063 | 0.005  |
| Yelp2018  | AdvInfo       | 0.0052 | 0.004  | 0.0062 | 0.0049 |
| Yelp2018  | DRO           | 0.0069 | 0.055  | 0.0086 | 0.0065 |
| Yelp2018  | CausalDiffRec | 0.0102 | 0.012  | 0.0182 | 0.0134 |

Algorithm 1 Training of CausalDiffRec under Multiple Environments

- 1: Input: The user-item interaction graph 𝐺 (V E) , and node feature matrix X ; Using the 𝜔 𝜃 , 1 , and 𝜃 2 to initial environment generator 𝑔 𝜔 (·) , environment 𝑃 𝜃 1 (·) , and graph representation learner (ie., sampling approximator) 𝑓 𝜃 2 (·) , respectively.
- 2: while not converged do

3: for all 𝑢 ∈ 𝑈 do

4: for all 𝑘 ∈ { 1 2 , , . . . , 𝐾 } do

5:

Get the modified modified graphs 𝐺 𝑘 by Eq. (9);

6: Infer the causal environment label 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 from Eq. (43);

7: Obtain the damage representation x 𝑡 𝐾 by Eq. (14);

8: // Forward process

9:

Sample

x

𝑡

-

1

𝑘

by

feeding

𝑧

𝑐𝑎𝑢𝑠𝑎𝑙

and

x

𝑡

𝑘

into

𝑓 𝜃 2 ( 𝑧 𝑐𝑎𝑢𝑠𝑎𝑙 , x 𝑡 𝑘 ) ;

10:

// Reverse process

11:

Calculate 𝑓 𝜃 2 ( x 𝑡 - 1 𝑘 ) via Eq. (17) ;

12: Calculate the gradients w.r.t. the loss in Eq. (27);

13: end for

14:

end for

15: Average the gradients over | 𝑈 | users and 𝐾 environments; 16: Update 𝜔 𝜃 , 1 , and 𝜃 2 via AdamW optimizer;

17: end while

18: Output: 𝑔 𝜔 (·) , 𝑃 𝜃 1 (·) , and 𝑓 𝜃 2 (·) .

4 1 , 𝑒 -5 . The number of diffusion steps varies between 10 and } 1000, and the diffusion embedding size is chosen in { 8 16 32 64 , , , } . Additional hyperparameter details are available in our released code.

## E BASELINES

We compare the CusalDiffRec with the following state-of-the-art models:

- · LightGCN [9]. It is an effective collaborative filtering method based on graph convolutional networks (GCNs) that streamline NGCF's message propagation scheme by eliminating non-linear projection and activation.
- · SGL [40]. It uses LightGCN as the backbone and incorporates a series of structural augmentations to enhance representation learning.
- · SimGCL [50]. This model employs a simple contrastive learning (CL) approach that avoids graph augmentations and introduces uniform noise into the embedding space to generate contrastive views.
- · LigthGCL [1]. This uses LightGCN as its backbone and introduces uniform noise into the embedding space for contrastive learning without relying on graph augmentations
- · CDR [32]. It captures preference shifts using a temporal variational autoencoder and learns the sparse influence from multiple environments.
- · InvPref [39]. It is a general debiasing model that iteratively decomposes invariant and variant preferences from biased observational user behaviors by estimating heterogeneous environments corresponding to different types of latent bias.
- · InvCF [55]. This model aims to mitigate popularity shift to discover disentangled representations that faithfully reveal the latent preference and popularity semantics without making any assumption about the popularity distribution.
- · AdvInfoNCE [54]. It is an InfoNCE variant that leverages a detailed hardness-aware ranking criterion to improve the recommender's ability to generalize
- · AdvDrop [53]. It is designed to alleviate general biases and inherent bias amplification in graph-based collaborative filtering by enforcing embedding-level invariance from learned bias-related views.
- · DR-GNN [28]. A GNN-based OOD recommendation algorithm solves the data distribution shift via the Distributionally Robust Optimization theory.

## F MODEL COMPLEXITY ANALYSIS

We analyze the time complexity of our CausalDiffRec across its different components: i) The environment generator has a time complexity of 𝑂 𝑘 ( · | 𝐸 |) , where | 𝐸 | is the size of the edge set and 𝑘 is the number of generated environments. ii) The most timeconsuming part of the causal diffusion component is the diffusion generation. Initially, a Variational Graph Auto-Encoder (VGAE) maps the graph-structured data to a fixed distribution in latent space with a complexity of 𝑂 𝐿 ( · | 𝐸 | · 𝑑 ) , where 𝐿 is the number of layers in the encoder part of VGAE, and 𝑑 represents the hidden layer dimensions. The overall time complexity of the diffusion model is 𝑂 𝑇 ( · 𝐿 · 𝑑 ) , where 𝑇 is the number of time steps. iii) The environment inference component has a time complexity of 𝑂 ( 1 . In summary, CausalDiffRec can achieve overall complexity ) comparable to state-of-the-art diffusion-based recommendation models such as DiffRec [33] and RecDiff [22].
Chu Zhao Enneng Yang Yuliang Liang Pengxiang Lan Yuting Liu Jianzhe Zhao Guibing Guo Xingwei Wang
Graph Representation Learning via Causal Diffusion for Out-of-Distribution Recommendation
Graph Neural Networks (GNNs)-based recommendation algorithms typically assume
that training and testing data are drawn from independent and identically
distributed (IID) spaces. However, this assumption often fails in the presence
of out-of-distribution (OOD) data, resulting in significant performance
degradation. In this study, we construct a Structural Causal Model (SCM) to
analyze interaction data, revealing that environmental confounders (e.g., the
COVID-19 pandemic) lead to unstable correlations in GNN-based models, thus
impairing their generalization to OOD data. To address this issue, we propose a
novel approach, graph representation learning via causal diffusion
(CausalDiffRec) for OOD recommendation. This method enhances the model's
generalization on OOD data by eliminating environmental confounding factors and
learning invariant graph representations. Specifically, we use backdoor
adjustment and variational inference to infer the real environmental
distribution, thereby eliminating the impact of environmental confounders. This
inferred distribution is then used as prior knowledge to guide the
representation learning in the reverse phase of the diffusion process to learn
the invariant representation. In addition, we provide a theoretical derivation
that proves optimizing the objective function of CausalDiffRec can encourage
the model to learn environment-invariant graph representations, thereby
achieving excellent generalization performance in recommendations under
distribution shifts. Our extensive experiments validate the effectiveness of
CausalDiffRec in improving the generalization of OOD data, and the average
improvement is up to 10.69% on Food, 18.83% on KuaiRec, 22.41% on Yelp2018, and
11.65% on Douban datasets.