Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear activation function leads to "object of type 'closure' is not subsettable" error #68

Closed
christophscheuch opened this issue Oct 5, 2023 · 3 comments · Fixed by #89
Labels
bug an unexpected problem or unintended behavior

Comments

@christophscheuch
Copy link

The problem

I cannot use linear activation functions in brulee_mlp(). I instead get my favorite R error :)

Reproducible example

library(brulee)
library(recipes)
library(yardstick)

data(bivariate, package = "modeldata")
set.seed(20)
nn_log_biv <- brulee_mlp(Class ~ log(A) + log(B), data = bivariate_train, 
                         epochs = 150, hidden_units = 3, activation = "linear")
#> Error in x$parameters: object of type 'closure' is not subsettable

Session info

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_Austria.utf8  LC_CTYPE=English_Austria.utf8   
[3] LC_MONETARY=English_Austria.utf8 LC_NUMERIC=C                    
[5] LC_TIME=English_Austria.utf8    

time zone: Europe/Vienna
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] yardstick_1.2.0 brulee_0.2.0    recipes_1.0.6   dplyr_1.1.2    

loaded via a namespace (and not attached):
 [1] utf8_1.2.3          future_1.32.0       generics_0.1.3     
 [4] class_7.3-22        lattice_0.21-8      listenv_0.9.0      
 [7] digest_0.6.31       magrittr_2.0.3      grid_4.3.1         
[10] timechange_0.2.0    rprojroot_2.0.3     Matrix_1.5-4.1     
[13] processx_3.8.2      nnet_7.3-19         survival_3.5-5     
[16] torch_0.11.0        ps_1.7.5            purrr_1.0.1        
[19] fansi_1.0.4         scales_1.2.1        coro_1.0.3         
[22] codetools_0.2-19    lava_1.7.2.1        cli_3.6.1          
[25] rlang_1.1.1         hardhat_1.3.0       parallelly_1.36.0  
[28] future.apply_1.11.0 munsell_0.5.0       bit64_4.0.5        
[31] splines_4.3.1       withr_2.5.0         prodlim_2023.03.31 
[34] tools_4.3.1         parallel_4.3.1      colorspace_2.1-0   
[37] ggplot2_3.4.3       globals_0.16.2      vctrs_0.6.2        
[40] R6_2.5.1            rpart_4.1.19        lifecycle_1.0.3    
[43] lubridate_1.9.2     bit_4.0.5           MASS_7.3-60        
[46] desc_1.4.2          pkgconfig_2.0.3     callr_3.7.3        
[49] gtable_0.3.3        pillar_1.9.0        data.table_1.14.8  
[52] glue_1.6.2          Rcpp_1.0.10         tibble_3.2.1       
[55] tidyselect_1.2.0    ipred_0.9-14        timeDate_4022.108  
[58] gower_1.0.1         compiler_4.3.1 
@EmilHvitfeldt EmilHvitfeldt added the bug an unexpected problem or unintended behavior label Oct 5, 2023
@statslover123
Copy link

Any update on this? Still can't use it

@topepo
Copy link
Member

topepo commented Jan 27, 2025

Working on it today in advance of a release

@dfalbel
Copy link
Collaborator

dfalbel commented Jan 27, 2025

I think you can use nn_identity instead in here:

brulee/R/activation.R

Lines 24 to 31 in b46122b

if (arg == "linear") {
res <- identity
} else {
cl <- rlang::call2(paste0("nn_", arg), .ns = "torch")
res <- rlang::eval_bare(cl)
}
res

if (arg == "linear") { 
  res <- nn_identity()
 } else { 
  cl <- rlang::call2(paste0("nn_", arg), .ns = "torch") 
  res <- rlang::eval_bare(cl) 
 } 

The problem is that later you are passing identity to nn_sequential() and that's not supported. nn_sequential expects modules as inputs.

topepo added a commit that referenced this issue Jan 30, 2025
@topepo topepo mentioned this issue Jan 30, 2025
topepo added a commit that referenced this issue Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants