├── schematic_simulation_process.png ├── tx_lim_operator.m ├── tx_lim_trend.m ├── tx_lim_simulation.m └── README.md /schematic_simulation_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tongtong-Xu-PSL/LIM/HEAD/schematic_simulation_process.png -------------------------------------------------------------------------------- /tx_lim_operator.m: -------------------------------------------------------------------------------- 1 | function [L,Q] = tx_lim_operator(X0,Xtau,tau0) 2 | %----------------- 3 | % Input: X(t), X(t+tau0), and the training lag tau0 4 | % Output: L - LIM operator; Q - noise covariance 5 | % 6 | % Xu et al 2022 7 | %----------------- 8 | 9 | C0 = X0*X0'/(size(X0,2)-1); 10 | Ctau = Xtau*X0'/(size(X0,2)-1); 11 | 12 | % linear operator 13 | G = Ctau/C0; 14 | L = logm(G)/tau0; 15 | 16 | % noise statistics 17 | Q = -1*(L*C0+C0*L'); 18 | 19 | end -------------------------------------------------------------------------------- /tx_lim_trend.m: -------------------------------------------------------------------------------- 1 | function [u,alpha,Xtr] = tx_lim_trend(X0,Xtau,tau0) 2 | %----------------- 3 | % Input: X(t), X(t+tau0), and the training lag tau0 4 | % Output: u - spatial pattern of LIM trend mode 5 | % alpha - temporal evolution of the LIM trend mode 6 | % Xtr - trend component in PC space. 7 | % 8 | % Note that the least damped mode should typically be stationary, meaning 9 | % the imaginary part of DD(1) should be 0. Please do not use this code if 10 | % you find DD(1) a complex value. 11 | % 12 | % After getting Xtr in PC space, we (in Xu et al 2022) obtained the spatial 13 | % temporal evolution of the trend by dot product of EOFs with Xtr. This 14 | % spatial temporal evolution is subtracted from original climate variables 15 | % for detrending. 16 | % 17 | % Xu et al 2022 18 | %----------------- 19 | 20 | % obtain LIM operator 21 | [L,~] = tx_lim_operator(X0,Xtau,tau0); 22 | 23 | % eigendecomposition of L matrix: u and adjoint matrix v 24 | [U,D] = eig(L); 25 | V = inv(U)'; 26 | 27 | % sort eigenvalues according to the decay rate 28 | % and sort eigenvectors accordingly 29 | DD = diag(D); 30 | [~,loc] = sort(real(DD),'descend'); 31 | UU = U(:,loc); 32 | VV = V(:,loc); 33 | 34 | % get the least damped mode 35 | u = UU(:,1); % spatial pattern of LIM trend mode 36 | v = VV(:,1); 37 | alpha = v'*X; % time series of LIM trend mode 38 | 39 | % trend in PC space 40 | Xtr = u*alpha; 41 | 42 | end -------------------------------------------------------------------------------- /tx_lim_simulation.m: -------------------------------------------------------------------------------- 1 | function Xg = tx_lim_simulation(X,tau0,group) 2 | %----------------- 3 | % Input: X(t), the training lag tau0, and the number of ensemble members 4 | % Output: Xg(t), the ensemble with each realization the same length as 5 | % X(t), and the total number of realizations determined by "group" 6 | % 7 | % Note that "group" needs to be multiple of 20, e.g., 40, 100. 8 | % 9 | % Xu et al 2022 10 | %----------------- 11 | 12 | % basic parameters & vectors; 13 | dt = 16/24/30; 14 | samplelen = size(X,2); 15 | 16 | % get L & Q from LIM 17 | X0 = X(:,1:end-tau0); 18 | Xtau = X(:,1+tau0:end); 19 | [L,Q] = tx_lim_operator(X0,Xtau,tau0); 20 | 21 | % decompose the noise statistics 22 | [V,D] = eig(Q); 23 | [DD,loc] = sort(diag(D),'descend'); 24 | V = V(:,loc); 25 | 26 | % keep only positive eigenvalues and rescale 27 | ploc = find(real(DD)>=0); 28 | Dp = DD(ploc); 29 | Dp = Dp*sum(real(DD))/sum(real(Dp)); 30 | Vp = V(:,ploc); 31 | 32 | % matrices used in integration 33 | noise = Vp*diag(sqrt(Dp*dt)); 34 | coef = eye(size(L,1))+L*dt; 35 | 36 | % initialization (discard the first 2000 years) 37 | subgroup = 20; 38 | X0 = zeros(size(X,1),subgroup); 39 | [X0,~] = tx_integration(X0,coef,noise,12*2000,dt); 40 | 41 | % simulation 42 | [~,Xp] = tx_integration(X0,coef,noise,samplelen*group/subgroup,dt); 43 | 44 | % organize into an ensemble: each member has length of "samplelen" and in 45 | % total there are "group" number of members 46 | Xg = zeros(size(Xp,1),samplelen,group); 47 | k = 0; 48 | for i = 1:subgroup 49 | for j = 1:(group/subgroup) 50 | k = k + 1; 51 | Xg(:,:,k) = Xp(:,i,(1:samplelen)+samplelen*(j-1)); 52 | end 53 | end 54 | 55 | end 56 | 57 | function [X0,Xp] = tx_integration(X0,coef,noise,totalMon,dt) 58 | 59 | Xp = []; 60 | g = size(X0,2); 61 | for i = 1:totalMon/dt 62 | % random number generator 63 | rt = normrnd(0,1,size(noise,2),g); 64 | 65 | % integration and iteration 66 | Xt = coef*X0+noise*rt; 67 | xp = (X0+Xt)/2; 68 | 69 | X0 = Xt; 70 | if mod(i,1/dt)==0 71 | Xp = cat(3,Xp,xp); 72 | end 73 | if any(isnan(X0)) 74 | disp('Simulation blows up!') 75 | break 76 | end 77 | end 78 | 79 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linear Inverse Model 2 | 3 | #stochastic-simulation #multivariate-linear-regression 4 | 5 | ## 1. Introduction 6 | 7 | The time evolution of a climate state $\mathbf{x}$ may often be approximated by the stochastically forced linear dynamical system, 8 | 9 | $$ 10 | \frac{\mathrm{d}\mathbf{x}}{\mathrm{d}t} = \mathbf{Lx} + \mathbf{\xi} 11 | $$ 12 | 13 | where $\mathbf{x}(t)$ is the climate state, $\mathbf{L}$ is a linear dynamical operator, $\mathbf{\xi}$ is a vector of temporally white noise that may have spatial structure, and $t$ is time. Determining the system from covariances of climate variables results in a Linear Inverse Model (LIM; Penland & Sardeshmukh 1995). 14 | 15 | The LIM has been extensively used in predicting seasonal-to-interannual surface ocean conditions (e.g., Alexander et al 2008; Newman & Sardeshmukh 2017; Shin & Newman 2021). But it can also be run as a climate simulation model (Penland & Matrosova 1994). One recent application is Xu et al 2022. And this repository serves as a code source associated with Xu et al 2022. Codes are written in MATLAB. 16 | 17 | ## 2. Solving LIM operator 18 | 19 | $\mathbf{x}(t)$ usually represents temporally evolving ampitudes of the leading Empirical Orthogonal Functions (EOFs) of climate variables (after removing climatology). 20 | 21 | $\mathbf{C}(0) = <\mathbf{x}(t)\mathbf{x}(t)^\mathrm{T}>$ is the auto-covariance matrix of $\mathbf{x}(t)$. 22 | 23 | $\mathbf{C}(\tau_0) = <\mathbf{x}(t+\tau_0)\mathbf{x}(t)^\mathrm{T}>$ is the lag-covariance matrix of $\mathbf{x}(t)$. $\tau_0$ is the training lag between $t$ and $t+\tau_0$. 24 | 25 | $\mathbf{G}(\tau_0) = \mathbf{C}(\tau_0)/\mathbf{C}(0)$ solves the Green function, which then gives us the LIM operator $\mathbf{L} = \log(\mathbf{G}(\tau_0))$. 26 | 27 | The following [MATLAB function](https://github.com/Tongtong-Xu-PSL/LIM/blob/main/tx_lim_operator.m) can be used to solve the LIM operator. Note that it also provides the covariance of the noise $\mathbf{\xi}(t)$, whose role is going to be introduced in the following section. 28 | 29 | ```Matlab 30 | function [L, Q] = tx_lim_operator(X0,Xtau,tau0) 31 | %----------------- 32 | % Input: X(t), X(t+tau0), and the training lag tau0 33 | % Output: L - LIM operator; Q - noise covariance 34 | % 35 | % Xu et al 2022 36 | %----------------- 37 | 38 | C0 = X0*X0'/(size(X0,2)-1); 39 | Ctau = Xtau*X0'/(size(X0,2)-1); 40 | 41 | % linear operator 42 | G = Ctau/C0; 43 | L = logm(G)/tau0; 44 | 45 | % noise statistics 46 | Q = -1*(L*C0+C0*L'); 47 | 48 | end 49 | ``` 50 | 51 | ## 3. Extracting long-term trend from LIM operator 52 | 53 | Several studies (e.g., Frankignoul et al 2017; Alexander et al 2022; Di Lorenzo et al 2023) have shown how the externally forced trend is captured by the least damped eigenmode of $\mathbf{L}$. This is done by performing an eigenanalysis on $\mathbf{L}$; that is, 54 | 55 | $\mathbf{LU} = \mathbf{U\Lambda}$ where $\mathbf{U}$ is the matrix of eigenvectors and $\mathbf{\Lambda}$ is the diagonal matrix of eigenvalues, $\lambda_i$. 56 | 57 | $\mathbf{V}$, the eigenvectors of $\mathbf{L}$’s adjoint, is simply determined by $\mathbf{V}^\mathrm{H}=\mathbf{U}^{-1}$, such that $\mathbf{L}^\mathrm{H} \mathbf{V}=\mathbf{VΛ}^\*$, where $\mathrm{H}$ is the conjugate transpose and $*$ is the conjugate. 58 | 59 | Check this [Wolfram World page](https://mathworld.wolfram.com/Eigenvector.html) for useful information to understand the derivation. 60 | 61 | The least damped mode corresponds to the mode that decays the slowest, i.e., the magnitude of $|\Re(\lambda_i)|$ is the smallest among all eigenvalues. The associated eigenvector $\mathbf{u}_i$ is the spatial pattern of the trend mode, and the time series of the trend mode is obtained by $\mathbf{v}^{\mathrm{H}}_i \mathbf{x}(t)$. 62 | 63 | The trend component in PC space is then determined by multiplying the trend spatial pattern with the temporally varying amplitudes, i.e., $\mathbf{x}_{TR}(t) = \mathbf{u}_i \mathbf{v}^{\mathrm{H}}_i \mathbf{x}(t) $. 64 | 65 | After getting $\mathbf{x}_{TR}(t)$ in PC space, we (in Xu et al 2022) obtained the spatial temporal evolution of the trend by dot product of EOFs with $\mathbf{x}\_{TR}(t)$. This spatial temporal evolution is subtracted from original climate variables for detrending. 66 | 67 | The following [MATLAB function](https://github.com/Tongtong-Xu-PSL/LIM/blob/main/tx_lim_trend.m) can be used to extract the LIM trend. 68 | 69 | ```Matlab 70 | function [u,alpha,Xtr] = tx_lim_trend(X0,Xtau,tau0) 71 | %----------------- 72 | % Input: X(t), X(t+tau0), and the training lag tau0 73 | % Output: u - spatial pattern of LIM trend mode 74 | % alpha - temporal evolution of the LIM trend mode 75 | % Xtr - trend component in PC space. 76 | % 77 | % Note that the least damped mode should typically be stationary, meaning 78 | % the imaginary part of DD(1) should be 0. Please do not use this code if 79 | % you find DD(1) a complex value. 80 | % 81 | % After getting Xtr in PC space, we (in Xu et al 2022) will get the spatial 82 | % temporal evolution of the trend by dot product of EOFs with Xtr. This 83 | % spatial temporal evolution is subtracted from original climate variables 84 | % for detrending. 85 | % 86 | % Xu et al 2022 87 | %----------------- 88 | 89 | % obtain LIM operator 90 | [L,~] = tx_lim_operator(X0,Xtau,tau0); 91 | 92 | % eigendecomposition of L matrix: u and adjoint matrix v 93 | [U,D] = eig(L); 94 | V = inv(U)'; 95 | 96 | % sort eigenvalues according to the decay rate 97 | % and sort eigenvectors accordingly 98 | DD = diag(D); 99 | [~,loc] = sort(real(DD),'descend'); 100 | UU = U(:,loc); 101 | VV = V(:,loc); 102 | 103 | % get the least damped mode 104 | u = UU(:,1); % spatial pattern of LIM trend mode 105 | v = VV(:,1); 106 | alpha = v'*X; % time series of LIM trend mode 107 | 108 | % trend in PC space 109 | Xtr = u*alpha; 110 | 111 | end 112 | ``` 113 | 114 | ## 4. Conducting LIM climate simulation 115 | 116 | LIM simulations may be generated by integrating white noise forcing with observationally constrained spatial structures (determined from $\mathbf{Q}$) forward in time. Example applications include Capotondi & Sardeshmukh 2017, Xu et al 2021. The following schematic diagram illustrates the process of stochastic integration using LIM, 117 | 118 | 119 | 120 | Repeating the above process, one can obtain an ensemble of realizations in length of interest. Useful references that document the integration process in detail includes Penland & Matrosova 1994, [supplementary file](https://agupubs.onlinelibrary.wiley.com/action/downloadSupplement?doi=10.1029%2F2020GL090661&file=2020GL090661-sup-0001-Text+SI-S01.pdf) of Xu et al 2021. 121 | 122 | The following [MATLAB code](https://github.com/Tongtong-Xu-PSL/LIM/blob/main/tx_lim_simulation.m) can be used to perform ensemble of LIM simulation. 123 | 124 | ```Matlab 125 | function Xg = tx_lim_simulation(X,tau0,group) 126 | %----------------- 127 | % Input: X(t), the training lag tau0, and the number of ensemble members 128 | % Output: Xg(t), the ensemble with each realization the same length as 129 | % X(t), and the total number of realizations determined by "group" 130 | % 131 | % Note that "group" needs to be multiple of 20, e.g., 40, 100. 132 | % 133 | % Xu et al 2022 134 | %----------------- 135 | 136 | % basic parameters & vectors; 137 | dt = 16/24/30; 138 | samplelen = size(X,2); 139 | 140 | % get L & Q from LIM 141 | X0 = X(:,1:end-tau0); 142 | Xtau = X(:,1+tau0:end); 143 | [L,Q] = tx_lim_operator(X0,Xtau,tau0); 144 | 145 | % decompose the noise statistics 146 | [V,D] = eig(Q); 147 | [DD,loc] = sort(diag(D),'descend'); 148 | V = V(:,loc); 149 | 150 | % keep only positive eigenvalues and rescale 151 | ploc = find(real(DD)>=0); 152 | Dp = DD(ploc); 153 | Dp = Dp*sum(real(DD))/sum(real(Dp)); 154 | Vp = V(:,ploc); 155 | 156 | % matrices used in integration 157 | noise = Vp*diag(sqrt(Dp*dt)); 158 | coef = eye(size(L,1))+L*dt; 159 | 160 | % initialization (discard the first 2000 years) 161 | subgroup = 20; 162 | X0 = zeros(size(X,1),subgroup); 163 | [X0,~] = tx_integration(X0,coef,noise,12*2000,dt); 164 | 165 | % simulation 166 | [~,Xp] = tx_integration(X0,coef,noise,samplelen*group/subgroup,dt); 167 | 168 | % organize into an ensemble: each member has length of "samplelen" and in 169 | % total there are "group" number of members 170 | Xg = zeros(size(Xp,1),samplelen,group); 171 | k = 0; 172 | for i = 1:subgroup 173 | for j = 1:(group/subgroup) 174 | k = k + 1; 175 | Xg(:,:,k) = Xp(:,i,(1:samplelen)+samplelen*(j-1)); 176 | end 177 | end 178 | 179 | end 180 | 181 | function [X0,Xp] = tx_integration(X0,coef,noise,totalMon,dt) 182 | 183 | Xp = []; 184 | g = size(X0,2); 185 | for i = 1:totalMon/dt 186 | % random number generator 187 | rt = normrnd(0,1,size(noise,2),g); 188 | 189 | % integration and iteration 190 | Xt = coef*X0+noise*rt; 191 | xp = (X0+Xt)/2; 192 | 193 | X0 = Xt; 194 | if mod(i,1/dt)==0 195 | Xp = cat(3,Xp,xp); 196 | end 197 | if any(isnan(X0)) 198 | disp('Simulation blows up!') 199 | break 200 | end 201 | end 202 | 203 | end 204 | ``` 205 | 206 | ## 5. Final Remarks 207 | 208 | The repository provides key elements of LIM analyses in Xu et al 2022: (1) solving LIM operator from observed climate variables, (2) identifying and extracting long-term trend from LIM without assuming whether the trend is linear or nonlinear, (3) conducting large ensembles of climate simulations using LIM. These above codes work under the assumption that the climate system is quasi-stationary and the constructed linear system is stable. For example, [this lecture](http://courses.ece.ubc.ca/491m/lectures/Lecture05.pdf) has some discussion about the stability of linear systems, which could be useful. 209 | 210 | Stay tune for more updates! 211 | 212 | If you find the materials useful, please help us by citing our very recent paper (Xu et al 2022)! 213 | 214 | 215 | 216 | ### References 217 | 218 | Penland C, Matrosova L. A Balance Condition for Stochastic Numerical-Models with Application to the El-Nino-Southern Oscillation. Journal of Climate 1994, 7(9): 1352-1372. 219 | 220 | Penland C, Sardeshmukh PD. The Optimal-Growth of Tropical Sea-Surface Temperature Anomalies. Journal of Climate 1995, 8(8): 1999-2024. 221 | 222 | Alexander M.A, Matrosova L, Penland C, Scott J.D, Chang P. Forecasting Pacific SSTs: Linear inverse model predictions of the PDO. Journal of Climate 2008, 21(2): 385-402. 223 | 224 | Frankignoul C, Gastineau G, Kwon YO. Estimation of the SST Response to Anthropogenic and External Forcing and Its Impact on the Atlantic Multidecadal Oscillation and the Pacific Decadal Oscillation. Journal of Climate 2017, 30(24): 9871-9895. 225 | 226 | Newman M, Sardeshmukh PD. Are we near the predictability limit of tropical Indo-Pacific sea surface temperatures? Geophysical Research Letters 2017, 44(16): 8520-8529. 227 | 228 | Capotondi A, Sardeshmukh PD. Is El Niño really changing? Geophysical Research Letters 2017, 44(16): 8548-8556. 229 | 230 | Xu T, Newman M, Capotondi A, Di Lorenzo E. The Continuum of Northeast Pacific Marine Heatwaves and Their Relationship to the Tropical Pacific. Geophysical Research Letters 2021, 48(2): 2020GL090661. 231 | 232 | Shin SI, Newman M. Seasonal Predictability of Global and North American Coastal Sea Surface Temperature and Height Anomalies. Geophysical Research Letters 2021, 48(10). 233 | 234 | Alexander MA, Shin S-I, Battisti DS. The Influence of the Trend, Basin Interactions, and Ocean Dynamics on Tropical Ocean Prediction. Geophysical Research Letters 2022, 49(3): e2021GL096120. 235 | 236 | Xu T, Newman M, Capotondi A, Stevenson S, Di Lorenzo E, Alexander M.A. An increase in marine heatwaves without significant changes in surface ocean temperature variability. Nature Communications 2022. Accepted. 237 | 238 | Di Lorenzo E, Xu T, Zhao Y, Newman M, Capotondi A, Stevenson S, et al. Modes and Mechanisms of Pacific Decadal-Scale Variability. Annual Review of Marine Science 2023, 15(1), https://doi.org/10.1146/annurev-marine-040422-084555. --------------------------------------------------------------------------------