# Replication Scripts
This repository contains replication scripts, written in R, for the numerical results presented in the paper [Sparse Precision Matrix Estimation With SQUIC](https://dx.doi.org/10.2139/ssrn.3904001). Before executing the scripts, make sure that you have installed the library $\mathtt{libSQUIC}$ and its R interface. A short overview of the different tests is given below as well as in Section 5 of the [User Manual](https://www.gitlab.ci.inf.usi.ch/SQUIC/gitlab-profile/-/raw/main/SQUIC_User_Manual.pdf).

Notes:
1) All test for SNETCH (https://github.com/vladisav/SNETCH) are carried out in the folder `test_SNETCH`.
2) The default location for the dataset is in this folder.

### Datasets & Dependencies
Due to their size, all data used for the synthetic tests ([Tests with Synthetic Datasets](#tests-with-synthetic-datasets)) are separately stored and available for download at https://drive.switch.ch/index.php/s/Avxc8ugzHXvW5jN, each consisting of n=500 samples (total size of ~20 GB). The following operations will download the datasets and unzip them to the default location:
```bash
curl -o temp.zip https://drive.switch.ch/index.php/s/Avxc8ugzHXvW5jN/download
unzip temp.zip -d squic_test_db/
```
All required R packages for the test outlined in the manuscript can be installed by executing `Rscript install_dependencies.R`, this includes the  real-world datasets on ([Microarray Classification](#microarray-classification-with-matrix-tuning-parameter-test_ldar)). 

_The default location of the dataset is assumed to be `Replication/squic_test_db`. If this is changed, please modify the file `Replication/load_data.R` accordingly. These packages are not dependencies of
SQUIC, but are used in the numerical experiments._

## Tests with Synthetic Datasets
For standardized comparisons synthetic test cases stemming from $p$-variate Gaussian random variables with predefined precision matrices, one with a tridiagonal structure and one with local clusters, were generated. They are employed to analyze the behaviour and performance of SQUIC, also in comparison to other methods. Below a quick overview of the different tests is provided and the relevant scripts are linked. Please see the original [paper](https://dx.doi.org/10.2139/ssrn.3904001) for an in-depth review. 

### Sparse Approximate Matrix Inversion ([``test_inv.R``](test_inv.R))
Section 4.1.1 provides an analysis of the sparse approximate matrix inversion routine within SQUIC. We examine the impact of the inversion tolerance $\tau_{\text{inv}}$, on the number of nonzero elements of the inverse and the approximation error on the synthetic datasets. Figure 2 provides a graphical representation of the results.

### Accuracy with Scalar Tuning Parameter ([``test_scal_acc.R``](test_scale_acc.R) and [``test_SNETCH/test_scal_acc_SNETCH.m``](test_SNETCH/test_scal_acc_SNETCH.m))
A comparison of the F1-Score for different precision matrix estimation packages with respect to the scalar tuning parameters is prestented in Section 4.1.2, see Figure 3. The packages ``glasso``, ``BigQUIC`` and ``SQUIC`` report very similar F1-scores as they minimize the same objective function. ``SNETCH`` and ``EQUAL`` do not coincide with the above but show a similar overall behaviour. 

### Accuracy with Matrix Tuning Parameter ([``test_mat_acc.R``](test_mat_acc.R))
Section 4.1.3 discusses how using different matrix tuning parameters in scenarios where we have some a priori knowledge of the nonzero pattern of the true precision, can improve the F1-score.
The results are summarized in Figure 4 for different ratios of false positives and false negatives in the matrix tuning parameter with respect to the bias parameter.

### Performance ([``test_perf.R``](test_perf.R) and [``test_SNETCH/test_perf_SNETCH.m``](test_SNETCH/test_perf_SNETCH.m))
A comparison of the run times for various precision matrix estimation packages, applied to the two synthetic testcases with datasets of increasing dimensions, ranging from $5 \cdot 10^2$ to $10^6$, is shown in Section 4.1.4. Figure 4 shows that ``SQUIC`` outperforms the other methods by more than an order of magnitude for all higher-dimensional cases.   

## Microarray Classification with Matrix Tuning Parameter ([``test_lda.R``](test_lda.R))
Section 4.2 dicusses LDA classification of different microarray datasets related to gene expressions using ``SQUIC``. 
The run time and classification accuracy using scalar and matrix tuning parameters are compared in Figure 6. 
The matrix tuning parameters are constructed using a minimal spanning tree approach and improve the classification accuracies for the employed datasets while only inducing a small increase in the standardized run time. 
