Go back to the About page.
Go back to the Basis Functions 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)
}
Figure 1 below shows an illustration of a compact and connected graph \(\Gamma = (\mathcal{V},\mathcal{E})\), where \(\mathcal{E}= \{e_1,\dots,e_8\}\) (black lines) and \(\mathcal{V} = \{v_1,\dots,v_7\}\) (blue points).
Press the Show button below to reveal the code.
df = data.frame(x = c(0.5,0), y = c(-1,-1), z = c(0,0))
df2 = data.frame(x = c(0,0), y = c(-1,0), z = c(0,0))
df3 = data.frame(x = c(0,-0.5), y = c(0,0), z = c(0,0))
graph$build_mesh(h = 1/40)
x <- graph$mesh$V[, 1]
y <- graph$mesh$V[, 2]
f <- x^2 - y^2
graph$plot(plotly = TRUE, vertex_size = 5, vertex_color = "blue",
edge_color = "black", edge_width = 2) %>%
config(mathjax = 'cdn') %>%
layout(title = TeX("\\text{Geodesic distance on a metric graph }\\Gamma = (\\mathcal{V},\\mathcal{E})"),
showlegend = FALSE,
font = list(family = "Palatino"),
scene = list(
aspectratio = list(x = 1.6, y = 1.6, z = 1),
annotations = list(
list(
x = -1, y = 0, z = 0,
text = TeX("v_1"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 20),
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 = 20),
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 = 20),
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 = 20),
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 = 20),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = 1, z = 0,
text = TeX("v_6"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 20),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 1, z = 0,
text = TeX("v_7"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 20),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = -1, z = 0,
text = TeX("s_1"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 20),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = -0.5, y = 0, z = 0,
text = TeX("s_2"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 20),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = -0.5, y = 0, z = 0,
text = TeX("e_1"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = -0.5, z = 0,
text = TeX("e_2"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = -1, z = 0,
text = TeX("e_3"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = -0.5, z = 0,
text = TeX("e_4"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = 0, z = 0,
text = TeX("e_5"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = 0.5, z = 0,
text = TeX("e_6"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = 1, z = 0,
text = TeX("e_7"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 0.5, z = 0,
text = TeX("e_8"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 20),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1)
))) %>%
add_trace(x = 0.5, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 5, color = "red", symbol = 104)) %>%
add_trace(x = -0.5, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 5, color = "red", symbol = 104)) %>%
add_trace(data = df, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104)) %>%
add_trace(data = df2, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104)) %>%
add_trace(data = df3, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104))
Figure 1: Illustration of a compact and connected graph \(\Gamma = \left(\mathcal{V},\mathcal{E}\right)\), where \(\mathcal{E}= \left\{e_1,\dots,e_8\right\}\) (black) and \(\mathcal{V}= \left\{v_1,\dots,v_7\right\}\) (blue). Notice that \(\ell_{e_i} = 1\) for \(i = 1,\dots,8\). Note also that, for example, \(\mathcal{E}_{v_2} = \left\{e_1,e_2,e_5,e_8\right\}\) and therefore \(d_{v_2} = 4.\) Given two points \(s_1 = (e_3, 0.5)\) and \(s_2 = (e_1, 0.5)\), we have that \(d(s_1,s_2) = 2\) (red). Following the convention mentioned in the text, we may write, for example, \(e_8 = (v_2,v_7) \cong [0,\ell_{e_8}]\).
Figure 2 below provides an illustration of a function defined on a graph.
Press the Show button below to reveal the code.
graph$build_mesh(h = 1/40)
x <- graph$mesh$V[, 1]
y <- graph$mesh$V[, 2]
f <- x^2 - y^2
df = data.frame(x = c(0.5,0), y = c(-1,-1), z = c(0,0))
df2 = data.frame(x = c(0,0), y = c(-1,0), z = c(0,0))
df3 = data.frame(x = c(0,-0.5), y = c(0,0), z = c(0,0))
graph$plot_function(f,plotly = TRUE, vertex_size = 5, vertex_color = "blue", line_color = "blue",
edge_color = "black", edge_width = 2) %>%
config(mathjax = 'cdn') %>%
layout(title = TeX("\\text{Function on a metric graph }\\Gamma = (\\mathcal{V},\\mathcal{E})"),
showlegend = FALSE,
font = list(family = "Palatino"),
scene = list(
aspectratio = list(x = 1.6, y = 1.6, z = 1),
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"),
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"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = -1, z = 0,
text = TeX("s_1"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = -0.5, y = 0, z = 0,
text = TeX("s_2"),
textangle = 0, ax = 0, ay = -25,
font = list(color = "black", size = 16),
arrowcolor = "black", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = -0.5, y = 0, z = 0,
text = TeX("e_1"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = -0.5, z = 0,
text = TeX("e_2"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = -1, z = 0,
text = TeX("e_3"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = -0.5, z = 0,
text = TeX("e_4"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = 0, z = 0,
text = TeX("e_5"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 1, y = 0.5, z = 0,
text = TeX("e_6"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0.5, y = 1, z = 0,
text = TeX("e_7"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = 0.5, z = 0,
text = TeX("e_8"),
textangle = 0, ax = 0, ay = 10,
font = list(color = "black", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1),
list(
x = 0, y = -1, z = 1,
text = TeX("f=\\gamma\\big|_\\Gamma"),
textangle = 0, ax = 60, ay = 0,
font = list(color = "blue", size = 16),
arrowcolor = "white", arrowsize = 1, arrowwidth = 1,arrowhead = 1)
))) %>%
add_trace(x = 0.5, y = -1, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 5, color = "red", symbol = 104)) %>%
add_trace(x = -0.5, y = 0, z = 0, mode = "markers", type = "scatter3d",
marker = list(size = 5, color = "red", symbol = 104)) %>%
add_trace(data = df, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104)) %>%
add_trace(data = df2, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104)) %>%
add_trace(data = df3, x = ~x, y = ~y, z = ~z, mode = "lines", type = "scatter3d",
line = list(width = 2, color = "red", symbol = 104))
Figure 2: Illustration of a function \(f\) (in blue) defined 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\}\). Function \(f:\Gamma\longrightarrow\mathbb{R}\) is the restriction of the surface \(\gamma:\mathbb{R}^2\longrightarrow\mathbb{R}\) to \(\Gamma\), where \(\gamma(x,y) = x^2-y^2\). That is, \(f= \gamma\big|_\Gamma\).
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).