Skip to content

Commit

Permalink
Updates figures from chapter 4 and 5
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloabur committed Feb 5, 2024
1 parent 7ca3294 commit 73c1a32
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 50 deletions.
14 changes: 10 additions & 4 deletions plots/balance_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ plot_weights <- function(df_data, bins, bin_width, subset=NULL){
w_distribution <- df_weights %>%
ggplot(aes(x=mids, y=count)) +
geom_col(width=bin_width, fill=color_map[2], color=color_map[2]) +
theme_bw() + labs(x='weights (pA)', y='fraction of synapses')
theme_bw() + labs(x='weights (pA)', y='fraction of synapses') +
theme(text=element_text(size=16))

return(w_distribution)
}
Expand All @@ -110,8 +111,10 @@ protocols <- map_int(metadata, \(x) x$protocol)
prot_id <- match(1, protocols)
event_data <- read.csv(file.path(data_path[prot_id], 'events_spikes.csv'))
fetches <- event_data %>%
mutate(time_ms = time_ms/1000) %>%
ggplot(aes(x=time_ms, y=num_events)) + geom_line() +
theme_bw() + labs(x='time (ms)', y='# Active neurons')
theme_bw() + labs(x='time (s)', y='# active neurons') +
theme(text=element_text(size=16))

w_distribution <- plot_weights(data_path[prot_id], bins=19, bin_width=0.64)
incoming_w_j0 <- plot_weights(data_path[prot_id], bins=19, bin_width=0.64, 0)
Expand All @@ -137,8 +140,10 @@ if(metadata[[prot_id[1]]]$alpha==.1449) {
event_data <- read.csv(file.path(data_path[prot_id], 'events_spikes.csv'))
fetches <- event_data %>%
filter(time_ms < 195000) %>%
mutate(time_ms = time_ms/1000) %>%
ggplot(aes(x=time_ms, y=num_events)) + geom_line() +
theme_bw() + labs(x='time (ms)', y='# Active neurons')
theme_bw() + labs(x='time (s)', y='# active neurons') +
theme(text=element_text(size=16))

w_distribution <- plot_weights(data_path[prot_id], bins=35, bin_width=.7)
w_distribution <- w_distribution +
Expand All @@ -160,7 +165,8 @@ df_rates_init$group <- 'initial'
freq <- bind_rows(df_rates_init, df_rates_final) %>%
ggplot(aes(x=rate, color=group, fill=group)) + theme_bw() +
geom_histogram(alpha=.5) + scale_color_manual(values=color_map) +
scale_fill_manual(values=color_map) + theme(legend.position = c(0.8, 0.8)) +
scale_fill_manual(values=color_map) +
theme(legend.position = c(0.8, 0.8), text=element_text(size=16)) +
labs(x='firing rates (Hz)', y='count', fill=element_blank(), color=element_blank()) +
scale_y_log10()

Expand Down
21 changes: 12 additions & 9 deletions plots/conditions_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,45 @@ t_final <- 250
fetch_dist_init <- df_events %>%
filter(time_ms > t_init & time_ms < t_final) %>%
ggplot(aes(x=group, y=num_fetch, fill=group)) +
geom_boxplot(outlier.shape=NA) + theme_bw() + theme(legend.position="none") +
geom_boxplot(outlier.shape=NA) + theme_bw() +
theme(legend.position="none", text = element_text(size=16)) +
geom_jitter(color="black", size=0.7, alpha=0.5) +
labs(x=element_blank(), y='# Memory access') +
labs(x=element_blank(), y='mems') +
scale_fill_manual(values=color_map)
t_init <- 0
t_final <- 100
trace_init <- df_events %>%
filter(time_ms > t_init & time_ms < t_final) %>%
ggplot(aes(x=time_ms, y=num_fetch, color=group)) + geom_line() +
theme(legend.position="none") + theme_bw() +
theme_bw() + theme(legend.position="none", text = element_text(size=16)) +
guides(color=guide_legend(override.aes=list(linewidth=4))) +
labs(x='time (ms)', y='# Memory access', color='Event threshold') +
labs(x='time (ms)', y='mems', color='Event threshold') +
scale_color_manual(values=color_map)

t_init <- 99500
t_final <- 99750
fetch_dist_final <- df_events %>%
filter(time_ms > t_init & time_ms < t_final) %>%
ggplot(aes(x=group, y=num_fetch, fill=group)) +
geom_boxplot(outlier.shape=NA) + theme_bw() + theme(legend.position="none") +
geom_boxplot(outlier.shape=NA) + theme_bw() +
theme(legend.position="none", text = element_text(size=16)) +
geom_jitter(color="black", size=0.7, alpha=0.5) +
labs(x=element_blank(), y='# Memory access') +
labs(x=element_blank(), y='mems') +
scale_fill_manual(values=color_map)
t_init <- 99500
t_final <- 100000
trace_final <- df_events %>%
filter(time_ms > t_init & time_ms < t_final) %>%
ggplot(aes(x=time_ms, y=num_fetch, color=group)) + geom_line() +
theme_bw() + labs(x='time (ms)', y='# Memory access') +
theme_bw() + labs(x='time (ms)', y='mems') +
scale_x_continuous(labels=c(t_init, t_final), breaks=c(t_init, t_final)) +
scale_color_manual(values=color_map) + theme(legend.position="none")
scale_color_manual(values=color_map) +
theme(legend.position="none", text = element_text(size=16))

df_spk <- read.csv(str_replace(nth(dir_list, -1), "events_spikes.feather", "spikes_post.csv"))
rates <- df_spk %>%
ggplot(aes(x=time_ms)) + geom_histogram(fill=color_map[3]) + theme_bw() +
labs(x='time (ms)', y='# spikes')
labs(x='time (ms)', y='# spikes') + theme(text = element_text(size=16))

n_fetch <- rates /
(trace_init + trace_final) /
Expand Down
19 changes: 11 additions & 8 deletions plots/fp8_simple_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ state_vars <- df_vars %>%
filter(!str_detect(monitor, "ref"), id==0) %>%
mutate(monitor = str_replace(monitor,
"statemon_pre_neurons",
"presynaptic neuron")) %>%
"presynaptic")) %>%
mutate(monitor = str_replace(monitor,
"statemon_post_neurons",
"postsynaptic neuron")) %>%
"postsynaptic")) %>%
mutate(variable = str_replace(variable, "Ca", "x")) %>%
mutate(variable = str_replace(variable, "g", "PSP"))
state_vars$value <- map_dbl(state_vars$value, minifloat2decimal)
Expand All @@ -54,7 +54,7 @@ states_stoch <- state_vars %>%
geom_line() + labs(x='time (ms)', y='magnitude (a.u.)', color='state variables') +
xlim(c(363, 713)) + scale_color_manual(values=color_map[c(1, 3, 5)]) +
guides(color=guide_legend(override.aes=list(linewidth=5))) +
theme(legend.position="none")
theme(legend.position="none", text = element_text(size=16))

df_weights <- read.csv(file.path(data_path[sim_id], 'synapse_vars.csv'))
w_trace <- df_weights %>%
Expand All @@ -71,7 +71,7 @@ weights_stoch_high <- temp_weights +
geom_line(data=avg_weight, aes(x=time_ms, y=value),
color=color_map[4], linewidth=1) +
labs(x='time (ms)', y='weight (a.u.)') +
xlim(c(363, 1957)) + theme_bw()
xlim(c(363, 1957)) + theme_bw() + theme(text=element_text(size=16))

selected_folder <- stoch_round & small_w
sim_id <- match(T, selected_folder)
Expand All @@ -90,7 +90,7 @@ weights_stoch_low <- temp_weights +
geom_line(data=avg_weight, aes(x=time_ms, y=value),
color=color_map[4], linewidth=1) +
labs(x='time (ms)', y='weight (a.u.)') +
xlim(c(363, 1957)) + theme_bw()
xlim(c(363, 1957)) + theme_bw() + theme(text=element_text(size=16))

selected_folder <- !stoch_round & !small_w
sim_id <- match(T, selected_folder)
Expand All @@ -100,10 +100,10 @@ state_vars <- df_vars %>%
filter(!str_detect(monitor, "ref"), id==0) %>%
mutate(monitor = str_replace(monitor,
"statemon_pre_neurons",
"presynaptic neuron")) %>%
"presynaptic")) %>%
mutate(monitor = str_replace(monitor,
"statemon_post_neurons",
"postsynaptic neuron")) %>%
"postsynaptic")) %>%
mutate(variable = str_replace(variable, "Ca", "x")) %>%
mutate(variable = str_replace(variable, "g", "PSP"))
state_vars$value <- map_dbl(state_vars$value, minifloat2decimal)
Expand All @@ -112,7 +112,8 @@ states_det <- state_vars %>%
facet_grid(rows=vars(fct_rev(monitor)), scales="free") +
geom_line() + labs(x='time (ms)', y='magnitude (a.u.)', color='state variables') +
xlim(c(363, 713)) + scale_color_manual(values=color_map[c(1, 3, 5)]) +
guides(color=guide_legend(override.aes=list(linewidth=5)))
guides(color=guide_legend(override.aes=list(linewidth=5))) +
theme(text=element_text(size=16))

df_weights <- read.csv(file.path(data_path[sim_id], 'synapse_vars.csv'))
w_trace <- df_weights %>%
Expand All @@ -122,6 +123,7 @@ weights_det_high <- w_trace %>%
filter(id==0) %>%
ggplot(aes(x=time_ms, y=value, group=id)) +
geom_line(alpha=.6, color=color_map[3]) + theme_bw() +
theme(text=element_text(size=16)) +
scale_color_manual(values = color_map[3]) +
labs(x='time (ms)', y='weight (a.u.)') +
xlim(c(363, 1957))
Expand All @@ -137,6 +139,7 @@ weights_det_low <- w_trace %>%
filter(id==0) %>%
ggplot(aes(x=time_ms, y=value, group=id)) +
geom_line(alpha=.6, color=color_map[3]) + theme_bw() +
theme(text=element_text(size=16)) +
scale_color_manual(values = color_map[3]) +
labs(x='time (ms)', y='weight (a.u.)') +
xlim(c(363, 1957))
Expand Down
3 changes: 2 additions & 1 deletion plots/multi_fetch_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ df_events <- df_events %>%
group_by(N_post, group) %>% mutate(mean_fetch=mean(num_fetch))
multi_fetch_avg <- df_events %>%
ggplot(aes(x=group, y=num_fetch)) +
geom_boxplot(aes(fill=group)) + theme_bw() + theme(legend.position="none") +
geom_boxplot(aes(fill=group)) + theme_bw() +
theme(legend.position="none", text=element_text(size=16)) +
geom_point(aes(y=mean_fetch, color=group), shape=2, size=7) +
facet_wrap(~N_post) + scale_y_log10() +
labs(x=element_blank(), y='# Memory access') +
Expand Down
18 changes: 11 additions & 7 deletions plots/simple_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ ca_traces <- ggplot() +
geom_histogram(data=df_pre_events, aes(x=time_ms), fill=color_map[2],
alpha=0.3, binwidth=1) +
labs(x=element_blank(), y=TeX(r'($x_i$ (a.u))')) +
theme_bw() + theme(panel.grid.minor=element_blank())
theme_bw() + theme(panel.grid.minor=element_blank(), text = element_text(size=16))

df_post_ca_trace <- df_vars %>%
filter(id==0) %>%
filter(variable=='Ca' & monitor=='statemon_post_neurons') %>%
filter(time_ms>690 & time_ms<890) %>%
ggplot(aes(x=time_ms, y=value)) +
labs(x='time (ms)', y=TeX(r'($x_j$ (a.u))')) +
theme_bw() + theme(panel.grid.minor=element_blank()) + geom_line()
theme_bw() + theme(panel.grid.minor=element_blank(), text = element_text(size=16)) +
geom_line()

b_rang <- c(0, 310, 420, 720, 800, 1110, 1210, 1510, 1610, 2010, 2080, 2320)
w_trace <- df_weights %>%
Expand All @@ -57,7 +58,8 @@ w_trace <- df_weights %>%
annotate(geom='text', x=b_rang[6] - (b_rang[6]-b_rang[5])/2, y=11.2, label='III') +
annotate(geom='text', x=b_rang[8] - (b_rang[8]-b_rang[7])/2, y=11.2, label='IV') +
annotate(geom='text', x=b_rang[10] - (b_rang[10]-b_rang[9])/2, y=11.2, label='V') +
annotate(geom='text', x=b_rang[12] - (b_rang[12]-b_rang[11])/2, y=11.2, label='VI')
annotate(geom='text', x=b_rang[12] - (b_rang[12]-b_rang[11])/2, y=11.2, label='VI') +
theme(text = element_text(size=16))

# Mean is taken over all connections, i.e. id
mse_w <- df_weights %>%
Expand All @@ -68,10 +70,12 @@ mse_w <- df_weights %>%
group_by(time_ms) %>%
summarise(mse = mean(squared_error)) %>%
ggplot(aes(x=time_ms, y=mse)) + labs(x='time (ms)', y='mean squared error') +
geom_line() + theme_bw() + theme(panel.grid.minor=element_blank())
geom_line() + theme_bw() +
theme(panel.grid.minor=element_blank(), text = element_text(size=16)) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 3))

w_changes <- wrap_elements(w_trace + plot_annotation(title='A')) /
(wrap_elements(mse_w + plot_annotation(title='B')) +
wrap_elements(ca_traces / df_post_ca_trace + plot_annotation(title='C')))
w_changes <- wrap_elements(w_trace + plot_annotation(title='A', theme=theme(text=element_text(size=16)))) /
(wrap_elements(mse_w + plot_annotation(title='B', theme=theme(text=element_text(size=16)))) +
wrap_elements(ca_traces / df_post_ca_trace + plot_annotation(title='C', theme=theme(text=element_text(size=16)))))

ggsave(argv$dest, w_changes)
22 changes: 14 additions & 8 deletions plots/stochastic_balance_stdp.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ plot_weights <- function(df_data, bin_width, subset=NULL){
w_distribution <- df_weights %>%
ggplot(aes(x=mids, y=count)) +
geom_col(width=bin_width, fill=color_map[1], color=color_map[1]) +
theme_bw() + labs(x='weights (a.u.)', y='fraction of synapses')
theme_bw() + labs(x='weights (a.u.)', y='fraction of synapses') +
theme(text=element_text(size=16))

return(w_distribution)
}
Expand All @@ -116,18 +117,20 @@ variables <- state_vars %>%
mutate(variable = str_replace(variable, "Ca", "x")) %>%
mutate(variable = str_replace(variable, "g", "PSP")) %>%
ggplot(aes(x=time_ms, y=value, color=variable)) +
labs(x='time (s)', y='magnitude (a.u.)') + scale_color_manual(values=color_map) +
labs(x='time (ms)', y='magnitude (a.u.)') + scale_color_manual(values=color_map) +
guides(color=guide_legend(override.aes=list(linewidth=5))) +
geom_line() + theme_bw()
geom_line() + theme_bw() + theme(text=element_text(size=16))

w_distribution <- plot_weights(data_path, bin_width=0.64)
incoming_w_j0 <- plot_weights(data_path, bin_width=0.64, 0)
incoming_w_j10 <- plot_weights(data_path, bin_width=0.64, 10000)

event_data <- read.csv(file.path(data_path, 'events_spikes.csv'))
fetches <- event_data %>%
mutate(time_ms = time_ms/1000) %>%
ggplot(aes(x=time_ms, y=num_events)) + geom_line(color=color_map[1]) +
theme_bw() + labs(x='time (ms)', y='# active neurons')
theme_bw() + labs(x='time (s)', y='# active neurons') +
theme(text=element_text(size=16))

df_raster <- read.csv(file.path(data_path, 'output_spikes.csv'))
print("Statistics with bimodal experiment: ")
Expand All @@ -146,10 +149,13 @@ df_rates_final$group <- 'final'
df_rates_init$group <- 'initial'
freq <- bind_rows(df_rates_init, df_rates_final) %>%
ggplot(aes(x=rate, color=group, fill=group)) + theme_bw() +
geom_histogram(alpha=.5) + scale_color_manual(values=color_map) +
scale_fill_manual(values=color_map) + theme(legend.position = c(0.8, 0.8)) +
labs(x='firing rates (Hz)', y='count', fill=element_blank(), color=element_blank()) +
scale_y_log10()
geom_histogram(alpha=.5, binwidth=1) + scale_color_manual(values=color_map) +
scale_fill_manual(values=color_map) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 4)) +
theme(legend.position = c(0.25, 0.8),
text=element_text(size=16),
legend.text=element_text(size=10)) +
labs(x='firing rates (Hz)', y='count', fill=element_blank(), color=element_blank())

fig <- fetches + variables + freq + w_distribution +
plot_annotation(tag_levels='A')
Expand Down
6 changes: 3 additions & 3 deletions plots/stochastic_kernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ generate_plot <- function(df, time) {
ggplot(aes(x=id, y=value)) + geom_line(color=color_map[3]) + theme_bw() +
labs(x=TeX(r'($\Delta$\;t (ms))'), y=element_blank(), color=element_blank()) +
guides(color=guide_legend(override.aes=list(linewidth=4))) +
theme(legend.position = c(0.25, 0.8))
theme(legend.position = c(0.25, 0.8), text=element_text(size=16))
return(kernel)
}

Expand All @@ -61,8 +61,8 @@ kernel_small_middle <- kernel_small_middle + labs(y='weight (a.u.)')
kernel_small_final <- generate_plot(df_weights_small, 9000)

fig_kernel <- wrap_elements(kernel_high_middle + kernel_high_final +
plot_annotation(title='A')) /
plot_annotation(title='A', theme=theme(text=element_text(size=16)))) /
wrap_elements(kernel_small_middle + kernel_small_final +
plot_annotation(title='B'))
plot_annotation(title='B', theme=theme(text=element_text(size=16))))

ggsave(argv$dest, fig_kernel)
10 changes: 6 additions & 4 deletions plots/stochastic_operations.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ if (op_type == "addition"){
L_heatmap <- ggplot(df_L, aes(delta, lambda, fill=L)) +
scale_fill_gradientn(colors=color_map, name=TeX(r'($L$)')) +
labs(x=TeX(r'($\delta$)'), y=TeX(r'($\lambda$)')) + theme_bw() + geom_tile() +
theme(legend.position="top")
theme(legend.position="top", text = element_text(size=16),
legend.text=element_text(angle=45))
}

my_breaks<-c(1, 10, 100, 1000)
Expand All @@ -76,7 +77,8 @@ probs_scatter <- ggplot(df_scatter, aes(x=p_round_closer_ideal, y=p_round_closer
geom_smooth(colour='black', method=lm) + geom_bin2d(bins=25) +
geom_abline(slope=1, intercept=0, linetype="dashed", color="black") +
theme_bw() + labs(x=TeX(r'($P_i$)'), y=TeX(r'($P_s$)')) +
theme(legend.position="top")
theme(legend.position="top", text = element_text(size=16),
legend.text=element_text(angle=45))

if (op_type == "addition"){
sim_id <- match("stickier", selected_folders)
Expand All @@ -90,7 +92,7 @@ if (op_type == "addition"){
geom_smooth(colour='black', method=lm) + geom_bin2d(bins=25) +
geom_abline(slope=1, intercept=0, linetype="dashed", color="black") +
theme_bw() + labs(x=TeX(r'($P_i$)'), y=TeX(r'($P_s$)')) +
theme(legend.position="none")
theme(legend.position="none", text = element_text(size=16))

sim_id <- match("cutoff", selected_folders)
df_cut <- read.csv(file.path(data_path[sim_id], "probs.csv"))
Expand All @@ -103,7 +105,7 @@ if (op_type == "addition"){
geom_smooth(colour='black', method=lm) + geom_bin2d(bins=25) +
geom_abline(slope=1, intercept=0, linetype="dashed", color="black") +
theme_bw() + labs(x=TeX(r'($P_i$)'), y=TeX(r'($P_s$)')) +
theme(legend.position="none")
theme(legend.position="none", text = element_text(size=16))
}

if (op_type == "addition"){
Expand Down
9 changes: 6 additions & 3 deletions plots/stochastic_pd.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ freq <- rates %>%
mutate(layer=fct_rev(layer)) %>%
ggplot(aes(rate, layer)) + theme_bw() +
theme(panel.grid.minor=element_blank(),
panel.grid.major=element_blank()) +
panel.grid.major=element_blank(),
text=element_text(size=16)) +
labs(x='firing rates (Hz)', y=element_blank()) +
geom_boxplot() +
stat_summary(fun='mean', geom='point', shape=2)
Expand Down Expand Up @@ -123,7 +124,7 @@ histograms <- df_raster %>%
ggplot(aes(x=t, color=type)) + geom_step(stat='bin', bins=50) +
guides(color=guide_legend(override.aes=list(size=4))) +
facet_grid(rows=vars(laminae), scales='free') + theme_bw() +
theme(legend.position = 'bottom') +
theme(legend.position = 'bottom', text=element_text(size=16)) +
scale_color_manual(values=color_map[c(1, 3)]) +
guides(color=guide_legend(override.aes=list(linewidth=5))) +
labs(x='time (ms)') + xlim(670, 730)
Expand All @@ -136,7 +137,9 @@ variables <- state_vars %>%
ggplot(aes(x=time_ms, y=value, color=variable)) +
geom_line() + theme_bw() +
facet_grid(layer ~ type, scales="free") +
theme(legend.position = 'bottom', strip.text.y = element_blank()) +
theme(legend.position = 'bottom',
strip.text.y = element_blank(),
text=element_text(size=16)) +
labs(x='time (s)', y='magnitude (a.u.)') + scale_color_manual(values=color_map) +
guides(color=guide_legend(override.aes=list(linewidth=5)))

Expand Down
Loading

0 comments on commit 73c1a32

Please sign in to comment.