From 7f22e2b4c2144853f54e18a4d597ad5aed52bc56 Mon Sep 17 00:00:00 2001 From: nkoenen Date: Fri, 26 Aug 2022 14:07:15 +0200 Subject: [PATCH 1/9] Bugfix with HTML5 The R version 4.2.0 switched to use HTML5 for the documentation pages and the validation using HTML Tidy found some problems that needed to be fixed: * re-generating .Rd files using the current version of roxygen2 * switch to package version 0.1.1 * update cran-comments.md and NEWS.md --- DESCRIPTION | 4 +-- NEWS.md | 5 ++++ README.Rmd | 4 +-- README.md | 9 ++++--- cran-comments.md | 51 ++++++++++++++++++++++++++++++++++++--- innsight.Rproj | 2 +- man/ConnectionWeights.Rd | 24 +++++++++--------- man/Converter.Rd | 12 ++++----- man/DeepLift.Rd | 38 ++++++++++++++--------------- man/Gradient.Rd | 34 +++++++++++++------------- man/GradientBased.Rd | 38 ++++++++++++++--------------- man/InterpretingMethod.Rd | 18 +++++++------- man/LRP.Rd | 38 ++++++++++++++--------------- man/SmoothGrad.Rd | 34 +++++++++++++------------- 14 files changed, 181 insertions(+), 130 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a8dcbab..3f2d170 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: innsight Title: Get the Insights of your Neural Network -Version: 0.1.0 +Version: 0.1.1 Authors@R: c(person(given = "Niklas", family = "Koenen", @@ -46,7 +46,7 @@ VignetteBuilder: Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE, r6 = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.1 Collate: 'ConnectionWeights.R' 'Convert_keras.R' diff --git a/NEWS.md b/NEWS.md index 8d9b073..c48d23f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# innsight 0.1.1 + +* Fix problem with old HTML version of the manual by re-generating the +`.Rd` files using the current CRAN version of roxygen2. + # innsight 0.1.0 * Added a `NEWS.md` file to track changes to the package. diff --git a/README.Rmd b/README.Rmd index f2d720f..0242c65 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,7 +13,7 @@ knitr::opts_chunk$set( ``` # `innsight` - Get the Insights of your Neural Network - + [![R-CMD-check](https://github.com/bips-hb/innsight/workflows/R-CMD-check/badge.svg)](https://github.com/bips-hb/innsight/actions) @@ -61,7 +61,7 @@ Example results for these methods on ImageNet with pretrained network Vgg16: The package `innsight` aims to be as flexible as possible and independent of a specific deep learning package in which the passed network has been learned. -Basically, a neural network of the libraries [`torch`](https://torch.mlverse.org/), [`keras`](https://keras.rstudio.com/) and [`neuralnet`](https://CRAN.R-project.org/package=neuralnet) +Basically, a neural network of the libraries [`torch`](https://torch.mlverse.org/), [`keras`](https://tensorflow.rstudio.com/) and [`neuralnet`](https://CRAN.R-project.org/package=neuralnet) can be passed, which is internally converted into a [`torch`](https://torch.mlverse.org/) model with special insights needed for interpretation. Currently, the following model and layer types are accepted: diff --git a/README.md b/README.md index 1501d0b..d141e55 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # `innsight` - Get the Insights of your Neural Network - + @@ -39,7 +39,10 @@ Attribution) methods based on neural networks in R, e.g., - Layer-wise Relevance Propagation ([LRP](https://doi.org/10.1371/journal.pone.0130140)) - - Including propagation rules: *ε*-rule and *α*-*β*-rule + - Including propagation rules: + ![\\varepsilon](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cvarepsilon "\varepsilon")-rule + and + ![\\alpha](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Calpha "\alpha")-![\\beta](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Cbeta "\beta")-rule - Deep Learning Important Features ([DeepLift](https://arxiv.org/abs/1704.02685)) - Including propagation rules for non-linearities: rescale rule @@ -60,7 +63,7 @@ The package `innsight` aims to be as flexible as possible and independent of a specific deep learning package in which the passed network has been learned. Basically, a neural network of the libraries [`torch`](https://torch.mlverse.org/), -[`keras`](https://keras.rstudio.com/) and +[`keras`](https://tensorflow.rstudio.com/) and [`neuralnet`](https://CRAN.R-project.org/package=neuralnet) can be passed, which is internally converted into a [`torch`](https://torch.mlverse.org/) model with special insights needed diff --git a/cran-comments.md b/cran-comments.md index 83e1f0e..ab80544 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,9 +1,51 @@ -## Test environments with LibTorch +## --- `innsight` 0.1.1 ------------------------------------------------------ + +### Test environments with LibTorch + +### Test environments without LibTorch +- R-hub Windows Server 2022, R-devel, 64 bit +- R-hub Ubuntu Linux 20.04.1 LTS, R-release, GCC +- R-hub Fedora Linux, R-devel, clang, gfortran + +#### R CMD check results + +There were no errors or warnings only two notes: + +* One on Windows: a bug in `rhub` that can be ignored ([see here](https://github.com/r-hub/rhub/issues/503#issue-1105809885/)) +``` + Build ID: innsight_0.1.1.tar.gz-5b65ac0c5d8648e88cdc6f523893c731 + Platform: Windows Server 2022, R-devel, 64 bit + Submitted: 1h 1m 3.8s ago + Build time: 4m 42.9s + +❯ checking for detritus in the temp directory ... NOTE + Found the following files/directories: + 'lastMiKTeXException' + +0 errors ✔ | 0 warnings ✔ | 1 note ✖ +``` + +* One note on Linux that is irrelevant for the submission +``` + Build ID: innsight_0.1.1.tar.gz-831d4fbd980b4a5eaba89f9f69499522 + Platform: Fedora Linux, R-devel, clang, gfortran + Submitted: 1h 1m 3.8s ago + Build time: 31m 21.3s + +❯ checking HTML version of manual ... NOTE + Skipping checking HTML validation: no command 'tidy' found + Skipping checking math rendering: package 'V8' unavailable + +0 errors ✔ | 0 warnings ✔ | 1 note ✖ +``` +## --- `innsight` 0.1.0 ------------------------------------------------------ + +### Test environments with LibTorch * GitHub Actions (ubuntu-18.04): 3.5, 3.6, 4.0, release, devel * GitHub Actions (windows): 3.6, release * Github Actions (macOS): release -## R CMD check results +#### R CMD check results There were no errors or notes and the following warning occurred only on the operating system Windows (see @@ -28,7 +70,7 @@ of torch (see torch [issue #651](https://github.com/mlverse/torch/issues/651#issuecomment-896783144)) and disabled their execution on CRAN. -## Test environments without LibTorch +### Test environments without LibTorch - R-hub windows-x86_64-devel (r-devel) - R-hub ubuntu-gcc-release (r-release) - R-hub fedora-clang-devel (r-devel) @@ -36,7 +78,7 @@ and disabled their execution on CRAN. - Win-builder (r-release) - Win-builder (r-devel) -## R CMD check results +#### R CMD check results There were no errors or warnings only one note: New submission and irrelevant misspellings in names in DESCRIPTION: @@ -57,3 +99,4 @@ checking CRAN incoming feasibility ... NOTE 0 errors ✓ | 0 warnings ✓ | 1 note x ``` + diff --git a/innsight.Rproj b/innsight.Rproj index ff8f85a..42b95bd 100644 --- a/innsight.Rproj +++ b/innsight.Rproj @@ -19,4 +19,4 @@ BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageCheckArgs: --as-cran -PackageRoxygenize: rd,namespace,vignette +PackageRoxygenize: rd,collate,namespace,vignette diff --git a/man/ConnectionWeights.Rd b/man/ConnectionWeights.Rd index ca422d1..c468239 100644 --- a/man/ConnectionWeights.Rd +++ b/man/ConnectionWeights.Rd @@ -157,15 +157,15 @@ first 10) are considered.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{ConnectionWeights$new()}} -\item \href{#method-get_result}{\code{ConnectionWeights$get_result()}} -\item \href{#method-plot}{\code{ConnectionWeights$plot()}} -\item \href{#method-clone}{\code{ConnectionWeights$clone()}} +\item \href{#method-ConnectionWeights-new}{\code{ConnectionWeights$new()}} +\item \href{#method-ConnectionWeights-get_result}{\code{ConnectionWeights$get_result()}} +\item \href{#method-ConnectionWeights-plot}{\code{ConnectionWeights$plot()}} +\item \href{#method-ConnectionWeights-clone}{\code{ConnectionWeights$clone()}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ConnectionWeights-new}{}}} \subsection{Method \code{new()}}{ \subsection{Usage}{ \if{html}{\out{
}}\preformatted{ConnectionWeights$new( @@ -198,8 +198,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-get_result}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ConnectionWeights-get_result}{}}} \subsection{Method \code{get_result()}}{ This function returns the result of the \emph{Connection Weights} method either as an array (\code{'array'}), a torch tensor (\code{'torch.tensor'} or @@ -224,8 +224,8 @@ type. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-plot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ConnectionWeights-plot}{}}} \subsection{Method \code{plot()}}{ This method visualizes the result of the \emph{ConnectionWeights} method in a \link[ggplot2:ggplot]{ggplot2::ggplot}. You can use the argument \code{output_idx} to select @@ -281,8 +281,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ConnectionWeights-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/Converter.Rd b/man/Converter.Rd index e3fafc0..705711f 100644 --- a/man/Converter.Rd +++ b/man/Converter.Rd @@ -293,13 +293,13 @@ the argument \code{save_model_as_list} this can be saved anyway.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{Converter$new()}} -\item \href{#method-clone}{\code{Converter$clone()}} +\item \href{#method-Converter-new}{\code{Converter$new()}} +\item \href{#method-Converter-clone}{\code{Converter$clone()}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Converter-new}{}}} \subsection{Method \code{new()}}{ Create a new Converter for a given neural network. \subsection{Usage}{ @@ -364,8 +364,8 @@ A new instance of the R6 class \code{'Converter'}. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Converter-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/DeepLift.Rd b/man/DeepLift.Rd index 84b4e02..2cd6131 100644 --- a/man/DeepLift.Rd +++ b/man/DeepLift.Rd @@ -174,22 +174,22 @@ for the non-linear part of a neural network layer. Either \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{DeepLift$new()}} -\item \href{#method-plot}{\code{DeepLift$plot()}} -\item \href{#method-boxplot}{\code{DeepLift$boxplot()}} -\item \href{#method-clone}{\code{DeepLift$clone()}} +\item \href{#method-DeepLift-new}{\code{DeepLift$new()}} +\item \href{#method-DeepLift-plot}{\code{DeepLift$plot()}} +\item \href{#method-DeepLift-boxplot}{\code{DeepLift$boxplot()}} +\item \href{#method-DeepLift-clone}{\code{DeepLift$clone()}} } } -\if{html}{ -\out{
Inherited methods} -\itemize{ -\item \out{}\href{../../innsight/html/InterpretingMethod.html#method-get_result}{\code{innsight::InterpretingMethod$get_result()}}\out{} -} -\out{
} -} +\if{html}{\out{ +
Inherited methods + +
+}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DeepLift-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of the DeepLift method. \subsection{Usage}{ @@ -241,8 +241,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-plot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DeepLift-plot}{}}} \subsection{Method \code{plot()}}{ This method visualizes the result of the selected method in a \link[ggplot2:ggplot]{ggplot2::ggplot}. You can use the argument \code{data_idx} to select @@ -300,8 +300,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-boxplot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DeepLift-boxplot}{}}} \subsection{Method \code{boxplot()}}{ This function visualizes the results of this method in a boxplot, where the type of visualization depends on the input dimension of the data. @@ -391,8 +391,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DeepLift-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/Gradient.Rd b/man/Gradient.Rd index 8ac8ba2..6966021 100644 --- a/man/Gradient.Rd +++ b/man/Gradient.Rd @@ -156,22 +156,22 @@ plotly::ggplotly(p, tooltip = "text") \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{Gradient$new()}} -\item \href{#method-clone}{\code{Gradient$clone()}} -} -} -\if{html}{ -\out{
Inherited methods} -\itemize{ -\item \out{}\href{../../innsight/html/InterpretingMethod.html#method-get_result}{\code{innsight::InterpretingMethod$get_result()}}\out{} -\item \out{}\href{../../innsight/html/GradientBased.html#method-boxplot}{\code{innsight::GradientBased$boxplot()}}\out{} -\item \out{}\href{../../innsight/html/GradientBased.html#method-plot}{\code{innsight::GradientBased$plot()}}\out{} -} -\out{
} -} +\item \href{#method-Gradient-new}{\code{Gradient$new()}} +\item \href{#method-Gradient-clone}{\code{Gradient$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Gradient-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of the Vanilla Gradient method. \subsection{Usage}{ @@ -218,8 +218,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Gradient-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/GradientBased.Rd b/man/GradientBased.Rd index 2b2677c..864c24c 100644 --- a/man/GradientBased.Rd +++ b/man/GradientBased.Rd @@ -27,22 +27,22 @@ This method is called 'Gradient x Input'.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{GradientBased$new()}} -\item \href{#method-plot}{\code{GradientBased$plot()}} -\item \href{#method-boxplot}{\code{GradientBased$boxplot()}} -\item \href{#method-clone}{\code{GradientBased$clone()}} +\item \href{#method-GradientBased-new}{\code{GradientBased$new()}} +\item \href{#method-GradientBased-plot}{\code{GradientBased$plot()}} +\item \href{#method-GradientBased-boxplot}{\code{GradientBased$boxplot()}} +\item \href{#method-GradientBased-clone}{\code{GradientBased$clone()}} } } -\if{html}{ -\out{
Inherited methods} -\itemize{ -\item \out{}\href{../../innsight/html/InterpretingMethod.html#method-get_result}{\code{innsight::InterpretingMethod$get_result()}}\out{} -} -\out{
} -} +\if{html}{\out{ +
Inherited methods + +
+}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-GradientBased-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of this class. \subsection{Usage}{ @@ -89,8 +89,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-plot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-GradientBased-plot}{}}} \subsection{Method \code{plot()}}{ This method visualizes the result of the selected method in a \link[ggplot2:ggplot]{ggplot2::ggplot}. You can use the argument \code{data_idx} to select @@ -148,8 +148,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-boxplot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-GradientBased-boxplot}{}}} \subsection{Method \code{boxplot()}}{ This function visualizes the results of this method in a boxplot, where the type of visualization depends on the input dimension of the data. @@ -239,8 +239,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-GradientBased-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/InterpretingMethod.Rd b/man/InterpretingMethod.Rd index ad4db68..640cf50 100644 --- a/man/InterpretingMethod.Rd +++ b/man/InterpretingMethod.Rd @@ -48,14 +48,14 @@ first 10) are considered.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{InterpretingMethod$new()}} -\item \href{#method-get_result}{\code{InterpretingMethod$get_result()}} -\item \href{#method-clone}{\code{InterpretingMethod$clone()}} +\item \href{#method-InterpretingMethod-new}{\code{InterpretingMethod$new()}} +\item \href{#method-InterpretingMethod-get_result}{\code{InterpretingMethod$get_result()}} +\item \href{#method-InterpretingMethod-clone}{\code{InterpretingMethod$clone()}} } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-InterpretingMethod-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of this super class. \subsection{Usage}{ @@ -97,8 +97,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-get_result}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-InterpretingMethod-get_result}{}}} \subsection{Method \code{get_result()}}{ This function returns the result of this method for the given data either as an array (\code{'array'}), a torch tensor (\code{'torch.tensor'}, @@ -123,8 +123,8 @@ type. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-InterpretingMethod-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/LRP.Rd b/man/LRP.Rd index dc26bd3..dc00034 100644 --- a/man/LRP.Rd +++ b/man/LRP.Rd @@ -199,22 +199,22 @@ are calculated. Implemented are \code{"simple"}, \code{"epsilon"}, \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{LRP$new()}} -\item \href{#method-plot}{\code{LRP$plot()}} -\item \href{#method-boxplot}{\code{LRP$boxplot()}} -\item \href{#method-clone}{\code{LRP$clone()}} +\item \href{#method-LRP-new}{\code{LRP$new()}} +\item \href{#method-LRP-plot}{\code{LRP$plot()}} +\item \href{#method-LRP-boxplot}{\code{LRP$boxplot()}} +\item \href{#method-LRP-clone}{\code{LRP$clone()}} } } -\if{html}{ -\out{
Inherited methods} -\itemize{ -\item \out{}\href{../../innsight/html/InterpretingMethod.html#method-get_result}{\code{innsight::InterpretingMethod$get_result()}}\out{} -} -\out{
} -} +\if{html}{\out{ +
Inherited methods + +
+}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LRP-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of the LRP-Method. \subsection{Usage}{ @@ -271,8 +271,8 @@ A new instance of the R6 class \code{'LRP'}. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-plot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LRP-plot}{}}} \subsection{Method \code{plot()}}{ This method visualizes the result of the selected method in a \link[ggplot2:ggplot]{ggplot2::ggplot}. You can use the argument \code{data_idx} to select @@ -330,8 +330,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-boxplot}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LRP-boxplot}{}}} \subsection{Method \code{boxplot()}}{ This function visualizes the results of this method in a boxplot, where the type of visualization depends on the input dimension of the data. @@ -421,8 +421,8 @@ Returns either a \link[ggplot2:ggplot]{ggplot2::ggplot} (\code{as_plotly = FALSE } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LRP-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ diff --git a/man/SmoothGrad.Rd b/man/SmoothGrad.Rd index f2e743d..5268524 100644 --- a/man/SmoothGrad.Rd +++ b/man/SmoothGrad.Rd @@ -164,22 +164,22 @@ perturbation, i.e. \eqn{\sigma = (max(x) - min(x)) *} \code{noise_level}.} \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-new}{\code{SmoothGrad$new()}} -\item \href{#method-clone}{\code{SmoothGrad$clone()}} -} -} -\if{html}{ -\out{
Inherited methods} -\itemize{ -\item \out{}\href{../../innsight/html/InterpretingMethod.html#method-get_result}{\code{innsight::InterpretingMethod$get_result()}}\out{} -\item \out{}\href{../../innsight/html/GradientBased.html#method-boxplot}{\code{innsight::GradientBased$boxplot()}}\out{} -\item \out{}\href{../../innsight/html/GradientBased.html#method-plot}{\code{innsight::GradientBased$plot()}}\out{} -} -\out{
} -} +\item \href{#method-SmoothGrad-new}{\code{SmoothGrad$new()}} +\item \href{#method-SmoothGrad-clone}{\code{SmoothGrad$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-new}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-SmoothGrad-new}{}}} \subsection{Method \code{new()}}{ Create a new instance of the SmoothGrad method. \subsection{Usage}{ @@ -233,8 +233,8 @@ either \code{'float'} for \link[torch:torch_dtype]{torch::torch_float} or \code{ } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-clone}{}}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-SmoothGrad-clone}{}}} \subsection{Method \code{clone()}}{ The objects of this class are cloneable with this method. \subsection{Usage}{ From e8455c9ba5290520094b0e21066f07096061bc3a Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 09:26:15 +0200 Subject: [PATCH 2/9] Update GitHub actions and add workflow for test coverage --- .Rbuildignore | 1 + .github/workflows/R-CMD-check.yaml | 117 ++++++++++++++------------- .github/workflows/pkgdown.yaml | 53 +++++------- .github/workflows/pr-commands.yaml | 79 ++++++++++++++++++ .github/workflows/test-coverage.yaml | 31 +++++++ DESCRIPTION | 1 + README.Rmd | 3 +- README.md | 4 +- codecov.yml | 14 ++++ 9 files changed, 213 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/pr-commands.yaml create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 codecov.yml diff --git a/.Rbuildignore b/.Rbuildignore index 14cc4ad..6ea7fe3 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ ^images$ ^man/images$ ^cran-comments\.md$ +^codecov\.yml$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 6b1a32b..e5b127d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,4 +1,4 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help # # NOTE: This workflow is overkill for most R packages and @@ -12,32 +12,45 @@ on: name: R-CMD-check +defaults: + run: + shell: Rscript {0} + jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + name: ${{ matrix.config.os }} (tf-${{ matrix.config.tf }}, R-${{ matrix.config.r }}) strategy: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: 'ubuntu-20.04', tf: 'default', r: 'devel', http-user-agent: 'release'} + + - {os: 'ubuntu-20.04' , tf: 'default', r: 'release'} + - {os: 'windows-latest', tf: 'default', r: 'release'} + - {os: 'macOS-latest' , tf: 'default', r: 'release'} - - {os: windows-latest, r: 'release'} - # Use 3.6 to trigger usage of RTools35 - - {os: windows-latest, r: '3.6'} + - {os: 'ubuntu-20.04' , tf: 'default', r: 'oldrel'} + - {os: 'windows-latest', tf: 'default', r: 'oldrel'} + # Use 3.6 to trigger usage of RTools35 + - {os: 'windows-latest', tf: 'default', r: '3.6'} - # Use older ubuntu to maximise backward compatibility - - {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-18.04, r: 'release'} - - {os: ubuntu-18.04, r: 'oldrel-1'} - - {os: ubuntu-18.04, r: 'oldrel-2'} - - {os: ubuntu-18.04, r: 'oldrel-3'} + - {os: 'ubuntu-20.04', tf: 'default', r: 'oldrel-1'} + - {os: 'ubuntu-20.04', tf: 'default', r: '3.6'} + - {os: 'ubuntu-20.04', tf: 'default', r: '3.5'} + + - {os: 'ubuntu-20.04', tf: '2.8', r: 'release'} + - {os: 'ubuntu-20.04', tf: '2.7', r: 'release'} + - {os: 'ubuntu-20.04', tf: '2.6', r: 'release'} + - {os: 'ubuntu-20.04', tf: '2.5', r: 'release'} + - {os: 'ubuntu-20.04', tf: '2.4', r: 'release'} + - {os: 'ubuntu-20.04', tf: '2.3', r: 'release'} env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: 'true' GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: yes TORCH_TEST: 1 steps: @@ -45,78 +58,68 @@ jobs: - uses: r-lib/actions/setup-pandoc@v1 - - uses: r-lib/actions/setup-r@v1 - id: install-r + - uses: r-lib/actions/setup-r@v2 + id: setup-r with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - name: Install pak and query dependencies + - name: Get Date + id: get-date + shell: bash run: | - install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") - pak::pak_install_extra() - saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds") - shell: Rscript {0} + echo "::set-output name=year-week::$(date -u "+%Y-%U")" + echo "::set-output name=date::$(date -u "+%F")" - name: Restore R package cache uses: actions/cache@v2 + id: r-package-cache with: - path: | - ${{ env.R_LIBS_USER }}/* - !${{ env.R_LIBS_USER }}/pak - key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }} - restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1- + path: ${{ env.R_LIBS_USER }} + key: ${{ matrix.config.os }}-${{ steps.setup-r.outputs.installed-r-version }}-${{ steps.get-date.outputs.year-week }} + + - name: Install remotes + if: steps.r-package-cache.outputs.cache-hit != 'true' + run: install.packages("remotes") - name: Install system dependencies if: runner.os == 'Linux' + shell: bash run: | - pak::local_system_requirements(execute = TRUE) - pak::pkg_system_requirements("rcmdcheck", execute = TRUE) - shell: Rscript {0} + . /etc/os-release + while read -r cmd + do + echo "$cmd" + sudo $cmd + done < <(Rscript -e "writeLines(remotes::system_requirements('$ID-$VERSION_ID'))") - - name: Install dependencies - run: | - pak::local_install_dev_deps(upgrade = TRUE) - pak::pkg_install("rcmdcheck") - shell: Rscript {0} + - name: Install Package + deps + run: remotes::install_local(dependencies = TRUE, force = TRUE) - name: Install Miniconda - run: | - install.packages("reticulate") - if (.Platform$OS.type == 'windows') { - reticulate::conda_create(packages = c("python=3.7", "numpy")) - } else { - reticulate::install_miniconda() - } - shell: Rscript {0} - - - name: Install TensorFlow + Keras - run: | - keras::install_keras() - shell: Rscript {0} + run: reticulate::install_miniconda() + + - name: Install Tensorflow + Keras deps + run: keras::install_keras(tensorflow = '${{ matrix.config.tf }}-cpu') - name: Install LibTorch - run: | - torch::install_torch() - shell: Rscript {0} + run: torch::install_torch() + + - name: Install rcmdcheck + run: remotes::install_cran("rcmdcheck") - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check") - shell: Rscript {0} + run: rcmdcheck::rcmdcheck(args = c('--no-manual', '--as-cran'), error_on = 'error', check_dir = 'check') - name: Show testthat output if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true shell: bash + run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - name: Upload check results if: failure() uses: actions/upload-artifact@main with: - name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results + name: ${{ matrix.config.os }}-tf${{ matrix.config.tf }}-r${{ matrix.config.r }}-results path: check diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 38d3322..0b26021 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,55 +1,46 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: branches: [main, master] - paths: - - "man/*" - - "_pkgdown.yml" - - "pkgdown" - - "NEWS.md" - - "README.Rmd" - - "vignettes" + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: name: pkgdown jobs: pkgdown: runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: pkgdown + extra-packages: any::pkgdown, local::. needs: website - - name: Install Miniconda - run: | - install.packages("reticulate") - reticulate::install_miniconda() - shell: Rscript {0} - - - name: Install TensorFlow + Keras - run: | - keras::install_keras() + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) shell: Rscript {0} - - name: Install LibTorch - run: | - torch::install_torch() - shell: Rscript {0} - - - name: Deploy package - run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@4.1.4 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 0000000..97271eb --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,79 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + issue_comment: + types: [created] + +name: Commands + +jobs: + document: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} + name: document + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::roxygen2 + needs: pr-document + + - name: Document + run: roxygen2::roxygenise() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE + git commit -m 'Document' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + style: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} + name: style + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + + - name: Install dependencies + run: install.packages("styler") + shell: Rscript {0} + + - name: Style + run: styler::style_pkg() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add \*.R + git commit -m 'Style' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..4b65418 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,31 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: covr::codecov(quiet = FALSE) + shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index 3f2d170..2a2d88c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: R6, torch Suggests: + covr, keras, knitr, neuralnet, diff --git a/README.Rmd b/README.Rmd index 0242c65..3cf69bc 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,9 +16,10 @@ knitr::opts_chunk$set( -[![R-CMD-check](https://github.com/bips-hb/innsight/workflows/R-CMD-check/badge.svg)](https://github.com/bips-hb/innsight/actions) +[![R-CMD-check](https://github.com/bips-hb/innsight/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bips-hb/innsight/actions/workflows/R-CMD-check.yaml) [![CRAN status](https://www.r-pkg.org/badges/version/innsight)](https://CRAN.R-project.org/package=innsight) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![Codecov test coverage](https://codecov.io/gh/bips-hb/innsight/branch/master/graph/badge.svg)](https://app.codecov.io/gh/bips-hb/innsight?branch=master) ## Table of Contents diff --git a/README.md b/README.md index d141e55..9900303 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,13 @@ -[![R-CMD-check](https://github.com/bips-hb/innsight/workflows/R-CMD-check/badge.svg)](https://github.com/bips-hb/innsight/actions) +[![R-CMD-check](https://github.com/bips-hb/innsight/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bips-hb/innsight/actions/workflows/R-CMD-check.yaml) [![CRAN status](https://www.r-pkg.org/badges/version/innsight)](https://CRAN.R-project.org/package=innsight) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![Codecov test +coverage](https://codecov.io/gh/bips-hb/innsight/branch/master/graph/badge.svg)](https://app.codecov.io/gh/bips-hb/innsight?branch=master) ## Table of Contents diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true From 27687351c81462f4c01d0d0256fde3c12575f97f Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 09:51:03 +0200 Subject: [PATCH 3/9] Add installation of keras and torch for the codecov workflow --- .github/workflows/test-coverage.yaml | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 4b65418..3d6afd9 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -12,7 +12,9 @@ jobs: test-coverage: runs-on: ubuntu-latest env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: 'true' GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + TORCH_TEST: 1 steps: - uses: actions/checkout@v2 @@ -21,6 +23,46 @@ jobs: with: use-public-rspm: true + - name: Get Date + id: get-date + shell: bash + run: | + echo "::set-output name=year-week::$(date -u "+%Y-%U")" + echo "::set-output name=date::$(date -u "+%F")" + + - name: Restore R package cache + uses: actions/cache@v2 + id: r-package-cache + with: + path: ${{ env.R_LIBS_USER }} + key: ubuntu-latest-${{ steps.get-date.outputs.year-week }} + + - name: Install remotes + if: steps.r-package-cache.outputs.cache-hit != 'true' + run: install.packages("remotes") + + - name: Install system dependencies + shell: bash + run: | + . /etc/os-release + while read -r cmd + do + echo "$cmd" + sudo $cmd + done < <(Rscript -e "writeLines(remotes::system_requirements('$ID-$VERSION_ID'))") + + - name: Install Package + deps + run: remotes::install_local(dependencies = TRUE, force = TRUE) + + - name: Install Miniconda + run: reticulate::install_miniconda() + + - name: Install Tensorflow + Keras deps + run: keras::install_keras(tensorflow = 'default-cpu') + + - name: Install LibTorch + run: torch::install_torch() + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::covr From c68393fa583a6ce1df8fc6cceae6ca369fd174cb Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 09:57:28 +0200 Subject: [PATCH 4/9] Bugfix in codecov workflow --- .github/workflows/test-coverage.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 3d6afd9..c8d706b 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -40,6 +40,7 @@ jobs: - name: Install remotes if: steps.r-package-cache.outputs.cache-hit != 'true' run: install.packages("remotes") + shell: Rscript {0} - name: Install system dependencies shell: bash @@ -53,15 +54,19 @@ jobs: - name: Install Package + deps run: remotes::install_local(dependencies = TRUE, force = TRUE) + shell: Rscript {0} - name: Install Miniconda run: reticulate::install_miniconda() + shell: Rscript {0} - name: Install Tensorflow + Keras deps run: keras::install_keras(tensorflow = 'default-cpu') + shell: Rscript {0} - name: Install LibTorch run: torch::install_torch() + shell: Rscript {0} - uses: r-lib/actions/setup-r-dependencies@v2 with: From 63281665ae950934d85af24aab92cfcaf168454c Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 12:05:31 +0200 Subject: [PATCH 5/9] Change dtype of tests for average pooling layers to 'double' due to numeical instabilities --- tests/testthat/test_pooling_layer.R | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/testthat/test_pooling_layer.R b/tests/testthat/test_pooling_layer.R index 5cedeba..65c8766 100644 --- a/tests/testthat/test_pooling_layer.R +++ b/tests/testthat/test_pooling_layer.R @@ -3,11 +3,12 @@ test_that("Test 1D average pooling layer", { library(torch) - x <- torch_randn(10, 4, 30) - x_ref <- torch_randn(1, 4, 30) + x <- torch_randn(c(10, 4, 30), dtype = torch_double()) + x_ref <- torch_randn(c(1, 4, 30), dtype = torch_double()) kernel_size <- c(2) - avg_pool1d <- avg_pool1d_layer(kernel_size, c(4, 30), c(4, 15)) + avg_pool1d <- avg_pool1d_layer(kernel_size, c(4, 30), c(4, 15), + dtype = "double") # Works properly y_true <- nnf_avg_pool1d(x, kernel_size) @@ -19,20 +20,20 @@ test_that("Test 1D average pooling layer", { expect_lt(as_array(mean(y_ref-y_ref_true)), 1e-12) # Test LRP: simple rule - rel_output <- torch_randn(c(10, 4, 15, 3)) + rel_output <- torch_randn(c(10, 4, 15, 3), dtype = torch_double()) rel <- avg_pool1d$get_input_relevances(rel_output) expect_equal(dim(rel), c(10, 4, 30, 3)) - expect_lt(as_array((sum(rel_output) - sum(rel))^2), 1e-3) + expect_lt(as_array((sum(rel_output) - sum(rel))^2), 1e-8) # Test LRP: alpha-beta-rule - rel_output <- torch_randn(c(10, 4, 15, 3)) + rel_output <- torch_randn(c(10, 4, 15, 3), dtype = torch_double()) rel <- avg_pool1d$get_input_relevances(rel_output, rule_name = "alpha_beta") expect_equal(dim(rel), c(10, 4, 30, 3)) # Test DeepLift - multiplier <- torch_randn(c(10, 4, 15, 3)) + multiplier <- torch_randn(c(10, 4, 15, 3), dtype = torch_double()) contrib_true <- (y_true - y_ref_true)$unsqueeze(-1) * multiplier mul <- avg_pool1d$get_input_multiplier(multiplier) contrib <- (x - x_ref)$unsqueeze(-1) * mul @@ -45,11 +46,12 @@ test_that("Test 1D average pooling layer", { test_that("Test 2D average pooling layer", { library(torch) - x <- torch_randn(10, 4, 20, 10) - x_ref <- torch_randn(1, 4, 20, 10) + x <- torch_randn(c(10, 4, 20, 10), dtype = torch_double()) + x_ref <- torch_randn(c(1, 4, 20, 10), dtype = torch_double()) kernel_size <- c(2,2) - avg_pool2d <- avg_pool2d_layer(kernel_size, c(4, 20, 10), c(4, 10, 5)) + avg_pool2d <- avg_pool2d_layer(kernel_size, c(4, 20, 10), c(4, 10, 5), + dtype = "double") # Works properly y_true <- nnf_avg_pool2d(x, kernel_size) @@ -61,11 +63,11 @@ test_that("Test 2D average pooling layer", { expect_lt(as_array(mean(y_ref-y_ref_true)), 1e-12) # Test LRP: simple rule - rel_output <- torch_randn(c(10, 4, 10, 5, 3)) + rel_output <- torch_randn(c(10, 4, 10, 5, 3), dtype = torch_double()) rel <- avg_pool2d$get_input_relevances(rel_output) expect_equal(dim(rel), c(10, 4, 20, 10, 3)) - expect_lt(as_array((sum(rel_output) - sum(rel))^2), 1e-3) + expect_lt(as_array((sum(rel_output) - sum(rel))^2), 1e-8) # Test LRP: alpha-beta-rule rel_output <- torch_randn(c(10, 4, 10, 5, 3)) @@ -75,7 +77,7 @@ test_that("Test 2D average pooling layer", { # Test DeepLift - multiplier <- torch_randn(c(10, 4, 10, 5, 3)) + multiplier <- torch_randn(c(10, 4, 10, 5, 3), dtype = torch_double()) contrib_true <- (y_true - y_ref_true)$unsqueeze(-1) * multiplier mul <- avg_pool2d$get_input_multiplier(multiplier) contrib <- (x - x_ref)$unsqueeze(-1) * mul From 11ba551ab56d2c7939dde8c0199fe1eac99803a8 Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 14:51:38 +0200 Subject: [PATCH 6/9] Do test for correctness with dtype 'double' and fix bug in codecov workflow --- .github/workflows/test-coverage.yaml | 1 - tests/testthat/test_Gradients.R | 5 +++-- tests/testthat/test_LRP.R | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index c8d706b..5a627c2 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -38,7 +38,6 @@ jobs: key: ubuntu-latest-${{ steps.get-date.outputs.year-week }} - name: Install remotes - if: steps.r-package-cache.outputs.cache-hit != 'true' run: install.packages("remotes") shell: Rscript {0} diff --git a/tests/testthat/test_Gradients.R b/tests/testthat/test_Gradients.R index d1f186d..a13dbfb 100644 --- a/tests/testthat/test_Gradients.R +++ b/tests/testthat/test_Gradients.R @@ -500,7 +500,7 @@ test_that("SmoothGrad: Conv2D-Net", { }) -test_that("LRP: Correctness", { +test_that("Correctness Gradient and SmoothGrad", { library(keras) library(torch) @@ -530,7 +530,8 @@ test_that("LRP: Correctness", { grad <- Gradient$new(converter, data, channels_first = FALSE, - times_input = FALSE + times_input = FALSE, + dtype = "double" ) smooth_grad <- SmoothGrad$new(converter, data, diff --git a/tests/testthat/test_LRP.R b/tests/testthat/test_LRP.R index d97cd2f..fe66221 100644 --- a/tests/testthat/test_LRP.R +++ b/tests/testthat/test_LRP.R @@ -391,18 +391,21 @@ test_that("LRP: Correctness", { # test non-fitted model converter <- Converter$new(model) - lrp <- LRP$new(converter, data, channels_first = FALSE) - converter$model(data, channels_first = FALSE, save_last_layer = TRUE) + lrp <- LRP$new(converter, data, channels_first = FALSE, dtype = "double") + converter$model(torch_tensor(data, dtype = torch_double()), + channels_first = FALSE, save_last_layer = TRUE) out <- converter$model$modules_list[[7]]$preactivation lrp_result_sum <- lrp$get_result(type = "torch.tensor")$sum(dim = c(2, 3, 4)) - expect_lt(as.array(mean(abs(lrp_result_sum - out)^2)), 1e-5) + expect_lt(as.array(mean(abs(lrp_result_sum - out)^2)), 1e-12) lrp <- - LRP$new(converter, data, channels_first = FALSE, ignore_last_act = FALSE) - converter$model(data, channels_first = FALSE, save_last_layer = TRUE) + LRP$new(converter, data, channels_first = FALSE, ignore_last_act = FALSE, + dtype = "double") + converter$model(torch_tensor(data, dtype = torch_double()), + channels_first = FALSE, save_last_layer = TRUE) out <- converter$model$modules_list[[7]]$output - 0.5 lrp_result_no_last_act_sum <- lrp$get_result(type = "torch.tensor")$sum(dim = c(2, 3, 4)) - expect_lt(as.array(mean(abs(lrp_result_no_last_act_sum - out)^2)), 1e-5) + expect_lt(as.array(mean(abs(lrp_result_no_last_act_sum - out)^2)), 1e-12) }) From aa3718583a6b0d6ece01c1d7eee9e12cecd2e643 Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 15:03:39 +0200 Subject: [PATCH 7/9] Remove Cache for test-coverage workflow --- .github/workflows/test-coverage.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 5a627c2..77a7f47 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -23,20 +23,6 @@ jobs: with: use-public-rspm: true - - name: Get Date - id: get-date - shell: bash - run: | - echo "::set-output name=year-week::$(date -u "+%Y-%U")" - echo "::set-output name=date::$(date -u "+%F")" - - - name: Restore R package cache - uses: actions/cache@v2 - id: r-package-cache - with: - path: ${{ env.R_LIBS_USER }} - key: ubuntu-latest-${{ steps.get-date.outputs.year-week }} - - name: Install remotes run: install.packages("remotes") shell: Rscript {0} From e30b579d10d60a2973d43072feb77633fe11b84c Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 15:21:48 +0200 Subject: [PATCH 8/9] Increase theshold value for tests with package 'neuralnet' --- tests/testthat/test_Converter.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test_Converter.R b/tests/testthat/test_Converter.R index a3132bc..fd30f4b 100644 --- a/tests/testthat/test_Converter.R +++ b/tests/testthat/test_Converter.R @@ -340,6 +340,7 @@ test_that("Test neuralnet model", { # nn <- neuralnet((Species == "setosa") ~ Petal.Length + Petal.Width, iris, + threshold = 0.8, linear.output = TRUE, hidden = c(3, 2), act.fct = "tanh", rep = 3 ) @@ -347,6 +348,7 @@ test_that("Test neuralnet model", { nn <- neuralnet((Species == "setosa") ~ Petal.Length + Petal.Width, iris, + threshold = 0.8, linear.output = FALSE, hidden = c(3, 2), act.fct = "tanh", rep = 1 ) From 9e7c5318d98cca42df80ec7327ac19818ea553a0 Mon Sep 17 00:00:00 2001 From: nkoenen Date: Mon, 29 Aug 2022 15:58:29 +0200 Subject: [PATCH 9/9] Update 'cran-comments.md' --- cran-comments.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index ab80544..c034874 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,6 +2,35 @@ ### Test environments with LibTorch +### Test environments with LibTorch +* GitHub Actions (ubuntu-20.04): 3.5, 3.6, 4.0, release, devel +* GitHub Actions (windows): 3.6, release +* Github Actions (macOS): release + +#### R CMD check results + +There were no errors or relevant notes and the following warning occurred only on the +operating system Windows: + +``` +Warning: Found the following significant warnings: + Warning: Torch failed to start, restart your R session to try again. +``` +This warning comes from the fact that the Windows machine has an old version +of Microsoft Visual C++ Redistributable (version 10.0.40219 from 2010) +preinstalled, but according to the torch +[issue #246](https://github.com/mlverse/torch/issues/246#issuecomment-695097121), +the latest version is required. + +In addition, we can't run examples, tests or vignettes on CRAN, as this +requires a successful installation of LibTorch. Every implemented method +relies on an instance of 'Converter' that converts a passed model to a +torch model, so any possibility of examples or (non-trivial) tests requires +LibTorch. In this regard, we have followed the recommendations of the authors +of torch (see torch +[issue #651](https://github.com/mlverse/torch/issues/651#issuecomment-896783144)) +and disabled their execution on CRAN. + ### Test environments without LibTorch - R-hub Windows Server 2022, R-devel, 64 bit - R-hub Ubuntu Linux 20.04.1 LTS, R-release, GCC