class_docstr: Test Gaussian Hyperparameter Optimization.
class_docstr_tok: ["Test","Gaussian","Hyperparameter","Optimization","."]
docstr: Test a simple example of optimizing a multitask model with a gaussian process search with per-parameter search range.
docstr_tok: ["Test","a","simple","example","of","optimizing","a","multitask","model","with","a","gaussian","process","search","with","per-parameter","search","range","."]
code: def test_multitask_example_different_search_range(self):
      """Test a simple example of optimizing a multitask model with a gaussian process search with per-parameter search range."""
      # Generate dummy dataset
      np.random.seed(123)
      train_dataset = dc.data.NumpyDataset(
          np.random.rand(10, 3),
          np.zeros((10, 2)),
          np.ones((10, 2)),
          np.arange(10),
      )
      valid_dataset = dc.data.NumpyDataset(
          np.random.rand(5, 3),
          np.zeros((5, 2)),
          np.ones((5, 2)),
          np.arange(5),
      )
      transformers = []
  
      # These are per-example multiplier
      search_range = {"learning_rate": 10, "batch_size": 4}
      optimizer = dc.hyper.GaussianProcessHyperparamOpt(
          lambda **params: dc.models.MultitaskRegressor(
              n_tasks=2,
              n_features=3,
              dropouts=[0.0],
              weight_init_stddevs=[np.sqrt(6) / np.sqrt(1000)],
              **params,
          ),
          search_range=search_range,
          max_iter=2,
      )
  
      params_dict = {"learning_rate": 0.003, "batch_size": 10}
      metric = dc.metrics.Metric(
          dc.metrics.mean_squared_error, task_averager=np.mean
      )
  
      with tempfile.TemporaryDirectory() as tmpdirname:
          (
              best_model,
              best_hyperparams,
              all_results,
          ) = optimizer.hyperparam_search(
              params_dict,
              train_dataset,
              valid_dataset,
              metric,
              transformers,
              logdir=tmpdirname,
              use_max=False,
          )
          valid_score = best_model.evaluate(
              valid_dataset, [metric], transformers
          )
      # Test that 2 parameters were optimized
      for hp_str in all_results.keys():
          # Recall that the key is a string of the form _batch_size_39_learning_rate_0.01 for example
          assert "batch_size" in hp_str
          assert "learning_rate" in hp_str
      assert valid_score["mean-mean_squared_error"] == min(
          all_results.values()
      )
      assert valid_score["mean-mean_squared_error"] > 0
  
file_path: deepchem/deepchem/hyper/tests/test_gaussian_hyperparam_opt.py
imports: import numpy
  import sklearn
  import sklearn.ensemble
  import deepchem
  import unittest
  import pytest
  import tempfile
  from flaky import flaky
label_desc: Use image node_id 6 for calling the TestGaussianHyperparamOpt obj's underlying member method code with example usage: obj.test_multitask_example_different_search_range() without return types