-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimizeChunks.m
85 lines (61 loc) · 2.47 KB
/
optimizeChunks.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
function [bestx, bestf] = optimizeChunks(tiepts, chunkStart, chunkEnd)
% Winnow chunk points table to only include the specified range
chunks = chunkStart:chunkEnd;
tiepts(~ismember(tiepts.chunk, chunks), :) = [];
% Calculate a time range and number of chunks in which each point appears
upoints = unique(tiepts.point);
timeRange = zeros(size(upoints));
pointFreq = zeros(size(upoints));
for i = 1:numel(upoints)
timeRange(i) = range(tiepts.flightTime(tiepts.point==upoints(i)));
pointFreq(i) = numel(unique(tiepts.chunk(tiepts.point==upoints(i))));
end
clear i
% Eliminate all points appearing in only one chunk
idx = pointFreq < 2;
tiepts(ismember(tiepts.point, upoints(idx)), :) = [];
upoints(idx) = [];
timeRange(idx) = [];
pointFreq(idx) = [];
% For each chunk, select (up to) five points with the greatest time range
selection = false(size(upoints));
[~, iTime] = sort(timeRange, 'descend');
upoints = upoints(iTime);
pointFreq = pointFreq(iTime);
for i = 1:numel(chunks)
chunkidx = tiepts.chunk == chunks(i);
pointidx = find(ismember(upoints, tiepts.point(chunkidx)));
for j = 1:min([numel(pointidx) 30])
selection(pointidx(j)) = true;
end
end
clear iTime i frameidx pointidx j
% Create a table containing only high points
hiPoints = upoints(selection);
highpts = tiepts(ismember(tiepts.point, hiPoints), :);
clear i dataFile data idx datapts
% Prepare objective function to be passed to SCEUA
idxchunk = false(size(highpts,1), numel(chunks));
idxpoint = false(size(highpts,1), numel(hiPoints));
hiPtFreq = pointFreq(selection);
for j = 1:numel(chunks)
idxchunk(:,j) = highpts.chunk == chunks(j); end
for j = 1:numel(hiPoints)
idxpoint(:,j) = highpts.point == hiPoints(j); end
functn = @(nopt, b)sceuaObjective(highpts.rawIntensity, ...
idxpoint, idxchunk, hiPtFreq, nopt, b);
clear j idximage idxpoint
% Set up and run shuffled complex algorithm
x0 = [ones(1, numel(chunks)) zeros(1, numel(chunks))];
lb = [1 0.8*ones(1, numel(chunks)-1) 0 -6000*ones(1, numel(chunks)-1)];
ub = [ 1.2*ones(1, numel(chunks)) 6000*ones(1, numel(chunks))];
ngs = 4;
maxn = 5e5;
kstop = 20;
pcento = 0.01;
peps = 1e-3;
iseed = 1;
iniflg = 1;
[bestx, bestf] = sceua(x0, lb, ub, maxn, kstop, pcento, peps, ngs, ...
iseed, iniflg, functn);
end