-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
83 lines (61 loc) · 3.27 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
pas3 <- 'proc_align_slicewise3'
pa3 <- 'proc_align3'
```
# FASE
<!-- badges: start -->
<!-- badges: end -->
The goal of fase is to fit a "Functional Adjacency Spectral Embedding" to an indexed collection of network snapshots. The behavior of each node is summarized by a latent process, which is fit in a prespecifed spline basis. The fase package has options to fit either B-spline (with equally spaced knots) or smoothing spline latent processes. For more details, see [MacDonald et al., (2022+)](https://arxiv.org/abs/2210.07491).
Additional functions are included in this package to do Procrustes alignments of latent processes stored as 3-dimensional arrays.
## Installation
You can install fase from CRAN with:
``` r
install.packages("fase")
```
## Example
This is a basic example which shows you how to generate functional network data and fit a functional adjacency spectral embedding.
First, we generate $50$ snapshots of a functional network on $100$ nodes, with Gaussian edges (standard deviation $\sigma=4$) and two-dimensional sinusoidal latent processes.
```{r simulating}
# load fase package
library(fase)
# set a seed
set.seed(1)
# generate functional network data
data <- gaussian_snapshot_ss(n=100,d=2,
x_vec=seq(0,1,length.out=50),
self_loops=FALSE,
sigma_edge=4)
```
Then we fit a two-dimensional functional adjacency spectral embedding to this data, using a $B$-spline basis design
with dimension $9$.
This choice of basis dimension is chosen to minimize the network generalized cross validation criterion.
As a post-processing step, and due to the intrinsic non-identifiability of the latent processes, we align our embedding to the original processes used to fit the data. Note that by using `r pa3` (rather than `r pas3`), we apply the same orthogonal transformation to all the evaluations of the latent process snapshots. The difference between slicewise and common identifying transformations is discussed in more detail in [MacDonald et al., (2022+)](https://arxiv.org/abs/2210.07491), Appendix C.
```{r embedding}
# embed with fase (B-spline design)
fit <- fase(data$A,d=2,self_loops=FALSE,
spline_design=list(type='bs',q=9,x_vec=data$spline_design$x_vec))
# align fitted and true latent processes
Z_align <- proc_align3(fit$Z,data$Z)
```
Finally, we extract a couple of example estimated (and aligned) latent processes: the first dimension for node 34, and the second dimension for node 54. We plot them against the true values over the entire index space.
```{r plotting, echo = FALSE}
par(mfrow=c(1,2))
plot(data$spline_design$x_vec,data$Z[34,1,],type='l',
xlab='x',ylab='Z_{34,1}(x)',ylim=c(-3,3))
lines(data$spline_design$x_vec,Z_align[34,1,],type='l',col='blue')
legend(x=0.35,y=-1.5,legend=c('True','Estimated'),
lty=1,pch=NA,col=c('black','blue'),cex=0.6)
plot(data$spline_design$x_vec,data$Z[54,2,],type='l',
xlab='x',ylab='Z_{54,2}(x)',ylim=c(-3,3))
lines(data$spline_design$x_vec,Z_align[54,2,],type='l',col='blue')
```