45 lines
1.5 KiB
R
45 lines
1.5 KiB
R
# 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() |