-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
95 lines (66 loc) · 3.08 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
---
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
<!-- 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
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
A basic application of the functions implemented in the package:
```{r example}
library(gsaot)
N <- 1000
# Define the inputs distribution
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)
# Sample the inputs
x1 <- rnorm(N)
x2 <- rnorm(N)
x3 <- rnorm(N)
x <- cbind(x1, x2, x3)
x <- mx + x %*% chol(Sigmax)
# Define the (linear) model and the output
A <- matrix(data = c(4, -2, 1, 2, 5, -1), nrow = 2, byrow = TRUE)
y <- t(A %*% t(x))
x <- data.frame(x)
M <- 25
# Compute the sensitivity indices using Sinkhorn's solver and default parameters
sensitivity_indices <- ot_indices(x, y, M)
sensitivity_indices
# Compute the sensitivity indices using the Network Simplex solver and default parameters
sensitivity_indices <- ot_indices(x, y, M, solver = "transport")
sensitivity_indices
# Compute the Wasserstein-Bures indices
sensitivity_indices <- ot_indices_wb(x, y, M, boot = TRUE, R = 100)
sensitivity_indices
# Compute the sensitivity map using 1-dimensional solver
sensitivity_indices <- ot_indices_smap(x, y, M)
sensitivity_indices
```