Skip to content

Commit fda02cf

Browse files
authored
Merge pull request #263 from sampsapursiainen/add-common-inverse-parameters-class
Add common inverse parameters class
2 parents d1821a3 + 556636a commit fda02cf

File tree

96 files changed

+8649
-891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+8649
-891
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
classdef BeamformerInverter < inverse.CommonInverseParameters & handle
2+
3+
%
4+
% BeamformerInverter
5+
%
6+
% A class which defines the properties needed for different types of
7+
% beamforming, and the method itself.
8+
%
9+
10+
properties
11+
12+
%
13+
%The inverse algorithm used. The options are currently:
14+
% - Linearly constrained minimum variance (LCMV) beamformer
15+
% - Unit noise gain (UNG) beamformer
16+
% - Unit-gain constrained beamformer
17+
% The last option is essentially UNG but beamformer-optimal, i.e.,
18+
% maximal-signal-producing orientation is calculated first.
19+
%
20+
method_type (1,1) string { mustBeMember(method_type, ["Linearly constrained minimum variance (LCMV) beamformer", "Unit noise gain (UNG) beamformer", "Unit-gain constrained beamformer"]) } = "Linearly constrained minimum variance (LCMV) beamformer"
21+
22+
%
23+
%The error covariance regularization parameter
24+
%
25+
cov_reg_parameter (1,1) double {mustBeNonnegative} = 0.05
26+
27+
%
28+
%The lead field regularization parameter
29+
%
30+
leadfield_reg_parameter (1,1) double {mustBeNonnegative} = 0.001
31+
32+
%
33+
%The leadfield regularization procedure
34+
%
35+
leadfield_reg_type (1,1) string { mustBeMember(leadfield_reg_type, ["Basic", "Pseudoinverse"]) } = "Basic"
36+
37+
%
38+
%Lead field normalization strategy
39+
%
40+
leadfield_normalization (1,1) string { mustBeMember(leadfield_normalization, ["None", "Matrix norm", "Column norm", "Row norm"]) } = "None"
41+
42+
%
43+
% Property to check if user has changed the error covariance by
44+
% hand
45+
%
46+
error_covSetted (1,1) {mustBeNumericOrLogical} = false
47+
48+
%
49+
% Support variable to ensure that only user changed of error_cov
50+
% causes action.
51+
%
52+
computing_parameters (1,1) {mustBeNumericOrLogical} = false
53+
54+
end % properties
55+
properties (SetObservable)
56+
57+
%
58+
%The data error covariance matrix (optional)
59+
%
60+
error_cov = []
61+
62+
end %SetObservable properties
63+
64+
methods
65+
66+
function self = BeamformerInverter(args)
67+
68+
%
69+
% BeamformerInverter
70+
%
71+
% The constructor for this class.
72+
%
73+
arguments
74+
75+
args.method_type = "Linearly constrained minimum variance (LCMV) beamformer"
76+
77+
args.cov_reg_parameter = 0.05
78+
79+
args.leadfield_reg_parameter = 0.001
80+
81+
args.reg_type = "Basic"
82+
83+
args.error_cov = []
84+
85+
args.error_covSetted = false
86+
87+
args.computing_parameters = false
88+
89+
args.leadfield_normalization = "None"
90+
91+
args.data_normalization_method = "Maximum entry"
92+
93+
args.high_cut_frequency = 9
94+
95+
args.low_cut_frequency = 7
96+
97+
args.number_of_frames = 1
98+
99+
args.sampling_frequency = 1024
100+
101+
args.time_start = 0
102+
103+
args.time_window = 0
104+
105+
args.time_step = 1
106+
107+
end
108+
109+
% Initialize superclass fields.
110+
111+
self = [email protected]( ...
112+
"low_cut_frequency" ,args.low_cut_frequency, ...
113+
"high_cut_frequency", args.high_cut_frequency, ...
114+
"data_normalization_method", args.data_normalization_method, ...
115+
"number_of_frames", args.number_of_frames, ...
116+
"sampling_frequency", args.sampling_frequency, ...
117+
"time_start", args.time_start, ...
118+
"time_window", args.time_window, ...
119+
"time_step", args.time_step ...
120+
);
121+
122+
% Initialize own fields.
123+
124+
self.method_type = args.method_type;
125+
126+
self.leadfield_reg_type = args.reg_type;
127+
128+
self.cov_reg_parameter = args.cov_reg_parameter;
129+
130+
self.leadfield_reg_parameter = args.leadfield_reg_parameter;
131+
132+
self.leadfield_normalization = args.leadfield_normalization;
133+
134+
self.error_cov = args.error_cov;
135+
136+
self.error_covSetted = args.error_covSetted;
137+
138+
self.computing_parameters = args.computing_parameters;
139+
140+
%Set listener for error_cov
141+
addlistener(self,'error_cov','PostSet',@(src,evnt)self.setEventsFlags(src,evnt,self));
142+
143+
end
144+
145+
% Declare the initialize and inverse method defined in the files invert and initialize in this same
146+
% folder.
147+
148+
self = initialize(self)
149+
150+
[reconstruction, self] = invert(self, f, L, procFile, source_direction_mode)
151+
152+
% Function that ZI runs after all inversions are done for each
153+
% desired time steps. With this function, one can reset the
154+
% variables and properties that has been changed during the
155+
% computing process
156+
157+
function self = terminateComputation(self)
158+
%If the user has not given their own inversion parameters, we
159+
%reset the automatically computed parameters because the user
160+
%could change the data or model between separate runs.
161+
if not(self.error_covSetted)
162+
self.error_cov = [];
163+
end
164+
end
165+
166+
end % methods
167+
168+
methods (Static)
169+
%The function that is woken by listener when the value of theta or
170+
%noise_cov is changed to something else than empty by hand.
171+
% The function set the respective *Setted property value true when
172+
% value is changed.
173+
function setEventsFlags(src,evnt,self) %two first inputs must be there and have these dedicated roles. The third 'self' is an extra variable.
174+
if not(self.computing_parameters)
175+
if isempty(self.error_cov)
176+
self.error_covSetted = false;
177+
else
178+
self.error_covSetted = true;
179+
end
180+
end
181+
end % function
182+
end % static methods
183+
184+
end % classdef
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function self = initialize(self,L,f_data)
2+
%
3+
% initialization function
4+
%
5+
% Initialize recursively updated variables before the computation of
6+
% the first time step.
7+
%
8+
% Inputs:
9+
%
10+
% - self
11+
%
12+
% An instance of BeamformerInverter with the method-specific parameters.
13+
%
14+
% Outputs:
15+
%
16+
% - self
17+
%
18+
% Recursive variables initialized
19+
%
20+
21+
arguments
22+
23+
self (1,1) inverse.BeamformerInverter
24+
25+
L (:,:) {mustBeA(L,["double","gpuArray"])}
26+
27+
f_data (:,:) {mustBeA(f_data,["double","gpuArray"])}
28+
29+
end
30+
self.computing_parameters = true;
31+
% Compute error covariance matrix if it is not given
32+
if isempty(self.error_cov)
33+
if size(f_data,2) > 1
34+
self.error_cov = (f_data-mean(f_data,2))*(f_data-mean(f_data,2))'/size(f_data,2);
35+
else
36+
self.error_cov = (f_data-mean(f_data,1))*(f_data-mean(f_data,1))';
37+
end
38+
end
39+
40+
end

0 commit comments

Comments
 (0)