-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotVisualizer.m
More file actions
10563 lines (8619 loc) · 407 KB
/
plotVisualizer.m
File metadata and controls
10563 lines (8619 loc) · 407 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = plotVisualizer(varargin)
% PLOTVISUALIZER MATLAB code for plotVisualizer.fig
% PLOTVISUALIZER, by itself, creates a new PLOTVISUALIZER or raises
% the existing singleton*.
%
% H = PLOTVISUALIZER returns the handle to a new PLOTVISUALIZER or the
% handle to the existing singleton*.
%
% PLOTVISUALIZER('CALLBACK',hObject,eventData,handles,...) calls the
% local function named CALLBACK in PLOTVISUALIZER.M with the given
% input arguments.
%
% PLOTVISUALIZER('Property','Value',...) creates a new PLOTVISUALIZER
% or raises the existing singleton*. Starting from the left, property
% value pairs are applied to the GUI before plotVisualizer_OpeningFcn
% gets called. An unrecognized property name or invalid value makes
% property application stop. All inputs are passed to
% plotVisualizer_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
%
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @plotVisualizer_OpeningFcn, ...
'gui_OutputFcn', @plotVisualizer_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
end
function plotVisualizer_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
set(hObject,'toolbar','figure');
set(handles.NeighOrRad2,'SelectionChangeFcn',@NeighOrRad2_SelectionChangeFcn);
guidata(hObject, handles);
end
function varargout = plotVisualizer_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
cla;
end
function configureWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('To use dancer data, click this pushbutton once to reformat the data to create plots and graphs and make computations.','"Configure Dance Data" Help','help');
end
function plotDatawithBorderwhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to plot position data. You will have the opportunity to select data to work with, and you can select a preference to plot data with or without distinction between border and interior individuals.','"Plot Data with Border Distinction" Help','help');
end
function saveImage_pushbutton_Callback(hObject, ~, handles)
% saves current figure
fileName = inputdlg('Please enter a name for your figure.');
directoryName = uigetdir('','Please select a folder to save to.');
if directoryName == 0 %User pressed the "Cancel" button
directoryName = ''; %choose the empty string for folder
end
filePath = fullfile(directoryName,fileName{1}); %Create file path
extensions = {'fig'};
for k = 1:length(extensions)
title(fileName,'Interpreter','none')
saveas(gcf,filePath,extensions{k}); %Save the file
set(gcf,'PaperPositionMode','auto');
end
guidata(hObject, handles); %update the handles
end
function savewhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to save the current figure as a .fig file for further MATLAB manipulation. You will be asked to provide a name for the file, as well as a choice for the directory to save it to.','"Save Image" Help','help');
end
function autoPlot_pushbutton_Callback(hObject, ~, handles)
% plots position data in current directory -- making the video of the
% changing graph
data_type = handles.data_type;
lb = handles.lb;
ub = handles.ub;
if data_type ~= 1
inputChoice = str2num(cell2mat(inputdlg('Select from the following two options: 1) Plot with distinction between border and interior individuals 2) Plot without distinction between border and interior individuals')));
end
avi_file_name = cell2mat(inputdlg('Please enter a name for the avi file to be created:'));
aviobj = avifile(avi_file_name,'compression','none','fps',10);
xmin=Inf;
ymin=Inf;
zmin=Inf;
xmax=-Inf;
ymax=-Inf;
zmax=-Inf;
for i=lb:ub
if data_type==1
data=handles.dancedata{i};
xtempmin = min(data(:,1));
if xtempmin < xmin
xmin = xtempmin;
end
ytempmin = min(data(:,2));
if ytempmin < ymin
ymin = ytempmin;
end
xtempmax = max(data(:,1));
if xtempmax > xmax
xmax = xtempmax;
end
ytempmax = max(data(:,2));
if ytempmax > ymax
ymax = ytempmax;
end
else %%% This may need to be changed for other data types!
borderFilename = strcat(num2str(i),'b','.dat');
borderData = load(borderFilename);
interiorFilename = strcat(num2str(i),'i','.dat');
interiorData = load(interiorFilename);
x = [borderData(:,1);interiorData(:,1)];
y = [borderData(:,2);interiorData(:,2)];
z = [borderData(:,3);interiorData(:,3)];
xtempmin = min(x);
if xtempmin < xmin
xmin = xtempmin;
end
ytempmin = min(y);
if ytempmin < ymin
ymin = ytempmin;
end
ztempmin = min(z);
if ztempmin < zmin
zmin = ztempmin;
end
xtempmax = max(x);
if xtempmax > xmax
xmax = xtempmax;
end
ytempmax = max(y);
if ytempmax > ymax
ymax = ytempmax;
end
ztempmax = max(z);
if ztempmax > zmax
zmax = ztempmax;
end
end
end
for i = lb:ub
if data_type == 1
cla;
data=handles.dancedata{i};
x = data(:,1);
y = data(:,2);
axis([xmin xmax ymin ymax]);
grid on;
hold on;
plot(x,y,'g.');
F = getframe(gcf);
aviobj = addframe(aviobj,F);
saveas(gcf,fullfile(strcat('t=',num2str(i))),'fig');
else %%This may need to be changed for other data types!
borderFilename = strcat(num2str(i),'b','.dat');
borderData = load(borderFilename);
dim = size(borderData,2);
axis([xmin xmax ymin ymax zmin zmax]);
grid on;
hold on;
xb = borderData(:,1);
yb = borderData(:,2);
if dim == 3
zb = borderData(:,3);
if inputChoice == 1
plot3(xb,yb,zb,'bx');
drawnow;
else
plot3(xb,yb,zb,'g.');
drawnow;
end
elseif inputChoice == 1
plot(xb,yb,'bx');
drawnow;
else
plot(xb,yb,'g.');
drawnow;
end
interiorFilename = strcat(num2str(i),'i','.dat');
interiorData = load(interiorFilename);
xi = interiorData(:,1);
yi = interiorData(:,2);
if dim == 3
zi = interiorData(:,3);
plot3(xi,yi,zi,'g.');
else plot(xi,y,'g.');
end
drawnow;
F = getframe(gcf);
aviobj = addframe(aviobj,F);
saveas(gcf,fullfile(strcat('t=',num2str(i))),'fig');
cla;
end
end
hold off;
aviobj = close(aviobj);
guidata(hObject, handles);
end
function autoplotwhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on this to plot multiple sets of position data from current directory. All figures will be saved as "t= (i) .fig" files for further MATLAB manipulation. The function will then compile all figures and create a time series animation saved as PlotAnimation.avi.','"Automatic Plot/Movie" Help','help');
end
function nearestNeighborsWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on this to visualize edges on the graph dictated by your input number of nearest neighbors. The function plots the position data. Then, it computes the Euclidean distance between each node and every other node. You will be asked to input your desired number of nearest neighbors, and it will compile a list of the nearest neighbor node pairs, as well as their corresponding distances. You will also have the opportunity to choose from a list of options for assigning edge weight. An Adjacency Matrix will be saved in the current MATLAB directory, named "UnweightedAdjacencyMatrix.mat". Then, MATLAB will plot directed arrows connecting all nearest neighbor node pairs.','"See Nearest Neighbor Edges" Help','help');
end
function distinctionWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on this to visualize the distinction between node connections as being directed (if the sensing only goes in one direction) or undirected (if the sensing goes in both directions). You will be asked to select the data you wish to plot, as well as the number of nearest neighbors you wish to use, and how to weight the edges. The function computes your input number of minimum distances between each node and every other node, and then goes on to figure out whether the node pair appears again in the sensor/sensed pairs, but in the reverse order. If it does, it means that both nodes are sensing each other and the edge is therefore undirected. If the node pair sensing only goes in one direction, then the edge is directed (arrow going from the sensor node to the sensed node).','"Directed and Undirected Edge Distinction" Help','help');
end
function biographNetworkWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on this button to visualize the nearest neighbor edges in a different way. The function will still ask you to select the data sets you would like to use, as well as the number of nearest neighbors, but instead of plotting position data, this will open a new figure in the MATLAB biograph viewer. The position data is therefore not a part of this visualization, but you can more clearly see connections between nodes. Note that it can take a few minutes to produce the biograph object.','"See Network in Separate Figure" Help','help');
end
function eitherorWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on either of these to visualize ONLY the directed edges or ONLY the undirected edges between nodes. You will be asked to select the data sets you wish to plot, the number of nearest neighbors, the edge weight, and the function will go through the same process as in "Directed & Undirected Edge Distinction" to separate the node connections based on whether they are directed or undirected.','"Just Directed" and "Just Undirected" Help','help');
end
function independentGroupsWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click on this button to visualize independent groups within the network of individual agents. A group is independent if the nodes connect to each other in a cyclic fashion, meaning that if the group were to be removed from the network, no other nodes would be affected. You will be asked to select the number of nearest neighbors you wish to visualize, as well as the data you will be working with. The function will plot the position data and each independent cluster in a different color.','"See Independent Groups within Network" Help','help');
end
function sliderMIN_editText_Callback(~, ~, ~)
end
function sliderMIN_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function sliderMAX_editText_Callback(~, ~, ~)
end
function sliderMAX_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function directInputRadiusEdgeWhat_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this button to create graphs with edges based on a user input radius. You will be asked to select data to plot, and you will also be given the opportunity to specify edge weights. The figure will be updated with position data, and then you must type in your desired input radius. Use the buttons in the "Input Radius Toolbox" below. The minimum and maximum edge lengths will appear next to "MIN" and "MAX". Watch the command window for detailed, step by step instructions for this particular visulaization. During the first input radius visualization, the figure will pause construction at various points to allow the user time to view different aspects of the graph. After viewing the graph, you can input new values into the text box, or slide the slider to get new graphs. These visualizations will be more rapid, but you will still see a sphere with the input radius, followed by the edges. Each visualization will feature differently colored edges.','"See Edges from Input Radius" Help','help');
end
function numberStronglyConnectedComponents_editText_Callback(~, ~, ~)
end
function numberStronglyConnectedComponents_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function numberWeaklyConnectedComponents_editText_Callback(~, ~, ~)
end
function numberWeaklyConnectedComponents_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function computeConnectedComponentsWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to compute the numbers of both strongly and weakly connected graph components.','"Compute Connected Components" Help','help');
end
function algebraicConnectivity_editText_Callback(~, ~, ~)
end
function algebraicConnectivity_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function algebraicConnectivityWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to compute the algebraic connectivity of the graph.','"Algebraic Connectivity" Help','help');
end
function speedOfConvergence_editText_Callback(~, ~, ~)
end
function speedOfConvergence_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function speedOfConvergenceWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to calculate the speed of convergence of the consensus of the graph.','"Speed of Convergence" Help','help');
end
function h2Norm_editText_Callback(~, ~, ~)
end
function h2Norm_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function h2NormWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to compute the H2 Norm of the graph.','"H2 Norm" Help','help');
end
function l2gain_editText_Callback(~, ~, ~)
end
function l2gain_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function l2GainWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to compute the L2 Gain of the graph.','"L2 Gain" Help','help');
end
function lowerEigenBound_editText_Callback(~, ~, ~)
end
function lowerEigenBound_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function upperEigenBound_editText_Callback(~, ~, ~)
end
function upperEigenBound_editText_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function eigBoundsWHAT_pushbutton_Callback(~, ~, ~)
msgbox...
('Click this to calculate the lower and upper eigenvalue bounds on the H2 Norm.','"H2 Norm Eigenvalue Bounds" Help','help');
end
function autoPlotandCompute_pushbutton_Callback(hObject, ~, handles)
% automatically creates graph based on user specification and computes and
% prints all graph properties to command window and saves them as matlab
% variables
lb = handles.lb;
ub = handles.ub;
data_type = handles.data_type;
inputEdgeChoice = str2num(get(handles.NeighOrRad2,'UserData'));
inputNewModel = get(handles.NewModel, 'Value');
inputNewModel2 = get(handles.NewModel2, 'Value');
if inputNewModel == 1
inputEdgeChoice = 3;
end
if inputNewModel2 == 1 & inputNewModel==0
inputEdgeChoice = 4;
end
if inputNewModel2 == 1 & inputNewModel == 1
inputEdgeChoice = 5;
end
ProbCheck_Status = get(handles.ProbCheck,'Value');
if inputEdgeChoice == 1
numberOfNeighbors = str2num(get(handles.nuneighbors_editText,'String'));
elseif inputEdgeChoice == 2
inputRadius = str2num(get(handles.inputradius_editText,'String'));
elseif inputEdgeChoice == 3 %if NewModel, need both # of neighbors AND a radius
numberOfNeighbors = str2num(get(handles.nuneighbors_editText,'String'));
inputRadius = str2num(get(handles.inputradius_editText,'String'));
elseif inputEdgeChoice == 4
numberOfNeighbors = str2num(get(handles.nuneighbors_editText,'String')); %these have now a different meaning: # of neighbors to consider, r = radius around nodes
inputRadius = str2num(get(handles.inputradius_editText,'String'));
end
if data_type == 1
viewAngle = str2num(get(handles.viewAngle_editText, 'String'));
if viewAngle < 0 || viewAngle > 360
msgbox('The angle you entered is invalid. Please enter a number between 0 and 360.');
return;
end
else
viewAngle = 360;
end
inputWeightChoice = (get(handles.edges_popup,'Value'));
inputComputeChoice = str2num(cell2mat(inputdlg...
('Please choose whether you would like to plot and/or compute: Select 1) to plot graphs and compute every graph property Select 2) to only plot graphs Select 3) to only compute graph properties')));
if inputComputeChoice < 1 || inputComputeChoice > 3
msgbox('Your selection was invalid. Please select from options 1-3.')
end
avi_file_name = cell2mat(inputdlg('Please enter a name for the avi file to be created:'));
if inputComputeChoice ~= 3
if inputEdgeChoice == 1 | inputEdgeChoice == 3 | inputEdgeChoice ==4 | inputEdgeChoice ==5
inputGraphChoice = str2num(cell2mat(inputdlg...
('Please enter your choice for the type of graphs to be created: Select 1) to plot nearest neighbor edges without directed/undirected distinction Select 2) to plot nearest neighbor edges with distinction between directed and undirected edges Select 3) to only plot nearest neighbor directed edges Select 4) to only plot nearest neighbor undirected edges Select 5) to see independent groups within each network of individuals')));
if inputGraphChoice < 1 || inputGraphChoice > 5
msgbox('Your selection was invalid. Please select from options 1-6.')
end
elseif inputEdgeChoice == 2
inputGraphChoice = str2num(cell2mat(inputdlg...
('Please enter your choice for the type of graphs to be created: Select 1) to plot all edges Select 2) to see independent groups')));
if inputGraphChoice == 2
inputGraphChoice = 5;
end
end
end
%CHECK:
numberPictures = ub-lb;
graphProperties = struct('UWadjacencyMatrix', cell(1,numberPictures),'adjacencyMatrix',cell(1,numberPictures),'stronglyConnected',cell(1,numberPictures),'weaklyConnected',cell(1,numberPictures),'algebraicConnectivity',cell(1,numberPictures),'speedOfConvergence',cell(1,numberPictures),'H2Norm',cell(1,numberPictures),'L2Gain',cell(1,numberPictures),'lowerEBound',cell(1,numberPictures),'upperEBound',cell(1,numberPictures),'status',cell(1,numberPictures),'probabilityMatrix',cell(1,numberPictures));
if inputComputeChoice == 1 || inputComputeChoice == 2
aviobj = avifile(strcat(avi_file_name,'.avi'),'compression','none','fps',10); %fps = 10??!
xmin=Inf;
ymin=Inf;
zmin=Inf;
xmax=-Inf;
ymax=-Inf;
zmax=-Inf;
for i=lb:ub
if data_type==1
file=strcat('Dance',num2str(i),'.dat');
data=handles.dancedata{i};
xtempmin = min(data(:,1));
if xtempmin < xmin
xmin = xtempmin;
end
ytempmin = min(data(:,2));
if ytempmin < ymin
ymin = ytempmin;
end
xtempmax = max(data(:,1));
if xtempmax > xmax
xmax = xtempmax;
end
ytempmax = max(data(:,2));
if ytempmax > ymax
ymax = ytempmax;
end
else
borderFilename = strcat(num2str(i),'b','.dat');
borderData = load(borderFilename);
interiorFilename = strcat(num2str(i),'i','.dat');
interiorData = load(interiorFilename);
x = [borderData(:,1);interiorData(:,1)];
y = [borderData(:,2);interiorData(:,2)];
z = [borderData(:,3);interiorData(:,3)];
xtempmin = min(x);
if xtempmin < xmin
xmin = xtempmin;
end
ytempmin = min(y);
if ytempmin < ymin
ymin = ytempmin;
end
ztempmin = min(z);
if ztempmin < zmin
zmin = ztempmin;
end
xtempmax = max(x);
if xtempmax > xmax
xmax = xtempmax;
end
ytempmax = max(y);
if ytempmax > ymax
ymax = ytempmax;
end
ztempmax = max(z);
if ztempmax > zmax
zmax = ztempmax;
end
end
end
if data_type == 1
lengthScale = min([xmax - xmin, ymax - ymin]);
else
lengthScale = min([xmax - xmin, ymax - ymin, zmax - zmin]);
end
end
%determine number of nodes outside for i=lb:ub loop, for practical reasons
data=handles.dancedata{handles.lb};
x = data(:,1);
numberOfNodes = length(x);
node_status_cum = zeros(1,numberOfNodes);
switch_nodes = zeros(1, numberOfNodes);
neighborNumber = zeros(1, numberOfNodes);
tau1=15; %3 tau's: long/short tau and limit at which neighbor is possible
tau2=50;
tau3=15;
neighbor_data = zeros(numberOfNodes,3,1);
cnt = ones(1, numberOfNodes);
if inputEdgeChoice==1 | inputEdgeChoice==2 | inputEdgeChoice==3
adjacencyMatrix = zeros(ub-lb+1,numberOfNodes, numberOfNodes);
for i = lb:ub
i
%open files, read etc.
cla;
lb = handles.lb;
ub = handles.ub;
file=strcat('Dance',num2str(i),'.dat');
data_type = handles.data_type;
if data_type==1
data=handles.dancedata{i};
set(handles.dataselection_editText,'String',i);
x = data(:,1);
y = data(:,2);
theta = data(:,3);
%[x y theta] = transf_in_familiar_coord(x,y,theta);
dim = 2;
positionMatrix = horzcat(x,y);
else
borderFilename = strcat(num2str(i),'b','.dat');
borderData = load(borderFilename);
dim = size(borderData,2);
interiorFilename = strcat(num2str(i),'i','.dat');
interiorData = load(interiorFilename);
set(handles.dataselection_editText,'String',strcat(borderFilename,' & ',interiorFilename));
x = [borderData(:,1); interiorData(:,1)];
y = [borderData(:,2); interiorData(:,2)];
if dim == 3
z = [borderData(:,3); interiorData(:,3)];
positionMatrix = horzcat(x,y,z);
else positionMatrix = horzcat(x,y);
end
end
numberOfNodes = length(positionMatrix);
distanceMatrix = ipdm(positionMatrix);
relativeAngles = NaN(numberOfNodes);
HeadingDiff = NaN(numberOfNodes);
for s = 1:(numberOfNodes-1);
for j = (s+1):numberOfNodes
relativeAngles(s,j) = atan2(positionMatrix(j,2)-positionMatrix(s,2),positionMatrix(j,1)-positionMatrix(s,1));
relativeAngles(j,s) = anglerestrict(relativeAngles(s,j) + pi);
end
end
for s=1:numberOfNodes
for j=1:numberOfNodes
if distanceMatrix(s,j) == 0
distanceMatrix(s,j) = Inf;
end
HeadingDiff(s,j) = abs(anglerestrict(theta(s)-theta(j)));
end
end
if inputEdgeChoice == 1
% organizedDistanceMatrix = sort(distanceMatrix, 2);
% kminDistances = organizedDistanceMatrix(:,1:numberOfNeighbors);
probabilityMatrix = zeros(numberOfNodes,numberOfNeighbors);
% probabilityMatrix = zeros(numberOfNodes);
br = zeros(numberOfNodes);
for s=1:numberOfNodes; %the beginning of a huge for loop
if viewAngle == 360
distanceRow = distanceMatrix(s,:);
organizedDistanceRow = sort(distanceRow);
[sortedDist, sortedNodes] = sort(distanceRow);
visibleNodes = 1:numberOfNodes;
keep = ismember(sortedNodes, visibleNodes);
index = keep == 0;
visible_sorted = sortedNodes;
visible_sorted(index) = [];
minimumRow = organizedDistanceRow(1:numberOfNeighbors);
adjacencyRow = ismember(distanceRow,minimumRow);
adjacencyMatrix(i,s,:) = adjacencyRow;
else
viewMin = anglerestrict(theta(s) - pi*viewAngle/360);
viewMax = anglerestrict(theta(s) + pi*viewAngle/360);
if viewMin < viewMax
visibleNodes = find((relativeAngles(s,:) <= viewMax) & (relativeAngles(s,:) >= viewMin));
else
visibleNodes = find((relativeAngles(s,:) <= viewMax) | (relativeAngles(s,:) >= viewMin));
end
if length(visibleNodes) < numberOfNeighbors
angles = relativeAngles(s,[1:(s-1) (s+1):numberOfNodes]);
sortedAngles = sort(angles);
viewAngleRequired = zeros(1,numberOfNodes-1);
for ii = 1:(numberOfNodes-1)
if ii <= numberOfNodes - numberOfNeighbors
viewAngleRequired(ii) = sortedAngles(ii+numberOfNeighbors-1) - sortedAngles(ii);
else
viewAngleRequired(ii) = anglerestrict(sortedAngles(ii+numberOfNeighbors-numberOfNodes) - sortedAngles(ii));
end
end
%number of neighbors goes down until a possible viewing
%angle is found for tempNumberofNeighbors; heading
%could be ignored! -all that matters is diff in angle!
tempNumberOfNeighbors = numberOfNeighbors;
while min(viewAngleRequired) > pi*viewAngle/180
tempNumberOfNeighbors = tempNumberOfNeighbors - 1;
viewAngleRequired = zeros(1,numberOfNodes-1);
for ii = 1:(numberOfNodes-1)
if ii <= numberOfNodes - tempNumberOfNeighbors
viewAngleRequired(ii) = sortedAngles(ii+tempNumberOfNeighbors-1) - sortedAngles(ii);
else
viewAngleRequired(ii) = anglerestrict(sortedAngles(ii+tempNumberOfNeighbors-numberOfNodes) - sortedAngles(ii));
end
end
end
distanceRow = distanceMatrix(s,:);
[mindist closestnode] = min(distanceRow);
direction = 2*(relativeAngles(s,closestnode) > 0) - 1;
if direction > 0
startloc = find(sortedAngles > viewMin,1);
if isempty(startloc)
startloc = 1;
end
else
startloc = find(sortedAngles > viewMax,1) - tempNumberOfNeighbors;
if isempty(startloc)
startloc = numberOfNodes - 1 - tempNumberOfNeighbors;
end
if startloc < 1
startloc = startloc + numberOfNodes - 1;
end
end
neededViewAngle = pi*viewAngle/180;
currentViewAngle = neededViewAngle + 1;
stepnum = 0;
while currentViewAngle > neededViewAngle
if mod(stepnum,2) ~= 0
location = startloc + direction*(stepnum+1)/2;
else
location = startloc - direction*stepnum/2;
end
if location < 1
location = location + numberOfNodes - 1;
end
if location >= numberOfNodes
location = location - numberOfNodes + 1;
end
currentViewAngle = viewAngleRequired(location);
stepnum = stepnum + 1;
end
if location <= (numberOfNodes - tempNumberOfNeighbors)
anglesOfVisibleNodes = sortedAngles(location:(location + tempNumberOfNeighbors - 1));
else
anglesOfVisibleNodes = sortedAngles([location:(numberOfNodes-1) 1:(location + tempNumberOfNeighbors - numberOfNodes)]);
end
visibleLogic = ismember(relativeAngles(s,:),anglesOfVisibleNodes);
visibleNodes = find(visibleLogic == 1);
end
distanceRow = distanceMatrix(s,:);
organizedDistances = sort(distanceRow(visibleNodes));
[sortedDist, sortedNodes] = sort(distanceRow);
keep = ismember(sortedNodes, visibleNodes);
index = keep == 0;
visible_sorted = sortedNodes;
visible_sorted(index) = [];
if length(visibleNodes) < numberOfNeighbors
minimumRow = organizedDistances;
else
minimumRow = organizedDistances(1:numberOfNeighbors);
end
end
h=1;
% PROBABILITY SWITCH %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (ProbCheck_Status)
m = str2num(get(handles.Increment,'String'));
mm = str2num(get(handles.Increment2,'String'));
L = str2num(get(handles.max_prob,'String'));
if i == lb
adjacencyRow = ismember(distanceRow,minimumRow);
neighbors = find(adjacencyRow == 1);
probabilityMatrix(s,:)= zeros(1,numberOfNeighbors);
else
if s==h
disp('frame and node')
i
s
end
probabilityMatrix = graphProperties(i-1).probabilityMatrix;
old_neighbors = graphProperties(i-1).neighbors(s,:); % node neighbors at previous frame
old_neighbors2 = old_neighbors;
closest = ismember(distanceRow,minimumRow);
num_closest = find(closest==1); % closest neighbors in view angle
potential_new = num_closest;
%{
if s==h
disp('FIRST old neighbors')
old_neighbors
disp('potential_new2_first')
potential_new
end
%}
for j = 1:numberOfNeighbors
if (ismember(old_neighbors(1,j),num_closest)) % if was neighbor and still closest in view
probabilityMatrix(s,j) = 0;
elseif ismember(old_neighbors(1,j),num_closest) == 0 % if was neighbor, still in view but not closest(2)
if probabilityMatrix(s,j) < (L - m) % increase pswitch towards saturation (possibly have this increase fasterthan case above)
probabilityMatrix(s,j) = probabilityMatrix(s,j) + m;
else
probabilityMatrix(s,j)= L;
end
end
if probabilityMatrix(s,j) > 0
change(s,j) = binornd(1,probabilityMatrix(s,j));
else
change(s,j) = 0;
end
end
num_changes = sum(change(s,:));
% if length(visibleNodes) == numberOfNeighbors
% neighbors = visibleNodes;
if num_changes == 0
neighbors = old_neighbors;
else
potential_new = visible_sorted;
for j = 1:numberOfNeighbors
if (ismember(old_neighbors(1,j),potential_new))
potential_new(potential_new == old_neighbors(1,j)) = [];
end
end
if length(potential_new) <= num_changes
for j = 1:numberOfNeighbors
if (change(s,j))
neighbors(1,j) = potential_new(1);
potential_new(potential_new == neighbors(1,j)) = [];
probabilityMatrix(s,j) = 0; %reset probability switch
else
neighbors(1,j) = old_neighbors(1,j);
end
end
elseif length(potential_new)> num_changes
for j = 1:numberOfNeighbors
if (change(s,j))
if numel(potential_new) == 0 %debug!
stop = 1;
end
neighbors(1,j) = potential_new(1);
potential_new(potential_new == neighbors(1,j)) = [];
probabilityMatrix(s,j) = 0; %reset probability switch
else
neighbors(1,j) = old_neighbors(1,j);
end
end
else
error = 1;
end
end
adjacencyRow = zeros(1,numberOfNodes);
adjacencyRow(1,neighbors) = 1;
end
else
adjacencyRow = ismember(distanceRow,minimumRow);
neighbors = find(adjacencyRow == 1);
end
adjacencyMatrix(i,s,:) = adjacencyRow;
graphProperties(i).probabilityMatrix(s,:) = probabilityMatrix(s,:);
graphProperties(i).neighbors(s,:) = neighbors;
if i==lb
neighborNumber(s) = neighborNumber(s)+1;
Invneighbors(s, neighborNumber(s),:)=neighbors;
fr_neigh(s, neighborNumber(s))=1;
else
if sum(neighbors==graphProperties(i-1).neighbors(s,:))~=numberOfNeighbors %this remembers the neighbors and how many
neighborNumber(s) = neighborNumber(s)+1
Invneighbors(s, neighborNumber(s),:)=neighbors
fr_neigh(s, neighborNumber(s)) = 1
else
fr_neigh(s, neighborNumber(s)) = fr_neigh(s, neighborNumber(s))+1;
end
end
end
graphProperties(i).UWadjacencyMatrix = squeeze(adjacencyMatrix(i,:,:)); %%unweighted!!!
if ProbCheck_Status & i~=lb
clear neighbors
clear change
end
if adjacencyRow(s) ~= 0
disp(' ')
disp('Problem: edge connecting a node to itself')
disp('-----------------------------------------')
disp(['Frame: ' num2str(i)])
disp(['Node: ' num2str(s)])
distanceRow
viewMin
viewMax
theta
relativeAngles(s,:)
if viewMin < viewMax
find((relativeAngles(s,:) <= viewMax) & (relativeAngles(s,:) >= viewMin))
else
find((relativeAngles(s,:) <= viewMax) | (relativeAngles(s,:) >= viewMin))
end
visibleNodes
adjacencyRow
pause
end
Ndist(i,s,:) = distanceMatrix(s, find(adjacencyMatrix(i,s,:)==1)); %store in N distances to neighbors. i=frame, o=node, :=dist to neighbors
Ndist = sort(Ndist,3);
handles.adjacencyMatrix = adjacencyMatrix;
elseif inputEdgeChoice == 2
adjacencyMatrix = zeros(numberOfNodes);
for o=1:numberOfNodes
for j=1:numberOfNodes
if viewAngle == 360
if distanceMatrix(o,j) < inputRadius
adjacencyMatrix(o,j) = 1;
end
else
viewMin = anglerestrict(theta(o) - pi*viewAngle/360);
viewMax = anglerestrict(theta(o) + pi*viewAngle/360);
if viewMin < viewMax
visible = (relativeAngles(o,j) <= viewMax) & (relativeAngles(o,j) >= viewMin);
else
visible = (relativeAngles(o,j) <= viewMax) | (relativeAngles(o,j) >= viewMin);
end
if visible && distanceMatrix(o,j) < inputRadius
adjacencyMatrix(o,j) = 1;
end
end
end
Ndist(i,o,:) = distanceMatrix(o, find(adjacencyMatrix(o,:)==1)); %store in N distances to neighbors. i=frame, o=node, :=dist to neighbors
Ndist = sort(Ndist,3);
end
elseif inputEdgeChoice==3 %NewModel stuff!!!
for o=1:numberOfNodes
if viewAngle == 360
distanceRow = distanceMatrix(o,:);
organizedDistanceRow = sort(distanceRow);
minimumRow = organizedDistanceRow(1:numberOfNeighbors);
adjacencyRow = ismember(distanceRow,minimumRow);
adjacencyMatrix(i,o,:) = adjacencyRow;
potential_neighbors = find(adjacencyRow==1);
else
viewMin = anglerestrict(theta(o) - pi*viewAngle/360);
viewMax = anglerestrict(theta(o) + pi*viewAngle/360);
if viewMin < viewMax
visible = find(relativeAngles(o,:) <= viewMax & relativeAngles(o,:) >= viewMin);
else
visible = find(relativeAngles(o,:) <= viewMax | relativeAngles(o,:) >= viewMin);
end
for j=1:size(visible,2)
if distanceMatrix(o,visible(j)) < inputRadius
adjacencyMatrix(i,o,visible(j)) = 1;
end
end
end
visible = find(adjacencyMatrix(i,o,:)==1);
%{
if o==8
o
find(adjacencyMatrix(o,:)==1)
end
%}
if sum(adjacencyMatrix(i,o,:)) > numberOfNeighbors
ind_radii = find(adjacencyMatrix(i,o,:)==1);
distanceMatrix_withinangle = distanceMatrix(o,ind_radii);
distanceMatrix_withinangle_sorted = sort(distanceMatrix_withinangle);
Reduced_distMatrix_withinangle = ...
distanceMatrix_withinangle_sorted(1:numberOfNeighbors);
g=0;
neigh = [];
for f = 1:numberOfNodes
if adjacencyMatrix(i,o,f)==1 & ismember(distanceMatrix(o,f), Reduced_distMatrix_withinangle)
neigh(g+1) = f;
g=g+1;
end
end
potential_neighbors=neigh;
%{
if o==8
distanceMatrix_withinangle
distanceMatrix_withinangle_sorted
Reduced_distMatrix_withinangle
end
%}
elseif sum(adjacencyMatrix(i,o,:)) < numberOfNeighbors
neighbors_left = numberOfNeighbors - sum(adjacencyMatrix(i,o,:));
ind2 = find(adjacencyMatrix(i,o,:)==0);
[distanceMatrix_sorted, ind_dM_sorted] = sort(distanceMatrix(o,:));
j=0;
k=1;
ind_dM_sorted2 = zeros(1, neighbors_left);
while j < neighbors_left
if ismember(ind_dM_sorted(k), ind2)
ind_dM_sorted2(j+1) = ind_dM_sorted(k);
j=j+1;
end
k=k+1;
end
potential_neighbors = [visible, ind_dM_sorted2];
%{
if o==8
neighbors_left
ind2
distanceMatrix_sorted
ind_dM_sorted
ind_dM_sorted2
adjacencyMatrix(o,:)
end
%}
else
potential_neighbors = visible;
end