Make curves smoooooooth
This commit is contained in:
@@ -206,7 +206,7 @@ chart = {
|
|||||||
const line = d3.line()
|
const line = d3.line()
|
||||||
.x(d => x(d.x))
|
.x(d => x(d.x))
|
||||||
.y(d => y(d.y))
|
.y(d => y(d.y))
|
||||||
.curve(d3.curveLinear);
|
.curve(d3.curveBasis);
|
||||||
|
|
||||||
// Group to contain the basis function lines
|
// Group to contain the basis function lines
|
||||||
const linesGroup = g.append("g")
|
const linesGroup = g.append("g")
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ library(readr)
|
|||||||
# Creating faceted plots for different knot values and mu values
|
# Creating faceted plots for different knot values and mu values
|
||||||
# Create a function to generate the data for a given number of knots and mu value
|
# Create a function to generate the data for a given number of knots and mu value
|
||||||
generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tailw_value, deg_value) {
|
generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tailw_value, deg_value) {
|
||||||
grid <- seq(from = 0.01, to = 0.99, length.out = 99)
|
grid <- seq(from = 0.01, to = 0.99, length.out = 50)
|
||||||
# Use provided degree
|
# Use provided degree
|
||||||
B <- profoc:::make_basis_matrix(grid,
|
B <- profoc:::make_basis_matrix(grid,
|
||||||
profoc::make_knots(
|
profoc::make_knots(
|
||||||
@@ -21,9 +21,9 @@ generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tail
|
|||||||
),
|
),
|
||||||
deg = deg_value
|
deg = deg_value
|
||||||
)
|
)
|
||||||
B_mat <- round(as.matrix(B), 2)
|
B_mat <- round(as.matrix(B), 3)
|
||||||
df <- as.data.frame(B_mat)
|
df <- as.data.frame(B_mat)
|
||||||
df$x <- round(grid, 2)
|
df$x <- grid
|
||||||
df_long <- pivot_longer(df,
|
df_long <- pivot_longer(df,
|
||||||
cols = -x,
|
cols = -x,
|
||||||
names_to = "b",
|
names_to = "b",
|
||||||
@@ -39,7 +39,6 @@ generate_basis_data <- function(num_knots, mu_value, sig_value, nonc_value, tail
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Generate data for each combination of knot, mu, sig, nonc, tailw, and deg
|
# Generate data for each combination of knot, mu, sig, nonc, tailw, and deg
|
||||||
knot_values <- c(10)
|
|
||||||
mu_values <- seq(0.1, 0.9, by = 0.2)
|
mu_values <- seq(0.1, 0.9, by = 0.2)
|
||||||
sig_values <- 2^(-2:2)
|
sig_values <- 2^(-2:2)
|
||||||
nonc_values <- c(-4, -2, 0, 2, 4)
|
nonc_values <- c(-4, -2, 0, 2, 4)
|
||||||
@@ -50,16 +49,14 @@ all_data <- list()
|
|||||||
counter <- 1
|
counter <- 1
|
||||||
|
|
||||||
# Nested loops to cover all parameter combinations
|
# Nested loops to cover all parameter combinations
|
||||||
for (k in knot_values) {
|
print(paste("Processing knots:", k))
|
||||||
print(paste("Processing knots:", k))
|
for (m in mu_values) {
|
||||||
for (m in mu_values) {
|
print(paste("Processing mu:", m))
|
||||||
print(paste("Processing mu:", m))
|
for (s in sig_values) {
|
||||||
for (s in sig_values) {
|
for (nc in nonc_values) {
|
||||||
for (nc in nonc_values) {
|
for (tw in tailw_values) {
|
||||||
for (tw in tailw_values) {
|
all_data[[counter]] <- generate_basis_data(5, m, s, nc, tw, 2)
|
||||||
all_data[[counter]] <- generate_basis_data(5, m, s, nc, tw, 2)
|
counter <- counter + 1
|
||||||
counter <- counter + 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,3 +68,16 @@ all_data <- bind_rows(all_data)
|
|||||||
write_csv(all_data, "25_07_phd_defense/assets/mcrps_learning/basis_functions.csv")
|
write_csv(all_data, "25_07_phd_defense/assets/mcrps_learning/basis_functions.csv")
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
all_data %>%
|
||||||
|
filter(mu == 0.1) %>%
|
||||||
|
filter(sig == 0.25) %>%
|
||||||
|
filter(nonc == -4) %>%
|
||||||
|
filter(tailw == 0.25) %>%
|
||||||
|
ggplot(aes(x = x, y = y, col = b)) +
|
||||||
|
geom_line(size = 2) +
|
||||||
|
labs(
|
||||||
|
title = "Basis Functions for Different Knot Values",
|
||||||
|
x = "x",
|
||||||
|
y = "y"
|
||||||
|
) +
|
||||||
|
theme_minimal()
|
||||||
|
|||||||
Reference in New Issue
Block a user