Skip to content

Commit

Permalink
Two layer neural networks (#80)
Browse files Browse the repository at this point in the history
* new function for two layer models

* two layer unit tests

* avoid overflow issues

* fix doc error

* test when loss cannot be computed

* tests for tunable values

* update GHA

* update spelling

* use current CRAN torch

* add missing snapshot and remove print snapshots (due to OS differences)

* don't test on R 4.1

* test overflow on M1 mac

---------

Co-authored-by: ‘topepo’ <‘[email protected]’>
  • Loading branch information
topepo and ‘topepo’ authored Jul 16, 2024
1 parent 9b01415 commit 631fe3c
Show file tree
Hide file tree
Showing 16 changed files with 1,562 additions and 555 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -26,18 +28,20 @@ jobs:

- {os: windows-latest, r: 'release'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
TORCH_INSTALL: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -55,4 +59,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
args: 'c("--no-multiarch", "--no-manual")'
build_args: 'c("--no-multiarch", "--no-manual","--compact-vignettes=gs+qpdf")'
23 changes: 17 additions & 6 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
Expand All @@ -16,36 +18,45 @@ jobs:
TORCH_INSTALL: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- 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
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Imports:
rlang (>= 1.1.1),
stats,
tibble,
torch (>= 0.11.0),
torch (>= 0.13.0),
utils
Suggests:
covr,
Expand All @@ -40,4 +40,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ S3method(brulee_mlp,default)
S3method(brulee_mlp,formula)
S3method(brulee_mlp,matrix)
S3method(brulee_mlp,recipe)
S3method(brulee_mlp_two_layer,data.frame)
S3method(brulee_mlp_two_layer,default)
S3method(brulee_mlp_two_layer,formula)
S3method(brulee_mlp_two_layer,matrix)
S3method(brulee_mlp_two_layer,recipe)
S3method(brulee_multinomial_reg,data.frame)
S3method(brulee_multinomial_reg,default)
S3method(brulee_multinomial_reg,formula)
Expand All @@ -39,13 +44,15 @@ S3method(print,brulee_multinomial_reg)
S3method(tunable,brulee_linear_reg)
S3method(tunable,brulee_logistic_reg)
S3method(tunable,brulee_mlp)
S3method(tunable,brulee_mlp_two_layer)
S3method(tunable,brulee_multinomial_reg)
export("%>%")
export(autoplot)
export(brulee_activations)
export(brulee_linear_reg)
export(brulee_logistic_reg)
export(brulee_mlp)
export(brulee_mlp_two_layer)
export(brulee_multinomial_reg)
export(coef)
export(matrix_to_dataset)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# brulee (development version)

* Added a convenience function, `brulee_mlp_two_layer()`, to more easily fit two-layer networks with parsnip.

# brulee 0.3.0

* Fixed bug where `coef()` didn't would error if used on a `brulee_logistic_reg()` that was trained with a recipe. (#66)
Expand Down
Loading

0 comments on commit 631fe3c

Please sign in to comment.