-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
99 lines (74 loc) · 3.29 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# gsaot <a href="https://pietrocipolla.github.io/gsaot/"><img src="man/figures/logo.png" align="right" height="139" alt="gsaot website" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/pietrocipolla/gsaot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pietrocipolla/gsaot/actions/workflows/R-CMD-check.yaml)
[![test-coverage](https://github.com/pietrocipolla/gsaot/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/pietrocipolla/gsaot/actions/workflows/test-coverage.yaml)
<!-- badges: end -->
The package `gsaot` provides a set of tools to compute and plot Optimal Transport (OT) based sensitivity indices. The core functions of the package are:
- `ot_indices()`: compute OT indices for multivariate outputs using different solvers for OT (network simplex, Sinkhorn, and so on).
- `ot_indices_wb()`: compute OT indices for univariate or multivariate outputs using the Wasserstein-Bures semi-metric.
- `ot_indices_1d()`: compute OT indices for univariate outputs using OT solution in one dimension.
The package provides also functions to plot the resulting indices and the inner statistics.
## Installation
```r
install.packages("gsaot")
```
You can install the development version of gsaot from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("pietrocipolla/gsaot")
```
### :exclamation: :exclamation: Installation note
The `sinkhorn` and `sinkhorn_log` solvers in `gsaot` greatly benefit from optimization in compilation. To add this option (before package installation), edit your `.R/Makevars` file with the desired flags. Even though different compilers have different options, a common flag to enable a safe level of optimization is
```
CXXFLAGS+=-O2
```
More detailed information on how to customize the R packages compilation can be found in the [R guide](https://cran.r-project.org/doc/manuals/R-admin.html#Customizing-package-compilation).
## Example
We can use a gaussian toy model with three outputs as an example:
```{r example}
library(gsaot)
N <- 1000
mx <- c(1, 1, 1)
Sigmax <- matrix(data = c(1, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 1), nrow = 3)
x1 <- rnorm(N)
x2 <- rnorm(N)
x3 <- rnorm(N)
x <- cbind(x1, x2, x3)
x <- mx + x %*% chol(Sigmax)
A <- matrix(data = c(4, -2, 1, 2, 5, -1), nrow = 2, byrow = TRUE)
y <- t(A %*% t(x))
x <- data.frame(x)
```
After having defined the number of partitions, we compute the sensitivity indices using different solvers. First, Sinkhorn solver and default parameters:
```{r continuation1}
M <- 25
sensitivity_indices <- ot_indices(x, y, M)
sensitivity_indices
```
Second, Network Simplex solver:
```{r continuation2}
sensitivity_indices <- ot_indices(x, y, M, solver = "transport")
sensitivity_indices
```
Third, Wasserstein-Bures solver, with bootstrap:
```{r continuation3}
sensitivity_indices <- ot_indices_wb(x, y, M, boot = TRUE, R = 100)
sensitivity_indices
```
Fourth, we can use the package to compute the sensitivity map on the output:
```{r continuation4}
sensitivity_indices <- ot_indices_smap(x, y, M)
sensitivity_indices
```