tests/testthat/test.optimization.R

context("Optimization")
library(s2net)

lm_test = function(train){
  obj = s2netR(train, s2Params(0))
  
  lm_fit = lm.fit(x = train$xL, y = train$yL)
  true_beta = unname(lm_fit$coefficients)
  found_beta = as.vector(obj$beta)
  expect_equal(found_beta, true_beta, tolerance = .01)
  
  lm_error = mean((train$xL%*%lm_fit$coefficients - train$yL)^2)
  error = mean((obj$intercept + train$xL%*%obj$beta - train$yL)^2)
  expect_equal(error, lm_error, tolerance = 0.00001)
}

test_that("s2net Fista solves the supervised problem correctly",{
  data("auto_mpg")
  train = s2Data(auto_mpg$P2$xL, auto_mpg$P2$yL, preprocess = TRUE)
  lm_test(train)
  
  train = s2Data(auto_mpg$P1$xL[,-1], auto_mpg$P1$yL, preprocess = TRUE)
  lm_test(train)
})

Try the s2net package in your browser

Any scripts or data that you put into this service are public.

s2net documentation built on July 1, 2022, 1:06 a.m.