docstr: ...Test that SVRG variance_reduction parameter behaves correctly
          
docstr_tok: ["...","Test","that","SVRG","variance_reduction","parameter","behaves","correctly"]
code: def test_variance_reduction_setting(self):
      """...Test that SVRG variance_reduction parameter behaves correctly"""
      svrg = SVRG()
  
      coeffs0 = weights_sparse_gauss(20, nnz=5, dtype=self.dtype)
      interc0 = None
  
      X, y = SimuLogReg(
          coeffs0,
          interc0,
          n_samples=3000,
          verbose=False,
          seed=123,
          dtype=self.dtype,
      ).simulate()
  
      model = ModelLogReg().fit(X, y)
      svrg.set_model(model)
  
      self.assertEqual(svrg.variance_reduction, "last")
      self.assertEqual(
          svrg._solver.get_variance_reduction(),
          SVRG_VarianceReductionMethod_Last,
      )
  
      svrg = SVRG(variance_reduction="rand")
      svrg.set_model(model)
      self.assertEqual(svrg.variance_reduction, "rand")
      self.assertEqual(
          svrg._solver.get_variance_reduction(),
          SVRG_VarianceReductionMethod_Random,
      )
  
      svrg.variance_reduction = "avg"
      self.assertEqual(svrg.variance_reduction, "avg")
      self.assertEqual(
          svrg._solver.get_variance_reduction(),
          SVRG_VarianceReductionMethod_Average,
      )
  
      svrg.variance_reduction = "rand"
      self.assertEqual(svrg.variance_reduction, "rand")
      self.assertEqual(
          svrg._solver.get_variance_reduction(),
          SVRG_VarianceReductionMethod_Random,
      )
  
      svrg.variance_reduction = "last"
      self.assertEqual(svrg.variance_reduction, "last")
      self.assertEqual(
          svrg._solver.get_variance_reduction(),
          SVRG_VarianceReductionMethod_Last,
      )
  
      msg = (
          '^variance_reduction should be one of "avg, last, rand", '
          'got "stuff"$'
      )
      with self.assertRaisesRegex(ValueError, msg):
          svrg = SVRG(variance_reduction="stuff")
          svrg.set_model(model)
      with self.assertRaisesRegex(ValueError, msg):
          svrg.variance_reduction = "stuff"
  
      X, y = self.simu_linreg_data(dtype=self.dtype)
      model_dense, model_spars = self.get_dense_and_sparse_linreg_model(
          X, y, dtype=self.dtype
      )
      try:
          svrg.set_model(model_dense)
          svrg.variance_reduction = "avg"
          svrg.variance_reduction = "last"
          svrg.variance_reduction = "rand"
          svrg.set_model(model_spars)
          svrg.variance_reduction = "last"
          svrg.variance_reduction = "rand"
      except Exception:
          self.fail(
              "Setting variance_reduction in these cases should have "
              "been ok"
          )
  
      msg = (
          "'avg' variance reduction cannot be used with sparse datasets"
      )
      with catch_warnings(record=True) as w:
          simplefilter("always")
          svrg.set_model(model_spars)
          svrg.variance_reduction = "avg"
          self.assertEqual(len(w), 1)
          self.assertTrue(issubclass(w[0].category, UserWarning))
          self.assertEqual(str(w[0].message), msg)
  
imports: import unittest
  from warnings import catch_warnings, simplefilter
  from itertools import product
  import numpy
  from scipy.linalg.special_matrices import toeplitz
  from scipy.sparse import csr_matrix
  from tick.linear_model import ModelLinReg, ModelLogReg, SimuLogReg
  from tick.prox import ProxL1, ProxL1w, ProxTV, ProxEquality, ProxElasticNet
  from tick.solver import SVRG
  from tick.solver.tests import TestSolver
  from tick.solver.build.solver import SVRG_VarianceReductionMethod_Last
  from tick.solver.build.solver import SVRG_VarianceReductionMethod_Average
  from tick.solver.build.solver import SVRG_VarianceReductionMethod_Random
  from tick.solver.build.solver import SVRG_StepType_Fixed
  from tick.solver.build.solver import SVRG_StepType_BarzilaiBorwein
  from tick.simulation import weights_sparse_gauss
label_desc: Use image node_id 5 for calling the SVRGTest obj's underlying member method code with example usage: obj.test_variance_reduction_setting() without return types