-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimizeGateSearch.m
More file actions
46 lines (31 loc) · 1.02 KB
/
optimizeGateSearch.m
File metadata and controls
46 lines (31 loc) · 1.02 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
function optimizeGateSearch(subSampleCode, runCode)
nSplits = 64;
rng('shuffle');
% Get initial conditions
Go = gateFromRandomSnip(subSampleCode, initialGate);
[x0,lb,ub] = gateToList(Go);
load(['~/derived/subSample-',subSampleCode,'.mat']);
% Define an objective function to use
objFunc = @(x) evalGate(listToGate(x, Go), procTracks, sampleIX, nSplits);
options = optimset('Display','iter','FunValCheck','off',...
'TolFun',10^-5,'TolX',10^-3,...
'MaxFunEvals', 500,...
'OutputFcn', @outFcn);
[x, fval, exitflag, output] = fminsearch(objFunc, x0, options);
% Save the data...
fileName = ['~/gateLearn/FitGates-',runCode,'.mat'];
a = dir(fileName);
if length(a) > 0
load(fileName);
else
gateVectors = [];
fVals = [];
gTemplates = [];
end
gateVectors = cat(1,gateVectors,x(:)');
fVals = cat(1,fVals,fval);
gTemplates = cat(1,gTemplates,Go);
save(fileName,'gateVectors','fVals','runCode','gTemplates');
function stop = outFcn(x, optimValues, state)
stop = false;
disp(x(:)');