docstr: Check solver instance finds same parameters as scipy BFGS
  
  Parameters
  ----------
  solver : `Solver`
      Instance of a solver to be tested
  
  fit_intercept : `bool`, default=True
      Model uses intercept is `True`
  
  model : 'linreg' | 'logreg' | 'poisreg', default='logreg'
      Name of the model used to test the solver
  
  decimal : `int`, default=1
      Number of decimals required for the test
docstr_tok: ["Check","solver","instance","finds","same","parameters","as","scipy","BFGS","Parameters","--","--","--","--","--","solver",":","`","Solver","`","Instance","of","a","solver","to","be","tested","fit_intercept",":","`","bool","`",",","default=True","Model","uses","intercept","is","`","True","`","model",":","'linreg","'","|","'logreg","'","|","'poisreg","'",",","default='logreg'","Name","of","the","model","used","to","test","the","solver","decimal",":","`","int","`",",","default=1","Number","of","decimals","required","for","the","test"]
code: def check_solver(
      self, solver, fit_intercept=True, model="logreg", decimal=1
  ):
      """Check solver instance finds same parameters as scipy BFGS
  
      Parameters
      ----------
      solver : `Solver`
          Instance of a solver to be tested
  
      fit_intercept : `bool`, default=True
          Model uses intercept is `True`
  
      model : 'linreg' | 'logreg' | 'poisreg', default='logreg'
          Name of the model used to test the solver
  
      decimal : `int`, default=1
          Number of decimals required for the test
      """
      # Set seed for data simulation
      dtype = self.dtype
  
      if np.dtype(dtype) != np.dtype("float64"):
          return
  
      np.random.seed(12)
      n_samples = TestSolver.n_samples
      n_features = TestSolver.n_features
  
      coeffs0 = weights_sparse_gauss(n_features, nnz=5, dtype=dtype)
      if fit_intercept:
          interc0 = 2.0
      else:
          interc0 = None
  
      if model == "linreg":
          X, y = SimuLinReg(
              coeffs0,
              interc0,
              n_samples=n_samples,
              verbose=False,
              seed=123,
              dtype=self.dtype,
          ).simulate()
          model = ModelLinReg(fit_intercept=fit_intercept).fit(X, y)
      elif model == "logreg":
          X, y = SimuLogReg(
              coeffs0,
              interc0,
              n_samples=n_samples,
              verbose=False,
              seed=123,
              dtype=self.dtype,
          ).simulate()
          model = ModelLogReg(fit_intercept=fit_intercept).fit(X, y)
      elif model == "poisreg":
          X, y = SimuPoisReg(
              coeffs0,
              interc0,
              n_samples=n_samples,
              verbose=False,
              seed=123,
              dtype=self.dtype,
          ).simulate()
          # Rescale features to avoid overflows in Poisson simulations
          X /= np.linalg.norm(X, axis=1).reshape(n_samples, 1)
          model = ModelPoisReg(fit_intercept=fit_intercept).fit(X, y)
      else:
          raise ValueError(
              "``model`` must be either 'linreg', 'logreg' or"
              " 'poisreg'"
          )
  
      solver.set_model(model)
      strength = 1e-2
      prox = ProxL2Sq(strength, (0, model.n_features))
  
      if type(solver) is not SDCA:
          solver.set_prox(prox)
      else:
          solver.set_prox(ProxZero().astype(self.dtype))
          solver.l_l2sq = strength
  
      coeffs_solver = solver.solve()
      # Compare with BFGS
      bfgs = (
          BFGS(max_iter=100, verbose=False)
          .set_model(model)
          .set_prox(prox)
      )
      coeffs_bfgs = bfgs.solve()
  
      np.testing.assert_almost_equal(
          coeffs_solver, coeffs_bfgs, decimal=decimal
      )
  
      # We ensure that reached coeffs are not equal to zero
      self.assertGreater(norm(coeffs_solver), 0)
  
      self.assertAlmostEqual(
          solver.objective(coeffs_bfgs),
          solver.objective(coeffs_solver),
          delta=1e-2,
      )
  
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 3 for calling the TestSolver obj's underlying member method code with example usage: obj.check_solver(solver, fit_intercept, model, decimal) without return types