From fe36738ea177ec28b3b4b7ed933d1f24124b1080 Mon Sep 17 00:00:00 2001 From: Niclas Date: Wed, 1 Apr 2026 14:35:29 +0200 Subject: [PATCH] adjusted non normal plots --- scripts/plot_non_normal_X.qmd | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/scripts/plot_non_normal_X.qmd b/scripts/plot_non_normal_X.qmd index 2303636..3790668 100644 --- a/scripts/plot_non_normal_X.qmd +++ b/scripts/plot_non_normal_X.qmd @@ -348,3 +348,82 @@ results |> colour=latex2exp::TeX("$a$"), shape=latex2exp::TeX("$\\alpha$")) ``` +```{r k = n^alpha data generation, N(0,1)} +#| cache: true +#| echo: false +#| collapse: true +ns <- seq(100, 5000, 100) +as <- seq(0, 20, 2) +alphas <- seq(0.1, 0.5, 0.1) + +set.seed(100) +results <- data.frame(dim_n = integer(), + dim_k = integer(), + param_a = double(), + param_alpha = double(), + ssv = double()) +for (a in as) { + for (i in 1:length(ns)) { + for (j in 1:length(alphas)) { + n <- ns[i] + # HERE WE USE THE CEILING AND NOT FLOOR! + K <- ceiling(n^alphas[j]) + if (!K > 0) next # skip if K is equal to zero + # use the default seed 1L + Q <- compute_matrix(seed=1L, + a= a, + n = n, + K = K, + 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) + + ssv <- compute_minmax_sv(Q)[["smallest_singular_value"]] + + current_res <- data.frame(dim_n = n, dim_k = K, param_a = a, param_alpha=alphas[j], ssv =ssv) + results <- rbind(results, current_res) + } + } +} +``` + +```{r k = n^alpha plotting, U[0,2]} +results |> + filter(param_a %in% c(0, 10, 20)) |> + mutate(param_a = as.factor(param_a), + param_alpha = as.factor(param_alpha)) |> + group_by(param_a, param_alpha) |> + ggplot(aes(dim_n, ssv * dim_k, col=param_a, shape=param_alpha, interaction(param_a, param_alpha))) + + geom_point(size=1.5) + + geom_line() + + geom_function(fun = function(x) {x^(0.5)}, colour="black") + + #scale_y_log10() + + theme_bw() + + labs(x=latex2exp::TeX("$n$"), + y=latex2exp::TeX("Smallest singular value of $Q$"), + title=latex2exp::TeX("Smallest singular value of $Q$ with respect to $a$."), + subtitle = latex2exp::TeX(("Hyperparameter $k = n^{\\alpha}$. Black line is $\\sqrt{n}$, and $X \\sim N(0,1) $")), + colour=latex2exp::TeX("$a$"), + shape=latex2exp::TeX("$\\alpha$")) +``` + +```{r k = n^alpha plotting, U[0,2]} +results |> + filter(param_a %in% c(0, 10, 20)) |> + mutate(param_a = as.factor(param_a), + param_alpha = as.factor(param_alpha)) |> + group_by(param_a, param_alpha) |> + ggplot(aes(dim_n, ssv / sqrt(dim_n) * dim_k, col=param_a, shape=param_alpha, interaction(param_a, param_alpha))) + + geom_point(size=1.5) + + geom_line() + + # geom_function(fun = function(x) {x^(0.5)}, colour="black") + + #scale_y_log10() + + theme_bw() + + labs(x=latex2exp::TeX("$n$"), + y=latex2exp::TeX("Smallest singular value of $Q$ / sqrt(n)"), + title=latex2exp::TeX("Smallest singular value of $Q$ with respect to $a$."), + subtitle = latex2exp::TeX(("Hyperparameter $k = n^{\\alpha}$. Black line is $\\sqrt{n}$, and $X \\sim N(0,1) $")), + colour=latex2exp::TeX("$a$"), + shape=latex2exp::TeX("$\\alpha$")) +``` \ No newline at end of file