From d13eee49eadeeb77c19f7b696d008f1f6d987eb0 Mon Sep 17 00:00:00 2001 From: Niclas Date: Wed, 6 May 2026 17:18:35 +0200 Subject: [PATCH] add visualization of the matrix Q wrt parameter a --- scripts/plot_Qa_wrt_a.R | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/plot_Qa_wrt_a.R diff --git a/scripts/plot_Qa_wrt_a.R b/scripts/plot_Qa_wrt_a.R new file mode 100644 index 0000000..9c92231 --- /dev/null +++ b/scripts/plot_Qa_wrt_a.R @@ -0,0 +1,45 @@ +# load local files +source(here::here("R", "singular_values.R")) +source(here::here("R", "graphon_distribution.R")) +source(here::here("R","singular_value_plot.R")) + +# load libaries for data handling +library(ggplot2) +library(tidyr) +library(dplyr) + +# Create a grid of a‑values +a_grid <- seq(-20, 20, length.out = 200) + +# function which takes only a to compute Q_c +make_matrix <- function(a) { compute_matrix(seed=4L, + a= a, + n = 2, + K = 2, + sample_X_fn = function(n) {matrix(rnorm(n), ncol = 1L)}, + fv = function(x) {dnorm(x, mean=0, sd=1)}, + Fv = function(x) {pnorm(x, mean=0, sd=1)}, + guard = 1e-12)} + +# Compute the matrices and reshape to long format +df_entries <- tibble(a = a_grid) %>% + mutate( + M = purrr::map(a, make_matrix), # list‑column of matrices + m11 = purrr::map_dbl(M, ~ .x[1, 1]), + m12 = purrr::map_dbl(M, ~ .x[1, 2]), + m21 = purrr::map_dbl(M, ~ .x[2, 1]), + m22 = purrr::map_dbl(M, ~ .x[2, 2]) + ) %>% + select(a, m11, m12, m21, m22) %>% + pivot_longer(-a, names_to = "entry", values_to = "value") + +# Plot +ggplot(df_entries, aes(x = a, y = value, colour = entry, linetype = entry)) + + geom_line(linewidth = 1) + + labs( + title = "Matrix entries as a function of the parameter `a`", + x = "a", + y = "Matrix entry value", + colour = "Entry" + ) + + theme_minimal() \ No newline at end of file