Skip to content

Commit 6f7cf70

Browse files
authored
Add convolution to SSITMultiModel.m
For convolving probabilities in the case that there are indistinguishable subspecies observed at some unknown rate that act differently in the biological model.
1 parent 6231139 commit 6f7cf70

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

src/CommandLine/SSITMultiModel.m

+65-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,73 @@
9696
fspSolnsSMM(i).stateSpace = fspSoln.stateSpace; % Store state space
9797
end
9898
end
99-
save('combinedGR_a_fspSolns.mat', 'fspSolnsSMM'); % Save fspSolns for accessibility
10099
end
101100

101+
%% Solve and Convolve
102+
function [SMM1,SMM2,conv2solnTensor] = solveandconvolve(SMM1,SMM2,boundGuesses)
103+
arguments
104+
SMM1
105+
SMM2
106+
boundGuesses = [];
107+
end
108+
nMod = length(SMM1.SSITModels);
109+
fspSolnsSMM1 = struct(); % Allocate structure to store solutions
110+
fspSolnsSMM2 = struct(); % Allocate structure to store solutions
111+
for i = 1:nMod
112+
%% Solve the model using the FSP
113+
Model1 = SMM1.SSITModels{i};
114+
Model2 = SMM2.SSITModels{i};
115+
Model1.fspOptions.fspTol = 1e-4;
116+
Model2.fspOptions.fspTol = 1e-4;
117+
if ~isempty(boundGuesses)
118+
Model1.fspOptions.bounds = boundGuesses{i};
119+
Model2.fspOptions.bounds = boundGuesses{i};
120+
else
121+
Model1.fspOptions.bounds = [];
122+
Model2.fspOptions.bounds = [];
123+
end
124+
125+
if strcmp(Model1.solutionScheme,'FSP')
126+
[fspSoln1,SMM1.SSITModels{i}.fspOptions.bounds] = Model1.solve;
127+
[fspSoln2,SMM2.SSITModels{i}.fspOptions.bounds] = Model2.solve;
128+
% Initialize the structure for the current model
129+
fspSolnsSMM1(i).fsp = cell(numel(fspSoln1.fsp), 1); % Cell array for FSP solutions
130+
fspSolnsSMM2(i).fsp = cell(numel(fspSoln2.fsp), 1); % Cell array for FSP solutions
131+
for f=1:numel(fspSoln1.fsp)
132+
fspSolnsSMM1(i).fsp{f} = fspSoln1.fsp{f};
133+
fspSolnsSMM2(i).fsp{f} = fspSoln2.fsp{f};
134+
end
135+
SMM1.fspStateSpaces{i} = fspSoln1.stateSpace;
136+
SMM2.fspStateSpaces{i} = fspSoln2.stateSpace;
137+
fspSolnsSMM1(i).stateSpace = fspSoln1.stateSpace; % Store state space
138+
fspSolnsSMM2(i).stateSpace = fspSoln2.stateSpace; % Store state space
139+
end
140+
141+
%% Convolution
142+
for f=1:(max(numel(fspSoln1.fsp),numel(fspSoln2.fsp)))
143+
% f is time point, so solution tensors are FSP probabilities across states for each time point
144+
conv2solnTensor{f} = conv2(double(fspSoln1.fsp{f}.p.data),double(fspSoln2.fsp{f}.p.data));
145+
figure(f)
146+
contourf(log10(conv2solnTensor{f}))
147+
hold on
148+
end
149+
%% check
150+
for g=1:f % f is number of time points
151+
fspsoln1_sptensor{g} = double(fspSoln1.fsp{g}.p.data);
152+
fspsoln2_sptensor{g} = double(fspSoln2.fsp{g}.p.data);
153+
figure(g)
154+
subplot(1,3,1)
155+
contourf(log10(fspsoln1_sptensor{g}))
156+
subplot(1,3,2)
157+
contourf(log10(fspsoln2_sptensor{g}))
158+
subplot(1,3,3)
159+
contourf(log10(conv2solnTensor{g}))
160+
hold on
161+
end
162+
end
163+
end
164+
165+
102166
function SMM = updateModels(SMM,parameters,makeplot, fignums)
103167
% Updates parameters of the models to provided values and makes
104168
% plots of the results.

0 commit comments

Comments
 (0)