-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample_4_SolveSSITModels_FSP.m
More file actions
185 lines (144 loc) · 7.42 KB
/
example_4_SolveSSITModels_FSP.m
File metadata and controls
185 lines (144 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%% example_4_SolveSSITModels_FSP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Section 2.2: Finding and visualizing master equation solutions
% * Compute Finite State Projection (FSP) solutions
%%%%%%%%%%%%%%%%%%d%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Preliminaries
% Use the models from example_1_CreateSSITModels
% clear
% close all
% example_1_CreateSSITModels
% Load the models created in example_1_CreateSSITModels
% load('example_1_CreateSSITModels.mat')
% View model summaries:
Model.summarizeModel
STL1.summarizeModel
STL1_4state.summarizeModel
% Set the times at which distributions will be computed:
Model.tSpan = linspace(0,50,101);
STL1.tSpan = linspace(0,50,101);
STL1_4state.tSpan = linspace(0,50,101);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ex(1): Use the stochastic Finite State Projection (FSP)
% approximation of the Chemical Master Equation (CME) to solve the time
% evolution of state space probabilities for the bursting gene example
% model from example_1_CreateSSITModels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Model:
% Create a copy of the bursting gene model for FSP:
Model_FSP = Model;
% Ensure the solution scheme is set to FSP (default):
Model_FSP.solutionScheme = 'FSP';
% Set FSP 1-norm error tolerance:
Model_FSP.fspOptions.fspTol = 1e-4;
% Guess initial bounds on FSP StateSpace:
Model_FSP.fspOptions.bounds = [0,0,0,1,1,200];
% Have FSP approximate the steady state for the initial distribution
% by finding the eigenvector corresponding to the smallest magnitude
% eigenvalue (i.e., zero, for generator matrix A, d/dtP(t)=AP(t)):
Model_FSP.fspOptions.initApproxSS = false;
% This function compiles and stores the given reaction propensities
% into symbolic expression functions that use sparse matrices to
% operate on the system based on the current state. The functions are
% stored with the given prefix, in this case, 'Model_FSP':
Model_FSP = Model_FSP.formPropensitiesGeneral('Model_FSP');
% Solve with FSP:
[~,~,Model_FSP] = Model_FSP.solve;
% Means and standard deviations:
Model_FSP.plotFSP(speciesNames=Model_FSP.species,...
plotType='meansAndDevs', lineProps={'linewidth',4},...
Title='Bursting Gene', TitleFontSize=26,...
AxisLabelSize=20, TickLabelSize=20, YLabel='Molecule Count',...
XLabel='Time', LegendFontSize=20, LegendLocation='southeast');
% Marginal distributions:
Model_FSP.plotFSP(speciesNames=Model_FSP.species(3),...
plotType='marginals', indTimes=[1,12,24,50,101],...
lineProps={'linewidth',3}, XLim=[0,15], Colors=[0.93,0.69,0.13]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ex(2): Use the stochastic Finite State Projection (FSP)
% approximation of the Chemical Master Equation (CME) to solve the time
% evolution of state space probabilities for the time-varying STL1 yeast
% model from example_1_CreateSSITModels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STL1:
% Create a copy of the time-varying STL1 yeast model for FSP:
STL1_FSP = STL1;
% Ensure the solution scheme is set to FSP (default):
STL1_FSP.solutionScheme = 'FSP';
% Set FSP 1-norm error tolerance:
STL1_FSP.fspOptions.fspTol = 1e-4;
% Guess initial bounds on FSP StateSpace:
STL1_FSP.fspOptions.bounds = [0,0,0,1,1,200];
% Have FSP approximate the steady state for the initial distribution
% by finding the eigenvector corresponding to the smallest magnitude
% eigenvalue (i.e., zero, for generator matrix A, d/dtP(t)=AP(t)):
STL1_FSP.fspOptions.initApproxSS = false;
% This function compiles and stores the given reaction propensities
% into symbolic expression functions that use sparse matrices to
% operate on the system based on the current state. The functions are
% stored with the given prefix, in this case, 'STL1_FSP':
STL1_FSP = STL1_FSP.formPropensitiesGeneral('STL1_FSP');
% Solve with FSP:
[~,~,STL1_FSP] = STL1_FSP.solve;
% Means and standard deviations:
STL1_FSP.plotFSP(speciesNames=STL1_FSP.species,...
plotType='meansAndDevs', lineProps={'linewidth',4},...
Title='STL1', TitleFontSize=26,...
AxisLabelSize=20, TickLabelSize=20, YLabel='Molecule Count',...
XLabel='Time', LegendFontSize=20, LegendLocation='southeast');
% Marginal distributions:
STL1_FSP.plotFSP(speciesNames=STL1_FSP.species(3),...
plotType='marginals', indTimes=[1,12,24,50,101],...
lineProps={'linewidth',3}, XLim=[0,15], Colors=[0.93,0.69,0.13]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ex(3): Use the stochastic Finite State Projection (FSP)
% approximation of the Chemical Master Equation (CME) to solve the time
% evolution of state space probabilities for the 4-state
% time-varying STL1 yeast model from example_1_CreateSSITModels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STL1 (4-state):
% Create a copy of the time-varying STL1 yeast model for FSP:
STL1_4state_FSP = STL1_4state;
% Ensure the solution scheme is set to FSP (default):
STL1_4state_FSP.solutionScheme = 'FSP';
% Set FSP 1-norm error tolerance:
STL1_4state_FSP.fspOptions.fspTol = 1e-4;
% Guess initial bounds on FSP StateSpace:
STL1_4state_FSP.fspOptions.bounds = [1,1,1,1,200];
% Have FSP approximate the steady state for the initial distribution
% by finding the eigenvector corresponding to the smallest magnitude
% eigenvalue (i.e., zero, for generator matrix A, d/dtP(t)=AP(t)):
STL1_4state_FSP.fspOptions.initApproxSS = true;
% This function compiles and stores the given reaction propensities
% into symbolic expression functions that use sparse matrices to
% operate on the system based on the current state. The functions are
% stored with the given prefix, in this case, 'STL1_4state_FSP':
STL1_4state_FSP = ...
STL1_4state_FSP.formPropensitiesGeneral('STL1_4state_FSP');
% Solve Model:
[~,~,STL1_4state_FSP] = STL1_4state_FSP.solve;
%% Plots for FSP solutions:
% Means only:
% STL1_4state_FSP.plotFSP(STL1_4state_FSPsoln,...
% STL1_4state_FSP.species, 'means')
% Means and standard deviations:
STL1_4state_FSP.plotFSP(speciesNames=STL1_4state_FSP.species(5),...
plotType='meansAndDevs', lineProps={'linewidth',4},...
Title='4-state STL1 (mRNA)', TitleFontSize=26,...
Colors=[0.23,0.67,0.2], AxisLabelSize=20, TickLabelSize=20,...
XLabel='Time', YLabel='Molecule Count',...
LegendFontSize=20, LegendLocation='northeast');
% Marginal distributions:
STL1_4state_FSP.plotFSP(speciesNames=STL1_4state_FSP.species(5),...
plotType='marginals', indTimes=[1,12,24,50,101],...
lineProps={'linewidth',3}, Colors=[0.23,0.67,0.2], XLim=[0,100])
% Joint distributions (warning: can be slow for many parameters!):
% STL1_4state_FSP.plotFSP(STL1_4state_FSPsoln,...
% STL1_4state_FSP.species(5), 'joints')
%% Save FSP models & solutions
saveNames = unique({
'Model_FSP'
'STL1_FSP'
'STL1_4state_FSP'
});
save('example_4_SolveSSITModels_FSP',saveNames{:})