docstr: ...Test that solvers can run all glm models and are consistent
  with sparsity
docstr_tok: ["...","Test","that","solvers","can","run","all","glm","models","and","are","consistent","with","sparsity"]
code: def _test_solver_sparse_and_dense_consistency(
      self,
      create_solver,
      model_classes=list([ModelLinReg, ModelLogReg, ModelPoisReg]),
      proxs_classes=list([ProxL2Sq, ProxL1]),
      fit_intercepts=list([False, True]),
  ):
      """...Test that solvers can run all glm models and are consistent
      with sparsity
      """
      dtype = self.dtype
      n_samples = 50
      n_features = 10
      coeffs0 = weights_sparse_gauss(n_features, nnz=5)
      interc0 = 2.0
      seed = 123
      prox_strength = 1e-3
  
      model_simu_map = {
          ModelLinReg: SimuLinReg,
          ModelPoisReg: SimuPoisReg,
          ModelLogReg: SimuLogReg,
      }
  
      cases = itertools.product(
          model_classes, proxs_classes, fit_intercepts
      )
  
      for Model, Prox, fit_intercept in cases:
          if fit_intercept:
              interc = interc0
          else:
              interc = None
  
          Simu = model_simu_map[Model]
          simu = Simu(
              coeffs0,
              interc,
              n_samples=n_samples,
              seed=seed,
              verbose=False,
              dtype=self.dtype,
          )
          X, y = simu.simulate()
          if X.dtype != y.dtype:
              raise ValueError(
                  "Simulation error, features and label dtypes differ"
              )
          X_sparse = csr_matrix(X).astype(self.dtype)
  
          for sparse in [True, False]:
              model = Model(fit_intercept=fit_intercept)
  
              if sparse:
                  model.fit(X_sparse, y)
              else:
                  model.fit(X, y)
  
              prox = Prox(prox_strength, (0, n_features)).astype(
                  self.dtype
              )
              solver = create_solver()
              solver.set_model(model).set_prox(prox)
  
              if sparse:
                  iterate_sparse = solver.solve()
              else:
                  iterate_dense = solver.solve()
  
          error_msg = "Failed for %s and %s solved with %s" % (
              model.name,
              prox.name,
              solver.name,
          )
  
          if fit_intercept:
              error_msg += " with intercept"
          else:
              error_msg += " without intercept"
  
          self.assertEqual(
              np.isfinite(iterate_dense).all(), True, error_msg
          )
  
          places = 7
          if self.dtype is "float32" or self.dtype is np.dtype(
              "float32"
          ):
              places = 4
          np.testing.assert_almost_equal(
              iterate_dense,
              iterate_sparse,
              err_msg=error_msg,
              decimal=places,
          )
  
file_path: tick/tick/solver/tests/solver.py
imports: import unittest
  import itertools
  import numpy
  from scipy.linalg import norm
  from scipy.sparse import csr_matrix
  from tick.linear_model import ModelLogReg, ModelPoisReg, ModelLinReg, SimuLinReg, SimuLogReg, SimuPoisReg
  from tick.prox import ProxL2Sq, ProxZero, ProxL1
  from tick.solver import SVRG, AGD, SGD, SDCA, GD, BFGS, AdaGrad
  from tick.simulation import weights_sparse_gauss
label_desc: Use image node_id 5 for calling the TestSolver obj's underlying member method code with example usage: obj._test_solver_sparse_and_dense_consistency(create_solver, model_classes, proxs_classes, fit_intercepts) without return types