-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractDynNN.m
109 lines (82 loc) · 4.1 KB
/
extractDynNN.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
86
87
88
89
90
91
92
93
94
95
96
97
98
function outNNdistances = extractDynNN(PARAMS,popSource,popTarget,popPermut,RSpairs)
% For one R and S pair calculate the NN distances between source population
% and the target population. For the moment, the tpSource == tptarget is
% excluded to avoid picking into the same population
%{
INPUT
PARAMs - See pointDynPatternMain
popSource - table containing 3D position of the source population
popTarget - table containing 3D position of the target population
popPermut - IF you want to simulate a model, then this variable has to be a
table containing 3D position of the permutation population. IF this
variable is empty then no simulation will be made
OUTPUT
NNdistances - list of NxM distances with:
- N = 1 if experimental populations or the number of simulations to
effectuate (nPerms).
- M = the number of lines in popSource
%}
switch nargin
case 3
if PARAMS.verbose > 1
fprintf('Calculating NN for experimental data\n');
end
doSimulation = false;
case 5 % additional info for RSpairs and popPermut
if PARAMS.verbose > 1
fprintf('Calculating NN for simulated data\n');
end
doSimulation = true;
otherwise
msg = fprintf('Error: Unrecognised number of parameters in extractDynNN function.\n');
error(msg)
end
% for every source temporal step => tpSource
for tpSource = PARAMS.movie.minTp:PARAMS.movie.maxTp-1
% For the moment, discard the situation where tpSource = tpTarget
shortSource = [popSource.PositionX(popSource.Time==tpSource, :),...
popSource.PositionY(popSource.Time==tpSource, :),...
popSource.PositionZ(popSource.Time==tpSource, :)];
% for every target temporal step => tpTarget
for tpTarget = tpSource+1:PARAMS.movie.maxTp
% Change for tpTarget = tpSource:PARAMS.movie.maxTp if same tp authorized
% Create a field name for data output
tpField = sprintf('dt%d_to_dt%d',tpSource,tpTarget);
% If simulation
if doSimulation
% Put both effect parameters into an independant variable
effect.Range = PARAMS.anaMap.RSpairs.Rs(RSpairs);
effect.Strength = PARAMS.anaMap.RSpairs.Ss(RSpairs);
simulatedObjects = simulateDynDispersion(PARAMS,popSource(popSource.Time==tpSource, :),...
popTarget(popTarget.Time==tpTarget, :),...
popPermut(popPermut.Time==tpTarget, :),effect); % List of positions
% function [dnSimu, Grand] = simulateSpatialDisp(effect, NNExp,
% pops, rowPermut, nTarget, PARAMS) => static version
allNNsimuDist = zeros(PARAMS.anaGlobal.numPermut,size(shortSource,1));
for permN = 1:PARAMS.anaGlobal.numPermut
shortTarget = [popPermut.PositionX(sum(popPermut.ID==simulatedObjects(permN,:),2,'native'),:),...
popPermut.PositionY(sum(popPermut.ID==simulatedObjects(permN,:),2,'native'),:),...
popPermut.PositionZ(sum(popPermut.ID==simulatedObjects(permN,:),2,'native'),:)];
[~,fooNNdist] = knnsearch(shortTarget, shortSource, 'K', 1);
allNNsimuDist(permN,:) = fooNNdist; % NN distances for this set of positions
end
outNNdistances.(tpField) = allNNsimuDist';
else % if using the experimental population
shortTarget = [popTarget.PositionX(popTarget.Time==tpTarget),...
popTarget.PositionY(popTarget.Time==tpTarget),...
popTarget.PositionZ(popTarget.Time==tpTarget)];
if tpSource == tpTarget %
[~,fooNNdist] = knnsearch(shortTarget, shortSource, 'K', 2);
fooNNdist = fooNNdist(:,2); % first column is identical position...
else
[~,fooNNdist] = knnsearch(shortTarget, shortSource, 'K', 1);
end
outNNdistances.(tpField) = fooNNdist;
end % end measurement
clear foo*
end % end tpTarget
end % end tpSource
%
end
%%%%%%%%%%% ADDITIONNAL FUNCTIONS %%%%%%%%%%%
% function