add visualization of the matrix Q wrt parameter a

This commit is contained in:
Niclas
2026-05-06 17:18:35 +02:00
parent 5acc3f4259
commit d13eee49ea

45
scripts/plot_Qa_wrt_a.R Normal file
View File

@@ -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 avalues
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), # listcolumn 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()