Go back to the About page.
Let us set some global options for all code chunks in this document.
# Set seed for reproducibility
set.seed(1982)
# Set global options for all code chunks
knitr::opts_chunk$set(
# Disable messages printed by R code chunks
message = FALSE,
# Disable warnings printed by R code chunks
warning = FALSE,
# Show R code within code chunks in output
echo = TRUE,
# Include both R code and its results in output
include = TRUE,
# Evaluate R code chunks
eval = TRUE,
# Enable caching of R code chunks for faster rendering
cache = FALSE,
# Align figures in the center of the output
fig.align = "center",
# Enable retina display for high-resolution figures
retina = 2,
# Show errors in the output instead of stopping rendering
error = TRUE,
# Do not collapse code and output into a single block
collapse = FALSE
)
# Start the figure counter
fig_count <- 0
# Define the captioner function
captioner <- function(caption) {
fig_count <<- fig_count + 1
paste0("Figure ", fig_count, ": ", caption)
}
Follow this link for an illustration of the geodesic distance on a metric graph.
Follow this link for an illustration of a function on a metric graph.
Follow this link for alternative illustrations of basis functions on a metric graph.
Let each edge \(e\in\mathcal{E}\) be subdivided into \(n_{e}\geq 2\) regular segments of length \(h_{e}\), and be delimited by the nodes \(0 = x_0^{e},x_1^{e},\dots,x_{n_{e}-1}^{e}, x_{n_{e}}^{e} = \ell_{e}\). For each \(j = 1,\dots,n_{e}-1\), we consider the following standard hat basis functions \[\begin{equation*} \varphi_j^{e}(x)=\begin{cases} 1-\dfrac{|x_j^{e}-x|}{h_{e}},&\text{ if }x_{j-1}^{e}\leq x\leq x_{j+1}^{e},\\ 0,&\text{ otherwise}. \end{cases} \end{equation*}\] For each \(e\in\mathcal{E}\), the set of hat functions \(\left\{\varphi_1^{e},\dots,\varphi_{n_{e}-1}^{e}\right\}\) is a basis for the space \[\begin{equation*} V_{h_{e}} = \left\{w\in H_0^1(e)\;\Big|\;\forall j = 0,1,\dots,n_{e}-1:w|_{[x_j^{e}, x_{j+1}^{e}]}\in\mathbb{P}^1\right\}, \end{equation*}\] where \(\mathbb{P}^1\) is the space of linear functions on \([0,\ell_{e}]\). For each vertex \(v\in\mathcal{V}\), we define \[\begin{equation*} \mathcal{N}_v = \left\{\bigcup_{e\in\left\{e\in\mathcal{E}_v: v = x_0^e\right\}}[v,x_1^e]\right\}\bigcup\left\{\bigcup_{e\in\left\{e\in\mathcal{E}_v: v = x^e_{n_e}\right\}}[x^e_{n_e-1},v]\right\}, \end{equation*}\] which is a star-shaped set with center at \(v\) and rays made of the segments contiguous to \(v\). On \(\mathcal{N}_v\), we define the hat functions as \[\begin{equation*} \phi_v(x)=\begin{cases} 1-\dfrac{|x_v^{e}-x|}{h_{e}},&\text{ if }x\in\mathcal{N}_v\cap e \text{ and }e\in\mathcal{E}_v,\\ 0,&\text{ otherwise}, \end{cases} \end{equation*}\] where \(x_v^e\) is either \(x_0^e\) or \(x_{n_e}^e\) depending on the edge direction and its parameterization. See Arioli and Benzi (2018) for more. Figure 3 below provides an illustration of the system of basis functions \(\{\varphi_j^e, \phi_v\}\) together with the set \(\mathcal{N}_v\).
Press the Show button below to reveal the code.
# star set
d49 = data.frame(y = c(1/3,0), x = c(0,0), z = c(0,0))
d50 = data.frame(y = c(0,0), x = c(1/3,0), z = c(0,0))
d51 = data.frame(y = c(-1/3,0), x = c(0,0), z = c(0,0))
d52 = data.frame(y = c(0,0), x = c(-1/3,0), z = c(0,0))
graph_to_get_loc <- graph$clone()
graph_to_get_loc$build_mesh(h = 1/120)
loc <- graph_to_get_loc$get_mesh_locations()
graph$build_mesh(h = 1/3)
A <- graph$fem_basis(loc)
DD <- data.frame(A = as.matrix(A)) %>%
rowwise() %>%
mutate(max_value = max(c_across(everything()))) %>%
cbind(edge_number = loc[, 1], distance_on_edge = loc[, 2], A.24 = 0)
graph$add_observations(data = DD, edge_number = "edge_number",
distance_on_edge = "distance_on_edge", data_coords = "PtE", normalized = TRUE, clear_obs = TRUE)
# Initialize the first plot
p <- graph_to_get_loc$plot_function(X = DD[[paste0("A.", 1)]], line_color = "red",
edge_width = 2, line_width = 2, support_width = 0.2, plotly = TRUE)
# Loop through to create the remaining plots
for (i in 2:24) {
line_color <- "gray"
if (i == 11) {line_color <- "blue"}
if (i == 24) {line_color <- "black"}
X <- DD[[paste0("A.", i)]]
p <- graph_to_get_loc$plot_function(X = X, line_color = line_color, edge_width = 2, line_width = 2, support_width = 0.2, plotly = TRUE, p = p)
}
pp = p %>%
config(mathjax = 'cdn') %>%
layout(title = TeX("\\text{Basis functions on a metric graph }\\Gamma = (\\mathcal{V},\\mathcal{E})"),
showlegend = FALSE,
font = list(family = "Palatino"),
scene = list(
aspectratio = list(x = 1.8, y = 1.8, z = 0.4),
annotations = list(
list(
x = -1, y = 0, z = 0,
text = TeX("v_1"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 0, z = 0,
text = TeX("v_2"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = -1, z = 0,
text = TeX("v_3"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = -1, z = 0,
text = TeX("v_4"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = 0, z = 0,
text = TeX("v_5"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = 1, z = 0,
text = TeX("v_6,x_0^{e_7}"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 1, z = 0,
text = TeX("v_7,x_3^{e_7}"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 2/3, y = 1, z = 0,
text = TeX("x_1^{e_7}"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1/3, y = 1, z = 0,
text = TeX("x_2^{e_7}"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.15, y = 0, z = 0,
text = TeX("\\mathcal{N}_{v_2}"),
textangle = 0, ax = 0, ay = 25,
font = list(color = "green", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 2/3, y = 1, z = 1,
text = TeX("\\varphi_1^{e_7}"),
textangle = 0, ax = 0, ay = 75,
font = list(color = "blue", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 0, z = 1,
text = TeX("\\phi_{v_2}"),
textangle = 0, ax = 0, ay = 75,
font = list(color = "red", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1)
))) %>%
add_trace(x = 0, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = 1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = 1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = -1, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = -2/3, y = 0, z = 0, mode = "markers", type = "scatter3d", # before this
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = -1/3, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = -1/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = -2/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1/3, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 2/3, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = 1/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 0, y = 2/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1/3, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 2/3, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1/3, y = 1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 2/3, y = 1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = 1/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = 2/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = -1/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(x = 1, y = -2/3, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 4, color = "blue", symbol = 104)) %>%
add_trace(data = d49, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 3, color = "green", symbol = 104)) %>%
add_trace(data = d50, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 3, color = "green", symbol = 104)) %>%
add_trace(data = d51, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 3, color = "green", symbol = 104)) %>%
add_trace(data = d52, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 3, color = "green", symbol = 104))
pp
Figure 1: Illustration of the system of basis functions \(\{\varphi_j^e, \phi_v\}\) (solid gray lines) on the graph \(\Gamma= (\mathcal{V},\mathcal{E})\), where \(\mathcal{E}= \left\{e_1,\dots,e_8\right\}\) and \(\mathcal{V}= \left\{v_1,\dots,v_7\right\}\). Note that for all \(e_i\in\mathcal{E}\), \(n_{e_i} = 3\) and \(h_{e_i} = 1/3\). In particular, for edge \(e_7\), observe that the three regular segments are delimited by the nodes \(v_6 = x_0^{e_7}, x_1^{e_7}, x_2^{e_7}, x_3^{e_7} = v_7\). Corresponding to node \(x_1^{e_7}\), we have plotted the basis function \(\varphi_1^{e_7}\) in blue. Notice also that the set \(\mathcal{N}_{v_2}\) is depicted in green and its corresponding basis function \(\phi_{v_2}\) is shown in red.
We used R version 4.4.1 (R Core Team 2024a) and the following R packages: cowplot v. 1.1.3 (Wilke 2024), ggmap v. 4.0.0.900 (Kahle and Wickham 2013), ggpubr v. 0.6.0 (Kassambara 2023), ggtext v. 0.1.2 (Wilke and Wiernik 2022), grid v. 4.4.1 (R Core Team 2024b), here v. 1.0.1 (Müller 2020), htmltools v. 0.5.8.1 (Cheng et al. 2024), INLA v. 24.12.11 (Rue, Martino, and Chopin 2009; Lindgren, Rue, and Lindström 2011; Martins et al. 2013; Lindgren and Rue 2015; De Coninck et al. 2016; Rue et al. 2017; Verbosio et al. 2017; Bakka et al. 2018; Kourounis, Fuchs, and Schenk 2018), inlabru v. 2.12.0.9002 (Yuan et al. 2017; Bachl et al. 2019), knitr v. 1.48 (Xie 2014, 2015, 2024), latex2exp v. 0.9.6 (Meschiari 2022), Matrix v. 1.6.5 (Bates, Maechler, and Jagan 2024), MetricGraph v. 1.4.0.9000 (Bolin, Simas, and Wallin 2023b, 2023a, 2023c, 2024; Bolin et al. 2024), OpenStreetMap v. 0.4.0 (Fellows and JMapViewer library by Jan Peter Stotz 2023), osmdata v. 0.2.5 (Mark Padgham et al. 2017), patchwork v. 1.2.0 (Pedersen 2024), plotly v. 4.10.4 (Sievert 2020), plotrix v. 3.8.4 (J 2006), reshape2 v. 1.4.4 (Wickham 2007), rmarkdown v. 2.28 (Xie, Allaire, and Grolemund 2018; Xie, Dervieux, and Riederer 2020; Allaire et al. 2024), rSPDE v. 2.4.0.9000 (Bolin and Kirchner 2020; Bolin and Simas 2023; Bolin, Simas, and Xiong 2024), scales v. 1.3.0 (Wickham, Pedersen, and Seidel 2023), sf v. 1.0.19 (E. Pebesma 2018; E. Pebesma and Bivand 2023), sp v. 2.1.4 (E. J. Pebesma and Bivand 2005; Bivand, Pebesma, and Gomez-Rubio 2013), tidyverse v. 2.0.0 (Wickham et al. 2019), viridis v. 0.6.4 (Garnier et al. 2023), xaringanExtra v. 0.8.0 (Aden-Buie and Warkentin 2024).