-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpcm_constructModelFamily.m
81 lines (75 loc) · 2.37 KB
/
pcm_constructModelFamily.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
function [M,CompI] = pcm_constructModelFamily(MComp,varargin)
% Constructs a model family from a set of component models
% with each model component either knocked-in or knocked-out.
% INPUT:
% MComp: Cell array of component models. Output will be of same type
% as these model components
% VARARGIN:
% 'alwaysInclude': Indices of model components that are always
% included
% 'fullModel': The model input is a full model, and should be broken
% into components if 'fullModel'==1
% only works if full model is a component model
% (has MComp.Gc field)
% OUTPUT:
% M: Cell array of models
% CompI: Component indicator for knock-in and knock-out of models
alwaysInclude = []; % If you have model components that are always included
fullModel =0;
pcm_vararginoptions(varargin,{'alwaysInclude','fullModel'});
% Check if input is full model
if fullModel==1
% break down into components
numComp = size(MComp.Gc,3);
for n=1:numComp
MTemp{n}.Gd = MComp.Gd(n,:);
MTemp{n}.Gc = MComp.Gc(:,:,n);
MTemp{n}.name = sprintf('Comp%d',n);
MTemp{n}.type = MComp.type;
end
clear MComp;
MComp = MTemp;
end
% Get number of fixed and variable components
numComp = numel(MComp);
fixComp = ismember([1:numComp],alwaysInclude);
numVarComp = numComp-sum(fixComp);
% Build all combination of 0,1,2... components
Comb = zeros(1,numVarComp);
for i=1:numVarComp
A=nchoosek([1:numVarComp],i);
n = size(A,1);
X=zeros(n,numVarComp);
for j=1:n
X(j,A(j,:))=1;
end;
Comb=[Comb;X];
end;
% Now build the models with fixed components set in
CompI= zeros(size(Comb,1),numComp);
i=1;
for i=1:size(Comb,1);
M{i}.type = MComp{1}.type;
vc=1;
M{i}.name =[];
M{i}.Gc =[];
for j=1:numComp
if fixComp(j) % Component is fixed (always included)
M{i}=pcm_addModelComp(M{i},MComp{j});
CompI(i,j)=1;
else
if Comb(i,vc)
M{i}=pcm_addModelComp(M{i},MComp{j});
CompI(i,j)=1;
end;
vc=vc+1;
end;
end;
if isempty(M{i}.Gc)
M{i}.numGparams=0; % Empty Model
M{i}.name = 'null';
M{i}.Gc = zeros(size(MComp{1}.Gc));
else
M{i}.numGparams=size(M{i}.Gc,3);
end;
end;