-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclustering interactions_sample code.R
77 lines (30 loc) · 1.98 KB
/
clustering interactions_sample code.R
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
# Main code which connects Python and R:
path_to_save = "your_path"
filename_to_save = "s7s8_A_feature_duration_df.csv"
adult_df = s7s8_A
juvenile_df = s7s8_BA
# Need to create joined_df and seq_indices only to be able to retrieve conversation type labels from python.
# To encode juvenile_df and adult_df it is enough to run PipelineCreateBirdFeatureDF
joined_df = MakeJoinedDF(juvenile_df, adult_df)
seq_indices =GetSubsequentIndices(joined_df, 0.5)
PipelineCreateBirdFeatureDF(juvenile_df, adult_df, 0.5, 20, path_to_save, filename_to_save, rank = "no")
# Now we need to retrieve labels. For this we create interaction_df: it is usual joined_df, but with several distinctions:
# It consists only from elements participating in interactions ( = from seq_indices), and with added interaction label (counter)
interaction_file_name = "interaction_type_labels_s7s8_BA.csv"
interaction_path = "C:/cmatlab-Roman/DivPrograms/Individual/RomanDoronin/Data/s7s8/feature_dataframes/"
interaction_df = CreateInteractionDF(joined_df, seq_indices)
interaction_df = AddInteractionTypes(interaction_df, interaction_path, interaction_file_name) # assigns label of type of interaction to each element in df
interaction_cluster = 17
CreateInteractionPerchStackPlot(interaction_df, chosen_interaction_types = c(interaction_cluster))+facet_wrap(~day, scale = "free")#+xlim(0.5, 1)
library(ggplot2)
# Auxillary code to check the ordered sequence of interspike intervals (and then also intervals between offset and next onset)
juvenile_df = s7s8_BA
adult_df = s7s8_A
joined_df = arrange(rbind(juvenile_df, adult_df), .by_group = list(day, time_h))
isi = diff(joined_df$time_h)
isi = sort(isi[which(isi > 0)]) * 3600
ggplot()+geom_line(aes(1:length(isi), isi))+ylim(0,0.5)
n = nrow(joined_df)
isi_dur = joined_df$time_h[2:n] * 3600 - joined_df$time_h[1:n-1] * 3600 - joined_df$duration[1:n-1]
isi_dur = sort(isi_dur[which(isi_dur > 0)])
ggplot()+geom_line(aes(1:length(isi_dur), isi_dur))+ylim(0,1)