-
Notifications
You must be signed in to change notification settings - Fork 92
/
gpsimMapCreate.m
218 lines (192 loc) · 6.2 KB
/
gpsimMapCreate.m
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
function model = gpsimMapCreate(numGenes, numProteins, times, geneVals, ...
geneVars, options)
% GPSIMMAPCREATE Create a GPSIMMAP model.
% The GPSIMMAP model is a model for estimating the protein
% concentration in a small gene network where several genes are
% governed by one protein. The model is based on Gaussian processes
% and simple linear differential equations of the form
%
% dx(t)/dt = B + Cf(t) - Dx(t)
%
% where x(t) is a given genes concentration and f(t) is the protein
% concentration.
%
% FORMAT
% DESC creates a model for single input motifs with Gaussian
% processes.
% ARG numGenes : number of genes to be modelled in the system.
% ARG numProteins : number of proteins to be modelled in the
% system.
% ARG times : the time points where the data is to be modelled.
% ARG geneVals : the values of each gene at the different time points.
% ARG geneVars : the varuabces of each gene at the different time points.
% ARG options : options structure, the default options can be
% generated using gpsimMapOptions.
% RETURN model : model structure containing default
% parameterisation.
%
% SEEALSO : modelCreate, gpsimMapOptions
%
% COPYRIGHT : Neil D. Lawrence, 2006
%
% MODIFIED : Pei Gao, 2008
% SHEFFIELDML
if any(size(geneVars)~=size(geneVals))
error('The gene variances have a different size matrix to the gene values.');
end
if(numGenes ~= size(geneVals, 2))
error('The number of genes given does not match the dimension of the gene values given.')
end
if(size(times, 1) ~= size(geneVals, 1))
error('The number of time points given does not match the number of gene values given')
end
% Initial parameters for the differential equation.
if length(options.B)~=numGenes
error('Incorrect length of options.B');
end
if length(options.D)~=numGenes
error('Incorrect length of options.D');
end
if length(options.S)~=numGenes
error('Incorrect length of options.S');
end
%data collection times
model.yvar = geneVars;
model.y = geneVals;
model.t = times;
model.type = 'gpsimMap';
% Assign options
model.nonLinearity = options.nonLinearity;
model.Transform = 'exp';
model.B = options.B;
model.D = options.D;
model.S = options.S;
model.optimiser = options.optimiser;
if isfield(options,'bTransform') && isempty(options.bTransform)
model.bTransform = options.bTransform;
end
if isfield(options,'alphaTransform') && isempty(options.alphaTransform)
model.alphaTransform = options.alphaTransform;
end
model.gParam = options.gParam;
model.ngParam = size(options.gParam, 1)*numGenes;
if isfield(model,'gParam') && ~isempty(model.gParam);
model.nonLinearity = cell(1,numGenes);
if ~isstruct(options.nonLinearity)
for i=1:numGenes
model.nonLinearity{i} = options.nonLinearity;
model.isGroupNonlinearity = 1;
end
else
model.isGroupNonlinearity = 0;
model.nonLinearity = options.nonLinearity;
end
end
epsilon = 1e-2;
if isfield(options,'alpha') && ~isempty(options.alpha)
model.alpha = options.alpha;
model.includeRepression = 1;
else
if isfield(model,'isGroupNonlinearity')
if model.isGroupNonlinearity
if strcmp(model.nonLinearity{1}, 'repression')
model.alpha = epsilon*ones(1, numGenes);
model.includeRepression = 1;
else
model.alpha = zeros(1, numGenes);
model.includeRepression = 0;
end
else
for i = 1:numGenes
if strcmp(model.nonLinearity{i}, 'repression')
model.alpha(i) = epsilon;
model.includeRepression = 1;
else
model.alpha(i) = 0;
end
end
end
end
end
noiseInit = 1e-2;
if options.includeNoise
model.yvar = zeros(size(model.yvar));
model.includeNoise = options.includeNoise;
model.noiseVar = noiseInit * ones(1, numGenes);
end
%spacing used for path integration.
startPoint = options.startPoint;
endPoint = options.endPoint;
span = endPoint - startPoint;
% startPoint = startPoint - span/6;
% endPoint = endPoint + span/6;
fullSpan = endPoint - startPoint;
if isfield(options, 'intPoints')
model.step = fullSpan/(options.intPoints-1);
else
model.step = options.step;
end
model.mapt=[];
model.mapt=[model.mapt,startPoint:model.step:times(1)];
model.times_index = [length(model.mapt)];
for i=1:length(times)-1
model.mapt=[model.mapt,times(i)+model.step:model.step:times(i+1)];
model.times_index = [model.times_index,length(model.mapt)];
end
model.mapt=[model.mapt,times(length(times))+model.step:model.step:endPoint]'; %time vector
model.numMapPts = length(model.mapt);
model.numGenes = numGenes;
if isfield(options, 'fix')
model.fix = options.fix;
end
if isfield(options, 'priorProtein') && ~isempty(options.priorProtein)
model.priorProteinTimes = options.priorProteinTimes;
model.priorProtein = options.priorProtein;
model.consLambda = 0;
end
% Initialise the kernel.
if isstruct(options.kern)
model.kern = options.kern;
else
model.kern = kernCreate(model.mapt, options.kern);
end
% % Initialise the kernel.
% if isstruct(options.kern)
% model.kern = options.kern;
% else
% if ~isfield(options,'includeNoise')
% optionsKern.type = options.kern;
% optionskern.includeNoise = 0;
% else
% optionsKern.type = options.kern;
% optionsKern.includeNoise = options.includeNoise;
% end
%
% model.kern = kernCreate(model.mapt, optionsKern);
% end
% Initialise posterior at zero
model.f = zeros(length(model.mapt), 1);
model.varf = ones(size(model.f)); %Variances
% Initialise data portion of Hessian to zero.
model.W = zeros(length(model.mapt));
% Update the data Hessian.
model.updateW = true;
% Update some internal representations.
model = gpsimMapUpdateG(model);
model = gpsimMapUpdateYpred(model);
% Switch off update of f to update kernels & W.
model = gpsimMapUpdateKernels(model);
model = gpsimMapFunctionalUpdateW(model);
param = gpsimMapExtractParam(model);
model.numParams = length(param);
% Initialise any mean function
if isfield(options, 'meanFunction') & ~isempty(options.meanFunction)
if isstruct(options.meanFunction)
model.meanFunction = options.meanFunction;
else
model.meanFunction = ...
modelCreate(options.meanFunction, size(model.mapt, 1), 1, ...
options.meanFunctionOptions);
end
model.numParams = model.numParams + model.meanFunction.numParams;
end