Installing GRIN

Working in Python and R.

You may not need to install anything. The Analyse page runs the same network in your browser: paste or upload a matrix and it returns the same numbers the packages do, with nothing uploaded anywhere. Install the packages when you want to script an analysis, run a sample, or drive an adaptive design.

Both packages are open source under an MIT licence and wrap identical trained weights, verified to agree to floating-point tolerance.

Where things stand

grintools (Python) and grin (R) are not yet on PyPI and CRAN. Until they are, install from the repository. The instructions below are the supported route, not a workaround, and they install exactly what the paper describes.

  1. Python

    Needs Python 3.9 or newer. There is no PyTorch dependency: the network ships as an ONNX graph and runs under onnxruntime, so the install is small and fast.

    git clone https://github.com/MurraySBennett/grin.git
    pip install "./grin/packages/grintools[plot]"
    # [plot] adds matplotlib, pandas and scipy, which the plots and tutorials use
    
    # check it worked
    python -c "import grintools as gt; \
    print(gt.infer([[83,112,47,11],[38,154,28,33],[15,27,117,94],[6,36,75,136]])[1]['p_PI'])"
    

    That prints a probability of perceptual independence for the example matrix. If you see a number, you are done.

  2. R

    The R package runs the same weights as a TorchScript graph through torch, so no Python installation is needed on the R side. However, torch itself has a second, separate download.

    install.packages(c("torch", "remotes", "jsonlite"))
    install.packages("patchwork")   # optional: combines the plot panels
    
    # libtorch is a SEPARATE ~2 GB download, and this is the slow step
    torch::install_torch()
    torch::torch_tensor(1)        # confirm it actually works
    
    remotes::install_github("MurraySBennett/grin", subdir = "packages/grin")
    
    # check it worked
    library(grin)
    cm <- matrix(c(83,112,47,11, 38,154,28,33,
                   15,27,117,94, 6,36,75,136), nrow = 4, byrow = TRUE)
    grin_infer(cm)$constructs$p_PI
    
  3. Common problems

    torch::install_torch() can report an error and still have succeeded. Run non-interactively it sometimes ends with cannot change value of locked binding for '.torch_can_load' after the download has already completed. Do not trust the exit status. Check with torch::torch_tensor(1) instead. If that returns a tensor, you are fine.

    On Windows with WSL, ~ does not cross the boundary. An R session running on Windows expands ~ to your Windows profile, so a path like ~/projects/grin will not find a clone that lives inside WSL. Use the UNC path, and prefer a built tarball over a directory, since install_local() copies recursively across the mount and tends to fail:

    # built in WSL with:  R CMD build --no-build-vignettes packages/grin
    install.packages(
      "//wsl.localhost/Ubuntu/home/USER/projects/grin/dist/grin_0.1.1.tar.gz",
      repos = NULL, type = "source"
    )
    
  4. Check the optional interval correction

    Both packages ship an off-by-default correction for the interval widths (see Evidence). This verifies it is present and behaving:

    # from a clone of the repository
    Rscript scripts/R/verify_recalibration.R
    # -> twelve checks, all PASS
    

    If cal.calibrated comes back False, the correction file did not ship with your build. The package still works, and you get the network's own intervals.

Next

Analyse data you already have, or see the other tutorials.