-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputeProbAdjacency.m
More file actions
68 lines (59 loc) · 2.14 KB
/
computeProbAdjacency.m
File metadata and controls
68 lines (59 loc) · 2.14 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function A = computeProbAdjacency(positions, covariances, varargin)
% COMPUTEPROBADJACENCY Compute an adjacency matrix using the probabilistic
% mass of the cells' covariance ellipses.
%
% Input:
% positions = cell positions
% covariances = cell positional covariances
% prob_ellipse = probabilistic mass for the covariance ellipses
% default = 0.95 (95%)
% sample_points = number of points for estimating covariance ellipses
%
% Output:
% A = adjacency matrix
% What is the probablistic mass for the covariance ellipses?
prob_ellipse = 0.95;
if ~isempty(varargin)
prob_ellipse = varargin{1};
end
% How many points should we use to estimate the covariance ellipses?
sample_points = 1000;
if length(varargin) > 1
sample_points = varargin{2};
end
% Use a stable seed for the random number generator.
rng('default');
rng(1);
% Initialize the data.
A = zeros(size(positions,1)); % adjacency matrix A
points = cell(1,size(A,1)); % points estimating the covariance ellipses
% Generate probabilistic masses for the cells' covariance.
for i = 1:size(A,1)
% Generate the covariance ellipse sampling points randomly.
points{i} = mvnrnd(positions(i,:), covariances(:,:,i), ...
sample_points);
% Sort the ellipsoid distances from the cell's center.
d = pdist2(points{i}, positions(i,:), 'mahalanobis', ...
covariances(:,:,i));
[~,idx] = sort(d, 'ascend');
% Sample points for the probabilistic mass of the cell's covariance.
points{i} = points{i}(idx(1:sample_points * prob_ellipse),:);
end
% Compute the distances between neurons' potential positions.
disp('Computing distances between neurons, please wait patiently ...');
for i = 1:size(A,1)
% Compute the distance from cell's point cloud to its mean.
di = pdist2(points{i}, positions(i,:), 'mahalanobis', ...
covariances(:,:,i));
% Compare cell point clouds, pairwise.
for j = 1:size(A,2)
dj = pdist2(points{i}, positions(j,:), 'mahalanobis', ...
covariances(:,:,j));
if any(dj < di, 1)
A(i,j)=1;
end
end
end
% Restore the random number generator.
rng('shuffle');
end